Skip to content

Commit 80498e5

Browse files
authored
fix code style
1 parent 666a627 commit 80498e5

File tree

10 files changed

+54
-25
lines changed

10 files changed

+54
-25
lines changed

.phive/phars.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpmd" version="^2.15.0" installed="2.15.0" location="../../home/codespace/.local/bin/phpmd" copy="false"/>
4+
<phar name="phpstan" version="^1.12.5" installed="1.12.5" location="../../home/codespace/.local/bin/phpstan" copy="false"/>
5+
<phar name="psalm" version="^5.26.1" installed="5.26.1" location="../../home/codespace/.local/bin/psalm" copy="false"/>
6+
<phar name="php-cs-fixer" version="^3.64.0" installed="3.64.0" location="../../home/codespace/.local/bin/php-cs-fixer" copy="false"/>
7+
</phive>

psalm-baseline.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="src/Optimization/Enqueue.php">
44
<RiskyTruthyFalsyComparison>
5+
<code><![CDATA[empty( $dependency->src )]]></code>
56
<code><![CDATA[empty( $file )]]></code>
67
<code><![CDATA[empty( $rootDir )]]></code>
78
</RiskyTruthyFalsyComparison>
9+
<TypeDoesNotContainType>
10+
<code><![CDATA[SCRIPT_DEBUG]]></code>
11+
</TypeDoesNotContainType>
12+
<UndefinedConstant>
13+
<code><![CDATA[WPINC]]></code>
14+
</UndefinedConstant>
815
</file>
916
<file src="src/Optimization/Media.php">
1017
<MixedReturnTypeCoercion>
@@ -50,6 +57,19 @@
5057
</RiskyTruthyFalsyComparison>
5158
</file>
5259
<file src="src/Optimization/WPQuery.php">
60+
<MixedArgument>
61+
<code><![CDATA[$limit]]></code>
62+
<code><![CDATA[$wpQuery->found_posts / $limit]]></code>
63+
<code><![CDATA[$wpQuery->get( 'posts_per_page' )]]></code>
64+
<code><![CDATA[$wpQuery->get( 'posts_per_page' )]]></code>
65+
</MixedArgument>
66+
<MixedAssignment>
67+
<code><![CDATA[$limit]]></code>
68+
<code><![CDATA[$limit]]></code>
69+
</MixedAssignment>
70+
<MixedOperand>
71+
<code><![CDATA[$limit]]></code>
72+
</MixedOperand>
5373
<RiskyTruthyFalsyComparison>
5474
<code><![CDATA[! $time]]></code>
5575
<code><![CDATA[! $time]]></code>
@@ -100,6 +120,9 @@
100120
</RiskyTruthyFalsyComparison>
101121
</file>
102122
<file src="src/helper.php">
123+
<MixedAssignment>
124+
<code><![CDATA[$post]]></code>
125+
</MixedAssignment>
103126
<RiskyTruthyFalsyComparison>
104127
<code><![CDATA[! $attributes['loading']]]></code>
105128
<code><![CDATA[empty( $alt )]]></code>

src/Optimization/CleanUp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function protectXmlrpc(): void {
8585
add_action( 'xmlrpc_call', static function ( string $action ) use ( $disableMethods ): void {
8686
if ( \in_array( $action, $disableMethods, true ) ) {
8787
wp_die(
88-
sprintf( '%s are not supported', $action ),
88+
\sprintf( '%s are not supported', $action ),
8989
'Not Allowed!',
9090
[ 'response' => 403 ]
9191
);

src/Optimization/LastPostModified.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static function isLocked( string $postType ): bool {
6363
}
6464

6565
private static function getLockName( string $postType ): string {
66-
return sprintf( '%s_%s_lock', self::OPTION_PREFIX, $postType );
66+
return \sprintf( '%s_%s_lock', self::OPTION_PREFIX, $postType );
6767
}
6868

6969
private static function bumpLastPostModified( WP_Post $wpPost ): void {
@@ -78,7 +78,7 @@ private static function bumpLastPostModified( WP_Post $wpPost ): void {
7878
}
7979

8080
private static function getOptionName( string $timezone, string $postType ): string {
81-
return sprintf( '%s_%s_%s', self::OPTION_PREFIX, strtolower( $timezone ), $postType );
81+
return \sprintf( '%s_%s_%s', self::OPTION_PREFIX, strtolower( $timezone ), $postType );
8282
}
8383

8484
private static function getLastPostModified( string $timezone, string $postType ): mixed {

src/Optimization/TermCount.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function maybeRecountPostsForTerm( int $termId, int $termTaxId, string $t
141141
return;
142142
}
143143

144-
if ( sprintf( 'edit-%s', $taxonomy ) === $screen->id ) {
144+
if ( \sprintf( 'edit-%s', $taxonomy ) === $screen->id ) {
145145
wp_update_term_count_now( [ $termTaxId ], $taxonomy );
146146
}
147147
}
@@ -230,7 +230,7 @@ private function quickUpdateTermsCount( int $objectId, array $termTaxIds, string
230230
$isIncrement = 'increment' === $transitionType;
231231

232232
$wpdb->query(
233-
sprintf(
233+
\sprintf(
234234
'update %s as tt set tt.count = tt.count %s 1 where tt.term_taxonomy_id in %s %s',
235235
$wpdb->term_taxonomy,
236236
$isIncrement ? '+' : '-',

src/Optimization/Update.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function load(): void {
1919

2020
// Remove bulk action for updating themes/plugins.
2121
foreach ( [ 'plugins', 'themes', 'plugins-network', 'themes-network' ] as $bulkAction ) {
22-
add_filter( sprintf( 'bulk_actions-%s', $bulkAction ), self::removeBulkActions( ... ) );
22+
add_filter( \sprintf( 'bulk_actions-%s', $bulkAction ), self::removeBulkActions( ... ) );
2323
}
2424

2525
// Admin UI items.
@@ -58,7 +58,7 @@ public function load(): void {
5858
$siteTransients = [ 'themes', 'plugins', 'core' ];
5959

6060
foreach ( $siteTransients as $siteTransient ) {
61-
add_filter( sprintf( 'pre_site_transient_update_%s', $siteTransient ), self::lastCheckedCore( ... ) );
61+
add_filter( \sprintf( 'pre_site_transient_update_%s', $siteTransient ), self::lastCheckedCore( ... ) );
6262
}
6363

6464
add_filter( 'site_transient_update_plugins', self::removePluginUpdates( ... ) );
@@ -369,7 +369,7 @@ public static function availableTranslations(): array {
369369
'strings' => [
370370
'continue' => __( 'Continue' ),
371371
],
372-
'package' => sprintf(
372+
'package' => \sprintf(
373373
'https://downloads.wordpress.org/translation/core/%s/%s.zip',
374374
esc_attr( $wp_version ),
375375
esc_attr( $language )

src/Optimization/WPQuery.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
final class WPQuery implements AutoloadInterface {
1515

1616
/**
17-
* @var string
18-
*/
17+
* @var string
18+
*/
1919
public const INVALIDATE_TIME_KEY = 'invalidate-time';
2020

2121
/**
@@ -59,7 +59,7 @@ public function postsClausesRequest( array $clauses, WP_Query $wpQuery ): array
5959

6060
/** @noinspection SqlConstantCondition */
6161
$pdoStatement = $pdo->prepare(
62-
sprintf(
62+
\sprintf(
6363
'select %s.ID from %s %s where 1=1 %s group by %s.ID order by %s.post_date',
6464
$wpdb->posts,
6565
$wpdb->posts,
@@ -160,7 +160,7 @@ private function invalidateFoundPostsCache(): void {
160160
/**
161161
* @return false|int
162162
*/
163-
private function getInvalidateTime() {
163+
private function getInvalidateTime(): bool|int {
164164
/** @var false|int $time */
165165
$time = wp_cache_get( self::INVALIDATE_TIME_KEY, Cache::QUERY_CACHE_GROUP );
166166

@@ -174,7 +174,7 @@ private function getInvalidateTime() {
174174
/**
175175
* @return false|int
176176
*/
177-
private function getTimeFoundPosts() {
177+
private function getTimeFoundPosts(): bool|int {
178178
/** @var false|int $time */
179179
$time = wp_cache_get( $this->generateFoundPostCacheKey( true ), Cache::QUERY_CACHE_GROUP );
180180

@@ -186,7 +186,7 @@ private function getTimeFoundPosts() {
186186
}
187187

188188
private function generateFoundPostCacheKey( bool $addTime = false ): string {
189-
return sprintf(
189+
return \sprintf(
190190
'%s%s-%s',
191191
$addTime ? 'time-' : '',
192192
self::FOUND_POSTS_KEY,

src/Utils/AttachmentData.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class AttachmentData {
3636
private readonly string $fullJpegUrl;
3737

3838
/**
39-
* @var null|array<string,array{file: string, width: int, height: int, mime-type: string}>
39+
* @var array<string,array{file: string, width: int, height: int, mime-type: string}>|null
4040
*/
4141
private ?array $attachmentSizes = null;
4242

@@ -63,7 +63,7 @@ public function __construct( int|string $attachmentId = 0 ) {
6363
}
6464

6565
/**
66-
* @return array<string,boolean|int|string>
66+
* @return array<string,bool|int|string>
6767
*/
6868
public function getUrl( string $attachmentSize = self::SIZE_FULL ): array {
6969
$sizeArray = $this->getSizeArray( $attachmentSize, false );
@@ -104,7 +104,7 @@ private function readImgMetadata( string $metadata ): void {
104104
private function getAttachmentFromDb( int|string $attachmentId = 0 ): array {
105105
global $wpdb;
106106

107-
$cacheKey = sprintf( 'attachment_image_%d', (int) $attachmentId );
107+
$cacheKey = \sprintf( 'attachment_image_%d', (int) $attachmentId );
108108

109109
/** @var array{attachmentId:int, fullUrl: string, metadata?: string, imageAlt?: string}|false $attachment */
110110
$attachment = wp_cache_get( $cacheKey, Cache::CACHE_GROUP );
@@ -148,7 +148,7 @@ private function getAttachmentFromDb( int|string $attachmentId = 0 ): array {
148148
}
149149

150150
if ( empty( $attachment ) ) {
151-
throw new InvalidArgumentException( sprintf( 'Invalid image ID, "%d" given.', $attachmentId ) );
151+
throw new InvalidArgumentException( \sprintf( 'Invalid image ID, "%d" given.', $attachmentId ) );
152152
}
153153

154154
/* @var array{attachmentId:int, fullUrl: string, metadata?: string, imageAlt?: string} $attachment */
@@ -171,7 +171,7 @@ private function getAttachmentSizes( string $attachmentSize ): array|false {
171171
}
172172

173173
/**
174-
* @return array<string,boolean|int|string>
174+
* @return array<string,bool|int|string>
175175
*/
176176
private function getSizeArray( string $attachmentSize = self::SIZE_FULL, bool $addDirData = true ): array {
177177
/** @var array<string,int|string> $sizeArray */
@@ -189,7 +189,7 @@ private function getSizeArray( string $attachmentSize = self::SIZE_FULL, bool $a
189189
$sizeArray['height'] = $sizes['height'];
190190
}
191191

192-
$sizeArray['sizes'] = empty( $sizeArray['width'] ) ? false : sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $sizeArray['width'] );
192+
$sizeArray['sizes'] = empty( $sizeArray['width'] ) ? false : \sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $sizeArray['width'] );
193193

194194
if ( $addDirData && ! empty( $this->imgFile ) ) {
195195
$dirname = _wp_get_attachment_relative_path( $this->imgFile );
@@ -235,14 +235,14 @@ private function getImageSrcset( string $attachmentSize = self::SIZE_FULL ): boo
235235
$srcset = [];
236236

237237
foreach ( $sources as $source ) {
238-
$srcset[] = sprintf( '%s %d%s', $source['url'], $source['value'], $source['descriptor'] );
238+
$srcset[] = \sprintf( '%s %d%s', $source['url'], $source['value'], $source['descriptor'] );
239239
}
240240

241241
return implode( ', ', $srcset );
242242
}
243243

244244
/**
245-
* @param array<string,boolean|int|string> $sizeData
245+
* @param array<string,bool|int|string> $sizeData
246246
*
247247
* @return array<array-key, array{url: string, descriptor: string, value: int}>|false
248248
*/

src/Utils/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function load(): void {
1818
}
1919

2020
public static function resetAttachmentCache( int $postId ): void {
21-
wp_cache_delete( sprintf( 'attachment_image_%d', $postId ), self::CACHE_GROUP );
21+
wp_cache_delete( \sprintf( 'attachment_image_%d', $postId ), self::CACHE_GROUP );
2222
}
2323
}

src/helper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ function app_attachment_url_to_postid( string $url ): bool|int {
175175
return false;
176176
}
177177

178-
179178
$guid_url = str_replace( $old_basename, $new_basename, $relative_url );
180179

181180
if ( empty( $guid_url ) ) {

0 commit comments

Comments
 (0)