style(phpcs): autofix WordPress-Core violations via phpcbf

Run phpcbf --standard=WordPress-Core across includes/, prautoblogger.php,
and uninstall.php. Fixed 1,362 formatting violations in 75 files:
  - Short array syntax: [] → array()
  - Line breaking for long function calls
  - Consistent indentation
  - Function call parameter alignment

No logic changes; purely mechanical formatting.
This commit is contained in:
peptiderepo
2026-04-23 02:42:48 +00:00
parent 7cd65b145f
commit f3eacd0d8d
75 changed files with 2148 additions and 1412 deletions

View File

@@ -23,15 +23,36 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
*
* @var array<string, array{in: string[], out: string[]}>
*/
private const CAPABILITY_MAP = [
'text→text' => [ 'in' => [ 'text' ], 'out' => [ 'text' ] ],
'text+image→text' => [ 'in' => [ 'text', 'image' ], 'out' => [ 'text' ] ],
'text+audio→text' => [ 'in' => [ 'text', 'audio' ], 'out' => [ 'text' ] ],
'text→image' => [ 'in' => [ 'text' ], 'out' => [ 'image' ] ],
'text→audio' => [ 'in' => [ 'text' ], 'out' => [ 'audio' ] ],
'text→video' => [ 'in' => [ 'text' ], 'out' => [ 'video' ] ],
'text→embedding' => [ 'in' => [ 'text' ], 'out' => [ 'embedding' ] ],
];
private const CAPABILITY_MAP = array(
'text→text' => array(
'in' => array( 'text' ),
'out' => array( 'text' ),
),
'text+image→text' => array(
'in' => array( 'text', 'image' ),
'out' => array( 'text' ),
),
'text+audio→text' => array(
'in' => array( 'text', 'audio' ),
'out' => array( 'text' ),
),
'text→image' => array(
'in' => array( 'text' ),
'out' => array( 'image' ),
),
'text→audio' => array(
'in' => array( 'text' ),
'out' => array( 'audio' ),
),
'text→video' => array(
'in' => array( 'text' ),
'out' => array( 'video' ),
),
'text→embedding' => array(
'in' => array( 'text' ),
'out' => array( 'embedding' ),
),
);
/**
* Normalize raw OpenRouter model records into the standardized shape.
@@ -54,15 +75,15 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
* }> Normalized records, sorted by name ascending.
*/
public function normalize( array $raw_models ): array {
$normalized = [];
$normalized = array();
foreach ( $raw_models as $model ) {
if ( ! is_array( $model ) || ! isset( $model['id'] ) ) {
continue;
}
$input_modalities = (array) ( $model['architecture']['input_modalities'] ?? [ 'text' ] );
$output_modalities = (array) ( $model['architecture']['output_modalities'] ?? [ 'text' ] );
$input_modalities = (array) ( $model['architecture']['input_modalities'] ?? array( 'text' ) );
$output_modalities = (array) ( $model['architecture']['output_modalities'] ?? array( 'text' ) );
$name_parts = explode( '/', (string) $model['id'], 2 );
@@ -70,7 +91,7 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
$prompt_price = (float) ( $model['pricing']['prompt'] ?? 0 );
$completion_price = (float) ( $model['pricing']['completion'] ?? 0 );
$normalized[] = [
$normalized[] = array(
'id' => (string) $model['id'],
'name' => (string) ( $model['name'] ?? $model['id'] ),
'provider' => $name_parts[0] ?? 'unknown',
@@ -80,12 +101,15 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
'capabilities' => $this->derive_capabilities( $input_modalities, $output_modalities ),
'deprecated' => false,
'updated_at' => (int) ( $model['created'] ?? 0 ),
];
);
}
usort( $normalized, static function ( array $a, array $b ): int {
return strcasecmp( $a['name'], $b['name'] );
} );
usort(
$normalized,
static function ( array $a, array $b ): int {
return strcasecmp( $a['name'], $b['name'] );
}
);
return $normalized;
}
@@ -99,7 +123,7 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
* @return string[] Matched capability labels. Defaults to ['text→text'].
*/
private function derive_capabilities( array $input_modalities, array $output_modalities ): array {
$caps = [];
$caps = array();
foreach ( self::CAPABILITY_MAP as $label => $requirements ) {
$input_match = empty( array_diff( $requirements['in'], $input_modalities ) );
@@ -109,6 +133,6 @@ class PRAutoBlogger_OpenRouter_Model_Normalizer {
}
}
return empty( $caps ) ? [ 'text→text' ] : $caps;
return empty( $caps ) ? array( 'text→text' ) : $caps;
}
}

View File

@@ -52,11 +52,11 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
) {
$this->option_name = $option_name;
$this->fetched_at_option = $option_name . '_fetched_at';
$this->transient_name = $transient_name;
$this->endpoint = $endpoint;
$this->cache_ttl = $cache_ttl_seconds;
$this->transient_name = $transient_name;
$this->endpoint = $endpoint;
$this->cache_ttl = $cache_ttl_seconds;
$this->idempotency_window = $idempotency_seconds;
$this->normalizer = new PRAutoBlogger_OpenRouter_Model_Normalizer();
$this->normalizer = new PRAutoBlogger_OpenRouter_Model_Normalizer();
}
/** {@inheritDoc} */
@@ -70,7 +70,7 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
array_filter(
$this->load_payload(),
static function ( array $model ) use ( $capability ): bool {
return in_array( $capability, $model['capabilities'] ?? [], true );
return in_array( $capability, $model['capabilities'] ?? array(), true );
}
)
);
@@ -92,14 +92,20 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
if ( ! $force && $fetched_at > 0 && ( time() - $fetched_at ) < $this->idempotency_window ) {
$payload = $this->load_payload();
return [ 'count' => count( $payload ), 'fetched_at' => $fetched_at ];
return array(
'count' => count( $payload ),
'fetched_at' => $fetched_at,
);
}
$raw_models = $this->fetch_from_api();
if ( null === $raw_models ) {
$this->flag_stale();
$stale = $this->load_from_option();
return [ 'count' => count( $stale ), 'fetched_at' => $fetched_at ];
return array(
'count' => count( $stale ),
'fetched_at' => $fetched_at,
);
}
$normalized = $this->normalizer->normalize( $raw_models );
@@ -113,7 +119,10 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
self::LOG_CONTEXT
);
return [ 'count' => count( $normalized ), 'fetched_at' => $now ];
return array(
'count' => count( $normalized ),
'fetched_at' => $now,
);
}
/** {@inheritDoc} */
@@ -141,8 +150,8 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
/** @return array<int, array> */
private function load_from_option(): array {
$data = get_option( $this->option_name, [] );
return is_array( $data ) ? $data : [];
$data = get_option( $this->option_name, array() );
return is_array( $data ) ? $data : array();
}
private function save_payload( array $payload, int $now ): void {
@@ -161,7 +170,7 @@ class PRAutoBlogger_OpenRouter_Model_Registry implements PRAutoBlogger_Model_Reg
$base_delay = defined( 'PRAUTOBLOGGER_RETRY_BASE_DELAY_SECONDS' ) ? PRAUTOBLOGGER_RETRY_BASE_DELAY_SECONDS : 2;
for ( $attempt = 1; $attempt <= $max_retries; $attempt++ ) {
$response = wp_remote_get( $this->endpoint, [ 'timeout' => self::HTTP_TIMEOUT ] );
$response = wp_remote_get( $this->endpoint, array( 'timeout' => self::HTTP_TIMEOUT ) );
if ( is_wp_error( $response ) ) {
PRAutoBlogger_Logger::instance()->warning(