Skip to content

Commit 407e4fe

Browse files
dev: fix reported PHPStan v2 errors
1 parent 032e673 commit 407e4fe

File tree

12 files changed

+34
-43
lines changed

12 files changed

+34
-43
lines changed

inc/admin.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,11 @@ public function inline_bootstrap_script() {
576576
/**
577577
* Add settings links in the plugin listing page.
578578
*
579-
* @param array $links Old plugin links.
579+
* @param string[] $links Old plugin links.
580580
*
581-
* @return array Altered links.
581+
* @return string[] Altered links.
582582
*/
583583
public function add_action_links( $links ) {
584-
if ( ! is_array( $links ) ) {
585-
return $links;
586-
}
587-
588584
return array_merge(
589585
$links,
590586
[
@@ -599,7 +595,7 @@ public function add_action_links( $links ) {
599595
* @return bool Should show?
600596
*/
601597
public function should_show_notice() {
602-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
598+
if ( wp_doing_ajax() ) {
603599
return false;
604600
}
605601

@@ -676,7 +672,7 @@ public function add_notice_upgrade() {
676672
*/
677673
public function should_show_upgrade() {
678674
$current_screen = get_current_screen();
679-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
675+
if ( wp_doing_ajax() ||
680676
is_network_admin() ||
681677
! current_user_can( 'manage_options' ) ||
682678
! $this->settings->is_connected() ||
@@ -1003,7 +999,7 @@ public function maybe_redirect() {
1003999
return;
10041000
}
10051001

1006-
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1002+
if ( wp_doing_ajax() ) {
10071003
return;
10081004
}
10091005

inc/api.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ public function request( $path, $method = 'GET', $params = [], $extra_headers =
160160
if ( ! empty( $this->api_key ) ) {
161161
$headers['Authorization'] = 'Bearer ' . $this->api_key;
162162
}
163-
if ( is_array( $headers ) ) {
164-
$headers = array_merge( $headers, $extra_headers );
165-
}
163+
$headers = array_merge( $headers, $extra_headers );
166164
$url = trailingslashit( $this->api_root ) . ltrim( $path, '/' );
167165
// If there is a extra, add that as a url var.
168166
if ( 'GET' === $method && ! empty( $params ) ) {

inc/app_replacer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public static function listen_to_sizes( $value, $orig_w, $orig_h, $dest_w, $dest
490490
/**
491491
* Extract domains and use them as keys for fast processing.
492492
*
493-
* @param array $urls Input urls.
493+
* @param array|null $urls Input urls.
494494
*
495495
* @return array Array of domains as keys.
496496
*/
@@ -529,7 +529,7 @@ function ( $value ) {
529529
/**
530530
* Check if we can replace the url.
531531
*
532-
* @param string $url Url to change.
532+
* @param string|mixed $url Url to change.
533533
*
534534
* @return bool Either we can replace this url or not.
535535
*/
@@ -668,7 +668,7 @@ protected function get_optimized_image_url( $url, $width, $height, $resize = []
668668
->width( $width )
669669
->height( $height );
670670

671-
if ( is_array( $resize ) && ! empty( $resize['type'] ) ) {
671+
if ( ! empty( $resize['type'] ) ) {
672672
$optimized_image->resize( $resize['type'], $resize['gravity'] ?? Position::CENTER, $resize['enlarge'] ?? false );
673673

674674
}

inc/compatibilities/pinterest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function should_load() {
3131
$selectors_array[] = '.heateorSssSharing.heateorSssPinterestBackground';
3232
$load = true;
3333
}
34-
$this->selectors = implode( ', ', array_filter( $selectors_array ) );
34+
$this->selectors = implode( ', ', $selectors_array );
3535
return $load;
3636
}
3737

inc/conflicts/conflicting_plugins.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function dismiss_conflicting_plugins() {
158158
* @return bool Should show?
159159
*/
160160
public function should_show_notice() {
161-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
161+
if ( wp_doing_ajax() ) {
162162
return false;
163163
}
164164

inc/manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function replace_content( $html, $partial = false ) {
435435
$hmac = wp_hash( $profile_id . $time, 'nonce' );
436436
$js_optimizer = str_replace(
437437
[ Profile::PLACEHOLDER, Profile::PLACEHOLDER_MISSING, Profile::PLACEHOLDER_TIME, Profile::PLACEHOLDER_HMAC ],
438-
[ $profile_id, implode( ',', $missing ), $time, $hmac ],
438+
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac ],
439439
$js_optimizer
440440
);
441441
$html = str_replace( Optml_Admin::get_optimizer_script( true ), $js_optimizer, $html );

inc/media_offload.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,15 @@ public static function get_image_size_from_width( $sizes, $width, $filename, $ju
376376
/**
377377
* Replace image URLs in the srcset attributes.
378378
*
379-
* @param array $sources Array of image sources.
380-
* @param array $size_array Array of width and height values in pixels (in that order).
381-
* @param string $image_src The 'src' of the image.
382-
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
383-
* @param int $attachment_id Image attachment ID.
379+
* @param array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
380+
* @param array{0: int, 1: int} $size_array Array of width and height values in pixels (in that order).
381+
* @param string $image_src The 'src' of the image.
382+
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
383+
* @param int $attachment_id Image attachment ID or 0.
384384
*
385385
* @return array
386386
*/
387387
public function calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
388-
if ( ! is_array( $sources ) ) {
389-
return $sources;
390-
}
391388

392389
if ( $this->is_legacy_offloaded_attachment( $attachment_id ) ) {
393390
if ( ! Optml_Media_Offload::is_uploaded_image( $image_src ) || ! isset( $image_meta['file'] ) || ! Optml_Media_Offload::is_uploaded_image( $image_meta['file'] ) ) {

inc/media_rename/attachment_db_renamer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private function replace_in_data( $data, $old_url, $new_url ) {
551551
/**
552552
* Check if a string is serialized
553553
*
554-
* @param string $data String to check.
554+
* @param string|mixed $data String to check.
555555
*
556556
* @return bool True if serialized
557557
*/

inc/rest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ private function fetch_sample_image() {
631631
/**
632632
* Disconnect from optimole service.
633633
*
634-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
635634
* @param WP_REST_Request $request disconnect rest request.
636635
*/
637636
public function disconnect( WP_REST_Request $request ) {
@@ -784,7 +783,7 @@ public function check_redirects( WP_REST_Request $request ) {
784783

785784
if ( $processed_images > 0 ) {
786785
$response = wp_remote_get( $value['src'][ rand( 0, $processed_images - 1 ) ], $args );
787-
if ( ! is_wp_error( $response ) && is_array( $response ) ) {
786+
if ( ! is_wp_error( $response ) ) {
788787
$headers = $response['headers']; // array of http header lines
789788
$status_code = $response['response']['code'];
790789
if ( $status_code === 301 ) {

inc/tag_replacer.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,15 @@ public function regular_tag_replace( $new_tag, $original_url, $new_url, $optml_a
430430
/**
431431
* Replace image URLs in the srcset attributes and in case there is a resize in action, also replace the sizes.
432432
*
433-
* @param array $sources Array of image sources.
434-
* @param array $size_array Array of width and height values in pixels (in that order).
435-
* @param string $image_src The 'src' of the image.
436-
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
437-
* @param int $attachment_id Image attachment ID.
433+
* @param array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
434+
* @param array{0: int, 1: int}|int[] $size_array Array of width and height values in pixels (in that order).
435+
* @param string $image_src The 'src' of the image.
436+
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
437+
* @param int $attachment_id Image attachment ID or 0.
438438
*
439439
* @return array
440440
*/
441441
public function filter_srcset_attr( $sources = [], $size_array = [], $image_src = '', $image_meta = [], $attachment_id = 0 ) {
442-
443-
if ( ! is_array( $sources ) ) {
444-
return $sources;
445-
}
446-
447442
if ( Optml_Media_Offload::is_uploaded_image( $image_src ) ) {
448443
return $sources;
449444
}
@@ -513,10 +508,10 @@ public function filter_srcset_attr( $sources = [], $size_array = [], $image_src
513508
/**
514509
* Filters sizes attribute of the images.
515510
*
516-
* @param array $sizes An array of media query breakpoints.
517-
* @param array $size Width and height of the image.
511+
* @param string $sizes An array of media query breakpoints.
512+
* @param string|int[] $size Width and height of the image.
518513
*
519-
* @return mixed An array of media query breakpoints.
514+
* @return string An array of media query breakpoints.
520515
*/
521516
public function filter_sizes_attr( $sizes, $size ) {
522517

0 commit comments

Comments
 (0)