style: auto-fix PHPCS violations via phpcbf

This commit is contained in:
peptiderepo
2026-06-16 14:01:59 +00:00
parent 3890485dcb
commit 1813d419e5
8 changed files with 246 additions and 93 deletions

View File

@@ -35,25 +35,33 @@ add_action( 'rest_api_init', 'prautoblogger_deploy_register_route' );
* Register the deploy REST route. * Register the deploy REST route.
*/ */
function prautoblogger_deploy_register_route(): void { function prautoblogger_deploy_register_route(): void {
register_rest_route( 'prautoblogger-deploy/v1', '/deploy', [ register_rest_route(
'methods' => 'POST', 'prautoblogger-deploy/v1',
'callback' => 'prautoblogger_deploy_handle', '/deploy',
'permission_callback' => 'prautoblogger_deploy_check_auth', array(
] ); 'methods' => 'POST',
'callback' => 'prautoblogger_deploy_handle',
'permission_callback' => 'prautoblogger_deploy_check_auth',
)
);
// Health check endpoint (GET) — useful for monitoring. // Health check endpoint (GET) — useful for monitoring.
register_rest_route( 'prautoblogger-deploy/v1', '/status', [ register_rest_route(
'methods' => 'GET', 'prautoblogger-deploy/v1',
'callback' => function () { '/status',
return [ array(
'status' => 'ready', 'methods' => 'GET',
'plugin' => is_dir( WP_PLUGIN_DIR . '/prautoblogger' ) ? 'installed' : 'not_installed', 'callback' => function () {
'active' => is_plugin_active( 'prautoblogger/prautoblogger.php' ), return array(
'version' => prautoblogger_deploy_get_installed_version(), 'status' => 'ready',
]; 'plugin' => is_dir( WP_PLUGIN_DIR . '/prautoblogger' ) ? 'installed' : 'not_installed',
}, 'active' => is_plugin_active( 'prautoblogger/prautoblogger.php' ),
'permission_callback' => 'prautoblogger_deploy_check_auth', 'version' => prautoblogger_deploy_get_installed_version(),
] ); );
},
'permission_callback' => 'prautoblogger_deploy_check_auth',
)
);
} }
/** /**
@@ -78,7 +86,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
return new WP_Error( return new WP_Error(
'rate_limited', 'rate_limited',
'Deploy in progress or recently completed. Wait 60 seconds.', 'Deploy in progress or recently completed. Wait 60 seconds.',
[ 'status' => 429 ] array( 'status' => 429 )
); );
} }
set_transient( 'prautoblogger_deploy_lock', time(), 60 ); set_transient( 'prautoblogger_deploy_lock', time(), 60 );
@@ -87,7 +95,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
$files = $request->get_file_params(); $files = $request->get_file_params();
if ( empty( $files['plugin']['tmp_name'] ) || ! is_uploaded_file( $files['plugin']['tmp_name'] ) ) { if ( empty( $files['plugin']['tmp_name'] ) || ! is_uploaded_file( $files['plugin']['tmp_name'] ) ) {
delete_transient( 'prautoblogger_deploy_lock' ); delete_transient( 'prautoblogger_deploy_lock' );
return new WP_Error( 'no_file', 'No plugin zip uploaded.', [ 'status' => 400 ] ); return new WP_Error( 'no_file', 'No plugin zip uploaded.', array( 'status' => 400 ) );
} }
$tmp_file = $files['plugin']['tmp_name']; $tmp_file = $files['plugin']['tmp_name'];
@@ -96,7 +104,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
$zip = new ZipArchive(); $zip = new ZipArchive();
if ( true !== $zip->open( $tmp_file ) ) { if ( true !== $zip->open( $tmp_file ) ) {
delete_transient( 'prautoblogger_deploy_lock' ); delete_transient( 'prautoblogger_deploy_lock' );
return new WP_Error( 'invalid_zip', 'Uploaded file is not a valid zip.', [ 'status' => 400 ] ); return new WP_Error( 'invalid_zip', 'Uploaded file is not a valid zip.', array( 'status' => 400 ) );
} }
$has_main_file = false; $has_main_file = false;
@@ -113,7 +121,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
return new WP_Error( return new WP_Error(
'invalid_plugin', 'invalid_plugin',
'Zip must contain prautoblogger/prautoblogger.php at root.', 'Zip must contain prautoblogger/prautoblogger.php at root.',
[ 'status' => 400 ] array( 'status' => 400 )
); );
} }
@@ -143,7 +151,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
activate_plugin( 'prautoblogger/prautoblogger.php' ); activate_plugin( 'prautoblogger/prautoblogger.php' );
} }
delete_transient( 'prautoblogger_deploy_lock' ); delete_transient( 'prautoblogger_deploy_lock' );
return new WP_Error( 'backup_failed', 'Could not backup current plugin.', [ 'status' => 500 ] ); return new WP_Error( 'backup_failed', 'Could not backup current plugin.', array( 'status' => 500 ) );
} }
} }
@@ -161,7 +169,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
} }
delete_transient( 'prautoblogger_deploy_lock' ); delete_transient( 'prautoblogger_deploy_lock' );
error_log( '[PRAutoBlogger Deploy] Extraction failed. Rolled back to previous version.' ); error_log( '[PRAutoBlogger Deploy] Extraction failed. Rolled back to previous version.' );
return new WP_Error( 'extract_failed', 'Zip extraction failed. Rolled back.', [ 'status' => 500 ] ); return new WP_Error( 'extract_failed', 'Zip extraction failed. Rolled back.', array( 'status' => 500 ) );
} }
// 7. Activate plugin. // 7. Activate plugin.
@@ -178,7 +186,7 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
return new WP_Error( return new WP_Error(
'activation_failed', 'activation_failed',
'Plugin activation failed: ' . $activation_result->get_error_message() . '. Rolled back.', 'Plugin activation failed: ' . $activation_result->get_error_message() . '. Rolled back.',
[ 'status' => 500 ] array( 'status' => 500 )
); );
} }
@@ -188,18 +196,23 @@ function prautoblogger_deploy_handle( WP_REST_Request $request ): WP_REST_Respon
} }
$old_version = prautoblogger_deploy_get_installed_version(); $old_version = prautoblogger_deploy_get_installed_version();
error_log( sprintf( error_log(
'[PRAutoBlogger Deploy] Successfully deployed v%s (was: %s) at %s', sprintf(
$incoming_version, '[PRAutoBlogger Deploy] Successfully deployed v%s (was: %s) at %s',
$old_version ?: 'fresh install', $incoming_version,
gmdate( 'Y-m-d H:i:s' ) $old_version ?: 'fresh install',
) ); gmdate( 'Y-m-d H:i:s' )
)
);
return new WP_REST_Response( [ return new WP_REST_Response(
'success' => true, array(
'version' => $incoming_version, 'success' => true,
'message' => "PRAutoBlogger v{$incoming_version} deployed and activated.", 'version' => $incoming_version,
], 200 ); 'message' => "PRAutoBlogger v{$incoming_version} deployed and activated.",
),
200
);
} }
/** /**
@@ -210,7 +223,7 @@ function prautoblogger_deploy_get_installed_version(): string {
if ( ! file_exists( $main_file ) ) { if ( ! file_exists( $main_file ) ) {
return ''; return '';
} }
$data = get_file_data( $main_file, [ 'Version' => 'Version' ] ); $data = get_file_data( $main_file, array( 'Version' => 'Version' ) );
return $data['Version'] ?? ''; return $data['Version'] ?? '';
} }

View File

@@ -25,19 +25,111 @@ class PRAutoBlogger_Keyword_Extractor {
* @var string[] * @var string[]
*/ */
private const STOPWORDS = array( private const STOPWORDS = array(
'a', 'an', 'the', 'and', 'or', 'but', 'is', 'are', 'was', 'were', 'a',
'in', 'on', 'at', 'to', 'for', 'of', 'with', 'by', 'from', 'as', 'an',
'it', 'its', 'this', 'that', 'your', 'you', 'how', 'what', 'when', 'the',
'why', 'where', 'which', 'who', 'do', 'does', 'did', 'not', 'no', 'and',
'can', 'will', 'should', 'could', 'would', 'may', 'might', 'have', 'or',
'has', 'had', 'be', 'been', 'being', 'about', 'into', 'through', 'but',
'during', 'before', 'after', 'above', 'below', 'between', 'same', 'is',
'up', 'down', 'out', 'off', 'over', 'under', 'again', 'then', 'here', 'are',
'there', 'all', 'each', 'every', 'both', 'few', 'more', 'most', 'was',
'other', 'some', 'such', 'than', 'too', 'very', 'just', 'also', 'were',
'only', 'own', 'so', 'if', 'while', 'because', 'until', 'vs', 'in',
'versus', 'guide', 'complete', 'ultimate', 'best', 'top', 'new', 'on',
'first', 'need', 'know', 'everything', 'at',
'to',
'for',
'of',
'with',
'by',
'from',
'as',
'it',
'its',
'this',
'that',
'your',
'you',
'how',
'what',
'when',
'why',
'where',
'which',
'who',
'do',
'does',
'did',
'not',
'no',
'can',
'will',
'should',
'could',
'would',
'may',
'might',
'have',
'has',
'had',
'be',
'been',
'being',
'about',
'into',
'through',
'during',
'before',
'after',
'above',
'below',
'between',
'same',
'up',
'down',
'out',
'off',
'over',
'under',
'again',
'then',
'here',
'there',
'all',
'each',
'every',
'both',
'few',
'more',
'most',
'other',
'some',
'such',
'than',
'too',
'very',
'just',
'also',
'only',
'own',
'so',
'if',
'while',
'because',
'until',
'vs',
'versus',
'guide',
'complete',
'ultimate',
'best',
'top',
'new',
'first',
'need',
'know',
'everything',
); );
/** /**

View File

@@ -26,13 +26,41 @@ class PRAutoBlogger_Image_Aspect_Ratio {
* @var array<int, array{w: int, h: int, ratio: float}> * @var array<int, array{w: int, h: int, ratio: float}>
*/ */
private const STANDARD_ASPECTS = array( private const STANDARD_ASPECTS = array(
array( 'w' => 1, 'h' => 1, 'ratio' => 1.0 ), array(
array( 'w' => 3, 'h' => 2, 'ratio' => 1.5 ), 'w' => 1,
array( 'w' => 2, 'h' => 3, 'ratio' => 0.6667 ), 'h' => 1,
array( 'w' => 4, 'h' => 3, 'ratio' => 1.3333 ), 'ratio' => 1.0,
array( 'w' => 3, 'h' => 4, 'ratio' => 0.75 ), ),
array( 'w' => 16, 'h' => 9, 'ratio' => 1.7778 ), array(
array( 'w' => 9, 'h' => 16, 'ratio' => 0.5625 ), 'w' => 3,
'h' => 2,
'ratio' => 1.5,
),
array(
'w' => 2,
'h' => 3,
'ratio' => 0.6667,
),
array(
'w' => 4,
'h' => 3,
'ratio' => 1.3333,
),
array(
'w' => 3,
'h' => 4,
'ratio' => 0.75,
),
array(
'w' => 16,
'h' => 9,
'ratio' => 1.7778,
),
array(
'w' => 9,
'h' => 16,
'ratio' => 0.5625,
),
); );
/** /**

View File

@@ -86,5 +86,4 @@ class PRAutoBlogger_Runware_Validator {
'message' => __( 'Runware API key valid.', 'prautoblogger' ), 'message' => __( 'Runware API key valid.', 'prautoblogger' ),
); );
} }
} }

View File

@@ -35,18 +35,18 @@ const CONSTANTS_GUARD_WINDOW = 4; // 4 covers if/elseif blocks and multi-line &&
const CONSTANTS_BOOTSTRAP_FILE = 'prautoblogger.php'; const CONSTANTS_BOOTSTRAP_FILE = 'prautoblogger.php';
// Directories skipped when walking the shipped tree for references. // Directories skipped when walking the shipped tree for references.
const CONSTANTS_EXCLUDE_DIRS = ['tests', 'vendor', '.github', '.git', 'node_modules']; const CONSTANTS_EXCLUDE_DIRS = array( 'tests', 'vendor', '.github', '.git', 'node_modules' );
// Entry points for the reference scan (files and dirs relative to repo root). // Entry points for the reference scan (files and dirs relative to repo root).
const CONSTANTS_SCAN_ROOTS = [ const CONSTANTS_SCAN_ROOTS = array(
'prautoblogger.php', 'prautoblogger.php',
'uninstall.php', 'uninstall.php',
'includes', 'includes',
'templates', 'templates',
]; );
$verbose = in_array( '--verbose', $argv ?? [], true ); $verbose = in_array( '--verbose', $argv ?? array(), true );
$self_test = in_array( '--self-test', $argv ?? [], true ); $self_test = in_array( '--self-test', $argv ?? array(), true );
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// 1. Build the defined set from prautoblogger.php only. // 1. Build the defined set from prautoblogger.php only.
@@ -67,7 +67,7 @@ preg_match_all(
); );
/** @var array<string, int> $defined_set constant name => 1 */ /** @var array<string, int> $defined_set constant name => 1 */
$defined_set = array_flip( $def_matches[1] ?? [] ); $defined_set = array_flip( $def_matches[1] ?? array() );
if ( $verbose ) { if ( $verbose ) {
echo 'Defined in ' . CONSTANTS_BOOTSTRAP_FILE . ' (' . count( $defined_set ) . "):\n"; echo 'Defined in ' . CONSTANTS_BOOTSTRAP_FILE . ' (' . count( $defined_set ) . "):\n";
@@ -108,7 +108,7 @@ function constants_collect_php_files( string $dir, array &$files ): void {
} }
/** @var string[] $php_files */ /** @var string[] $php_files */
$php_files = []; $php_files = array();
foreach ( CONSTANTS_SCAN_ROOTS as $root ) { foreach ( CONSTANTS_SCAN_ROOTS as $root ) {
if ( ! file_exists( $root ) ) { if ( ! file_exists( $root ) ) {
@@ -133,7 +133,7 @@ if ( $verbose ) {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/** @var array<int, array{string, int, string, string}> $errors */ /** @var array<int, array{string, int, string, string}> $errors */
$errors = []; $errors = array();
foreach ( $php_files as $php_path ) { foreach ( $php_files as $php_path ) {
$raw = file_get_contents( $php_path ); $raw = file_get_contents( $php_path );
@@ -188,7 +188,7 @@ foreach ( $php_files as $php_path ) {
} }
if ( ! $guarded ) { if ( ! $guarded ) {
$errors[] = [ $php_path, $idx + 1, $name, $raw_line ]; $errors[] = array( $php_path, $idx + 1, $name, $raw_line );
} }
} }
} }
@@ -198,7 +198,7 @@ foreach ( $php_files as $php_path ) {
// 4. Report results. // 4. Report results.
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
if ( $errors !== [] ) { if ( $errors !== array() ) {
fwrite( STDERR, "\nFAIL -- Unguarded undefined PRAUTOBLOGGER_* constants:\n\n" ); fwrite( STDERR, "\nFAIL -- Unguarded undefined PRAUTOBLOGGER_* constants:\n\n" );
foreach ( $errors as [ $php_path, $lineno, $name, $line_text ] ) { foreach ( $errors as [ $php_path, $lineno, $name, $line_text ] ) {
fwrite( STDERR, " {$php_path}:{$lineno}: {$name}\n" ); fwrite( STDERR, " {$php_path}:{$lineno}: {$name}\n" );
@@ -228,7 +228,7 @@ if ( $self_test ) {
// Now simulate an unguarded reference by re-running the scan on a temp file. // Now simulate an unguarded reference by re-running the scan on a temp file.
$tmp_file = tempnam( sys_get_temp_dir(), 'prab_selftest_' ) . '.php'; $tmp_file = tempnam( sys_get_temp_dir(), 'prab_selftest_' ) . '.php';
file_put_contents( $tmp_file, "<?php\necho {$sentinel};\n" ); file_put_contents( $tmp_file, "<?php\necho {$sentinel};\n" );
$tmp_errors = []; $tmp_errors = array();
$tmp_lines = explode( "\n", (string) file_get_contents( $tmp_file ) ); $tmp_lines = explode( "\n", (string) file_get_contents( $tmp_file ) );
foreach ( $tmp_lines as $idx => $raw_line ) { foreach ( $tmp_lines as $idx => $raw_line ) {
if ( preg_match_all( '/PRAUTOBLOGGER_[A-Z0-9_]+/', $raw_line, $m ) ) { if ( preg_match_all( '/PRAUTOBLOGGER_[A-Z0-9_]+/', $raw_line, $m ) ) {

View File

@@ -72,10 +72,10 @@ $base_url = admin_url( 'admin.php?page=prautoblogger-ideas' );
<tbody> <tbody>
<?php foreach ( $rows as $row ) : ?> <?php foreach ( $rows as $row ) : ?>
<?php <?php
$meta = json_decode( $row['metadata_json'] ?? '{}', true ) ?: []; $meta = json_decode( $row['metadata_json'] ?? '{}', true ) ?: array();
$suggested = $meta['suggested_title'] ?? ''; $suggested = $meta['suggested_title'] ?? '';
$key_points = $meta['key_points'] ?? []; $key_points = $meta['key_points'] ?? array();
$keywords = $meta['target_keywords'] ?? []; $keywords = $meta['target_keywords'] ?? array();
$score_pct = round( (float) $row['relevance_score'] * 100 ); $score_pct = round( (float) $row['relevance_score'] * 100 );
$type_label = ucfirst( $row['analysis_type'] ?? 'unknown' ); $type_label = ucfirst( $row['analysis_type'] ?? 'unknown' );
$type_class = 'prab-type-' . sanitize_html_class( $row['analysis_type'] ); $type_class = 'prab-type-' . sanitize_html_class( $row['analysis_type'] );
@@ -164,14 +164,18 @@ $base_url = admin_url( 'admin.php?page=prautoblogger-ideas' );
<?php if ( $total_pages > 1 ) : ?> <?php if ( $total_pages > 1 ) : ?>
<div class="prautoblogger-pagination" style="margin-top: 12px;"> <div class="prautoblogger-pagination" style="margin-top: 12px;">
<?php <?php
echo wp_kses_post( paginate_links( [ echo wp_kses_post(
'base' => add_query_arg( 'paged', '%#%' ), paginate_links(
'format' => '', array(
'current' => $paged, 'base' => add_query_arg( 'paged', '%#%' ),
'total' => $total_pages, 'format' => '',
'prev_text' => '&laquo;', 'current' => $paged,
'next_text' => '&raquo;', 'total' => $total_pages,
] ) ); 'prev_text' => '&laquo;',
'next_text' => '&raquo;',
)
)
);
?> ?>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@@ -18,13 +18,13 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
$base_url = admin_url( 'admin.php?page=prautoblogger-logs' ); $base_url = admin_url( 'admin.php?page=prautoblogger-logs' );
$level_counts = [ $level_counts = array(
'all' => __( 'All', 'prautoblogger' ), 'all' => __( 'All', 'prautoblogger' ),
'error' => __( 'Errors', 'prautoblogger' ), 'error' => __( 'Errors', 'prautoblogger' ),
'warning' => __( 'Warnings', 'prautoblogger' ), 'warning' => __( 'Warnings', 'prautoblogger' ),
'info' => __( 'Info', 'prautoblogger' ), 'info' => __( 'Info', 'prautoblogger' ),
'debug' => __( 'Debug', 'prautoblogger' ), 'debug' => __( 'Debug', 'prautoblogger' ),
]; );
?> ?>
<div class="wrap ab-wrap"> <div class="wrap ab-wrap">
<div class="ab-header"> <div class="ab-header">
@@ -46,7 +46,20 @@ $level_counts = [
<div class="ab-log-filters"> <div class="ab-log-filters">
<div class="ab-log-level-tabs"> <div class="ab-log-level-tabs">
<?php foreach ( $level_counts as $lv => $lv_label ) : ?> <?php foreach ( $level_counts as $lv => $lv_label ) : ?>
<a href="<?php echo esc_url( add_query_arg( [ 'level' => $lv, 's' => $search, 'paged' => 1 ], $base_url ) ); ?>" <a href="
<?php
echo esc_url(
add_query_arg(
array(
'level' => $lv,
's' => $search,
'paged' => 1,
),
$base_url
)
);
?>
"
class="ab-log-level-tab <?php echo $level === $lv ? 'ab-log-level-active' : ''; ?>"> class="ab-log-level-tab <?php echo $level === $lv ? 'ab-log-level-active' : ''; ?>">
<?php echo esc_html( $lv_label ); ?> <?php echo esc_html( $lv_label ); ?>
</a> </a>
@@ -119,14 +132,18 @@ $level_counts = [
<?php if ( $total_pages > 1 ) : ?> <?php if ( $total_pages > 1 ) : ?>
<div class="ab-log-pagination"> <div class="ab-log-pagination">
<?php <?php
echo wp_kses_post( paginate_links( [ echo wp_kses_post(
'base' => add_query_arg( 'paged', '%#%' ), paginate_links(
'format' => '', array(
'current' => $paged, 'base' => add_query_arg( 'paged', '%#%' ),
'total' => $total_pages, 'format' => '',
'prev_text' => '&laquo;', 'current' => $paged,
'next_text' => '&raquo;', 'total' => $total_pages,
] ) ); 'prev_text' => '&laquo;',
'next_text' => '&raquo;',
)
)
);
?> ?>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
$meta = [ $meta = array(
'topic' => get_post_meta( $post->ID, '_prautoblogger_topic', true ), 'topic' => get_post_meta( $post->ID, '_prautoblogger_topic', true ),
'type' => get_post_meta( $post->ID, '_prautoblogger_article_type', true ), 'type' => get_post_meta( $post->ID, '_prautoblogger_article_type', true ),
'model' => get_post_meta( $post->ID, '_prautoblogger_model_used', true ), 'model' => get_post_meta( $post->ID, '_prautoblogger_model_used', true ),
@@ -22,7 +22,7 @@ $meta = [
'seo_score' => get_post_meta( $post->ID, '_prautoblogger_seo_score', true ), 'seo_score' => get_post_meta( $post->ID, '_prautoblogger_seo_score', true ),
'generated_at' => get_post_meta( $post->ID, '_prautoblogger_generated_at', true ), 'generated_at' => get_post_meta( $post->ID, '_prautoblogger_generated_at', true ),
'keywords' => get_post_meta( $post->ID, '_prautoblogger_target_keywords', true ), 'keywords' => get_post_meta( $post->ID, '_prautoblogger_target_keywords', true ),
]; );
?> ?>
<div class="prautoblogger-metabox"> <div class="prautoblogger-metabox">
<p> <p>
@@ -69,7 +69,7 @@ $meta = [
<?php if ( $meta['keywords'] ) : ?> <?php if ( $meta['keywords'] ) : ?>
<p> <p>
<strong><?php esc_html_e( 'Keywords:', 'prautoblogger' ); ?></strong> <strong><?php esc_html_e( 'Keywords:', 'prautoblogger' ); ?></strong>
<?php echo esc_html( implode( ', ', json_decode( $meta['keywords'], true ) ?: [] ) ); ?> <?php echo esc_html( implode( ', ', json_decode( $meta['keywords'], true ) ?: array() ) ); ?>
</p> </p>
<?php endif; ?> <?php endif; ?>
</div> </div>