Skip to content

Commit

Permalink
WordPress#718: Fix lint and phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurdybanowski committed Jul 25, 2024
1 parent 37fe48b commit 061657f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function get_dominant_color() {
$shorted_image = imagecreatetruecolor( 1, 1 );
$image_width = imagesx( $this->image );
$image_height = imagesy( $this->image );
if ( false === $shorted_image || false === $image_width || false === $image_height ) {
if ( false === $shorted_image || false === $image_width || false === $image_height ) { // @phpstan-ignore-line
return new WP_Error( 'image_editor_dominant_color_error', __( 'Dominant color detection failed.', 'dominant-color-images' ) );
}
imagecopyresampled( $shorted_image, $this->image, 0, 0, 0, 0, 1, 1, $image_width, $image_height );
Expand Down Expand Up @@ -78,7 +78,7 @@ public function has_transparency() {
return new WP_Error( 'unable_to_obtain_rgb_via_imagecolorat' );
}
$rgba = imagecolorsforindex( $this->image, $rgb );
if ( ! is_array( $rgba ) ) {
if ( ! is_array( $rgba ) ) { // @phpstan-ignore-line
return new WP_Error( 'unable_to_obtain_rgba_via_imagecolorsforindex' );
}
if ( $rgba['alpha'] > 0 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke( OD_HTML_Tag_Walker $walker ): bool {
&&
0 < (int) preg_match( '/background(-image)?\s*:[^;]*?url\(\s*[\'"]?\s*(?<background_image>.+?)\s*[\'"]?\s*\)/', $style, $matches )
&&
'' !== $matches['background_image'] // PHPStan should ideally know that this is a non-empty string based on the `.+?` regular expression.
'' !== $matches['background_image'] // PHPStan should ideally know that this is a non-empty string based on the `.+?` regular expression. // @phpstan-ignore-line
&&
! $this->is_data_url( $matches['background_image'] )
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
/**
* Callback for Object Cache Info fields.
*
* @return array Fields.
* @return array<string, array{label: string, value: string}> Fields.
* @since 3.3.0
*/
function object_cache_supported_fields() {
function object_cache_supported_fields(): array {
return array(
'extension' => array(
'label' => __( 'Extension', 'performance-lab' ),
Expand All @@ -42,24 +42,26 @@ function object_cache_supported_fields() {
}

/**
* Attempts to determine which object cache is being used.
* Attempts to determine which object cache is being used as in wp-cli repository.
*
* Note that the guesses made by this function are based on the WP_Object_Cache classes
* that define the 3rd party object cache extension. Changes to those classes could render
* problems with this function's ability to determine which object cache is being used.
*
* @return string
* @return string Object cache type.
* @since 3.3.0
*/
function wp_get_cache_type() {
function wp_get_cache_type(): string {
global $_wp_using_ext_object_cache, $wp_object_cache;

$message = '';

if ( ! empty( $_wp_using_ext_object_cache ) ) {
// Test for Memcached PECL extension memcached object cache (https://github.com/tollmanz/wordpress-memcached-backend)
// Test for Memcached PECL extension memcached object cache (https://github.com/tollmanz/wordpress-memcached-backend).
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) {
$message = 'Memcached';

// Test for Memcache PECL extension memcached object cache (https://wordpress.org/extend/plugins/memcached/)
// Test for Memcache PECL extension memcached object cache (https://wordpress.org/extend/plugins/memcached/).
} elseif ( isset( $wp_object_cache->mc ) ) {
$is_memcache = true;
foreach ( $wp_object_cache->mc as $bucket ) {
Expand All @@ -72,33 +74,32 @@ function wp_get_cache_type() {
$message = 'Memcache';
}

// Test for Xcache object cache (https://plugins.svn.wordpress.org/xcache/trunk/object-cache.php)
} elseif ( $wp_object_cache instanceof \XCache_Object_Cache ) {
// Test for Xcache object cache (https://plugins.svn.wordpress.org/xcache/trunk/object-cache.php).
} elseif ( $wp_object_cache instanceof \XCache_Object_Cache ) { // @phpstan-ignore-line
$message = 'Xcache';

// Test for WinCache object cache (https://wordpress.org/extend/plugins/wincache-object-cache-backend/)
// Test for WinCache object cache (https://wordpress.org/extend/plugins/wincache-object-cache-backend/).
} elseif ( class_exists( 'WinCache_Object_Cache' ) ) {
$message = 'WinCache';

// Test for APC object cache (https://wordpress.org/extend/plugins/apc/)
// Test for APC object cache (https://wordpress.org/extend/plugins/apc/).
} elseif ( class_exists( 'APC_Object_Cache' ) ) {
$message = 'APC';

// Test for WP Redis (https://wordpress.org/plugins/wp-redis/)
// Test for WP Redis (https://wordpress.org/plugins/wp-redis/).
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof \Redis ) {
$message = 'Redis';

// Test for Redis Object Cache (https://wordpress.org/plugins/redis-cache/)
} elseif ( method_exists( $wp_object_cache, 'redis_instance' ) && method_exists( $wp_object_cache,
'redis_status' ) ) {
// Test for Redis Object Cache (https://wordpress.org/plugins/redis-cache/).
} elseif ( method_exists( $wp_object_cache, 'redis_instance' ) && method_exists( $wp_object_cache, 'redis_status' ) ) {
$message = 'Redis';

// Test for Object Cache Pro (https://objectcache.pro/)
// Test for Object Cache Pro (https://objectcache.pro/).
} elseif ( method_exists( $wp_object_cache, 'config' ) && method_exists( $wp_object_cache, 'connection' ) ) {
$message = 'Redis';

// Test for WP LCache Object cache (https://github.com/lcache/wp-lcache)
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \LCache\Integrated ) {
// Test for WP LCache Object cache (https://github.com/lcache/wp-lcache).
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \LCache\Integrated ) { // @phpstan-ignore-line
$message = 'WP LCache';

} elseif ( function_exists( 'w3_instance' ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
/**
* Adds Object Cache module to Site Health Info.
*
* @param array $info Site Health Info.
* @param array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} $info Site Health Info.
*
* @return array Amended Info.
* @return array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} Amended Info. * @since 3.3.0
* @since 3.3.0
*
*/
function object_cache_supported_info( array $info ): array {
$info['object_cache'] = array(
'label' => __( 'Object Caching', 'performance-lab' ),
'description' => __( 'Shows which features object cache supports and if object caching is in use.',
'performance-lab' ),
'description' => __( 'Shows which features object cache supports and if object caching is in use.', 'performance-lab' ),
'fields' => object_cache_supported_fields(),
);

Expand Down
2 changes: 1 addition & 1 deletion plugins/webp-uploads/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function webp_uploads_update_image_references( $content ): string {
continue;
}

if ( empty( $class_name ) ) {
if ( empty( $class_name ) ) { // @phpstan-ignore-line
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/webp-uploads/tests/test-image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test_it_should_backup_the_sources_structure_alongside_the_full_s
foreach ( $backup_sizes as $size => $properties ) {
$size_name = str_replace( '-orig', '', $size );

if ( 'full-orig' === $size ) {
if ( 'full-orig' === $size ) { // @phpstan-ignore-line
continue;
}

Expand Down

0 comments on commit 061657f

Please sign in to comment.