diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index 9d019b4d..134fd5f2 100644 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] + php-versions: [ '8.0', '8.1', '8.2', '8.3' ] services: database: image: mysql:latest @@ -41,7 +41,7 @@ jobs: - name: Setup PHP version uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-version }} + php-version: ${{ matrix.php-versions }} extensions: simplexml, mysql tools: phpunit-polyfills:1.1 - name: Checkout source code diff --git a/composer.lock b/composer.lock index d743021e..18aefafa 100644 --- a/composer.lock +++ b/composer.lock @@ -904,11 +904,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.31", + "version": "2.1.32", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ead89849d879fe203ce9292c6ef5e7e76f867b96", - "reference": "ead89849d879fe203ce9292c6ef5e7e76f867b96", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e126cad1e30a99b137b8ed75a85a676450ebb227", + "reference": "e126cad1e30a99b137b8ed75a85a676450ebb227", "shasum": "" }, "require": { @@ -953,7 +953,7 @@ "type": "github" } ], - "time": "2025-10-10T14:14:11+00:00" + "time": "2025-11-11T15:18:17+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/inc/admin.php b/inc/admin.php index 6f9f8884..0b5b705c 100755 --- a/inc/admin.php +++ b/inc/admin.php @@ -575,11 +575,14 @@ public function inline_bootstrap_script() { /** * Add settings links in the plugin listing page. * - * @param string[] $links Old plugin links. + * @param string[]|mixed $links Old plugin links. * - * @return string[] Altered links. + * @return string[]|mixed Altered links. */ public function add_action_links( $links ) { + if ( ! is_array( $links ) ) { + return $links; + } return array_merge( $links, [ diff --git a/inc/app_replacer.php b/inc/app_replacer.php index 6ed4dbc2..a76d7654 100644 --- a/inc/app_replacer.php +++ b/inc/app_replacer.php @@ -654,10 +654,10 @@ public function url_has_dam_flag( $url ) { /** * Get the optimized image url for the image url. * - * @param string $url The image URL. - * @param mixed $width The image width. - * @param mixed $height The image height. - * @param array $resize The resize properties. + * @param string $url The image URL. + * @param mixed $width The image width. + * @param mixed $height The image height. + * @param array|mixed $resize The resize properties. * * @return string */ @@ -668,7 +668,7 @@ protected function get_optimized_image_url( $url, $width, $height, $resize = [] ->width( $width ) ->height( $height ); - if ( ! empty( $resize['type'] ) ) { + if ( is_array( $resize ) && ! empty( $resize['type'] ) ) { $optimized_image->resize( $resize['type'], $resize['gravity'] ?? Position::CENTER, $resize['enlarge'] ?? false ); } diff --git a/inc/lazyload_replacer.php b/inc/lazyload_replacer.php index 15fd4534..1284a71e 100644 --- a/inc/lazyload_replacer.php +++ b/inc/lazyload_replacer.php @@ -115,6 +115,11 @@ public static function get_background_lazyload_selectors() { return self::$background_lazyload_selectors; } + if ( self::instance()->settings === null ) { + self::$background_lazyload_selectors = []; + + return self::$background_lazyload_selectors; + } if ( self::instance()->settings->get( 'bg_replacer' ) === 'disabled' ) { self::$background_lazyload_selectors = []; return self::$background_lazyload_selectors; diff --git a/inc/tag_replacer.php b/inc/tag_replacer.php index 75372f50..78cc5f87 100644 --- a/inc/tag_replacer.php +++ b/inc/tag_replacer.php @@ -809,15 +809,18 @@ public function change_url_for_size( $original_url, $width, $height, $dpr = 1 ) /** * Replace image URLs in the srcset attributes and in case there is a resize in action, also replace the sizes. * - * @param array $sources Array of image sources. - * @param array{0: int, 1: int}|int[] $size_array Array of width and height values in pixels (in that order). - * @param string $image_src The 'src' of the image. - * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. - * @param int $attachment_id Image attachment ID or 0. + * @param array|mixed $sources Array of image sources. + * @param array{0: int, 1: int}|int[] $size_array Array of width and height values in pixels (in that order). + * @param string $image_src The 'src' of the image. + * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. + * @param int $attachment_id Image attachment ID or 0. * - * @return array + * @return array|mixed */ public function filter_srcset_attr( $sources = [], $size_array = [], $image_src = '', $image_meta = [], $attachment_id = 0 ) { + if ( ! is_array( $sources ) ) { + return $sources; + } if ( Optml_Media_Offload::is_uploaded_image( $image_src ) ) { return $sources; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index deb5805c..a002da25 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -516,12 +516,6 @@ parameters: count: 1 path: inc/app_replacer.php - - - message: '#^Method Optml_App_Replacer\:\:get_optimized_image_url\(\) has parameter \$resize with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: inc/app_replacer.php - - message: '#^Method Optml_App_Replacer\:\:get_upload_resource\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -2790,12 +2784,6 @@ parameters: count: 1 path: inc/tag_replacer.php - - - message: '#^Method Optml_Tag_Replacer\:\:filter_srcset_attr\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: inc/tag_replacer.php - - message: '#^Method Optml_Tag_Replacer\:\:init\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/tests/test-lazyload-viewport.php b/tests/test-lazyload-viewport.php index dfeb8c66..93930c70 100644 --- a/tests/test-lazyload-viewport.php +++ b/tests/test-lazyload-viewport.php @@ -489,7 +489,7 @@ private function storeMockProfileData( $deviceType, $above_fold_images = [], $bgSelectors = [], - $lcpData = [], + $lcpData = [] ) { Optml_Manager::instance()->page_profiler->store( $profileId,