Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate usage of empty() construct #1803

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,3 @@ parameters:
-
identifier: staticMethod.dynamicCall
path: */tests/*
-
# TODO: Remove this to fix https://github.com/WordPress/performance/issues/1219
identifier: empty.notAllowed
paths:
- */tests/*
- plugins/dominant-color-images
- plugins/performance-lab
- plugins/webp-uploads
13 changes: 7 additions & 6 deletions plugins/dominant-color-images/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@
$attr['data-has-transparency'] = $image_meta['has_transparency'] ? 'true' : 'false';

$class = $image_meta['has_transparency'] ? 'has-transparency' : 'not-transparent';
if ( empty( $attr['class'] ) ) {
$attr['class'] = $class;
} else {

if ( isset( $attr['class'] ) && is_string( $attr['class'] ) && '' !== $attr['class'] ) {
$attr['class'] .= ' ' . $class;
} else {
$attr['class'] = $class;

Check warning on line 70 in plugins/dominant-color-images/hooks.php

View check run for this annotation

Codecov / codecov/patch

plugins/dominant-color-images/hooks.php#L70

Added line #L70 was not covered by tests
}
}

if ( ! empty( $image_meta['dominant_color'] ) ) {
if ( isset( $image_meta['dominant_color'] ) && is_string( $image_meta['dominant_color'] ) && '' !== $image_meta['dominant_color'] ) {
$attr['data-dominant-color'] = esc_attr( $image_meta['dominant_color'] );
$style_attribute = empty( $attr['style'] ) ? '' : $attr['style'];
$style_attribute = isset( $attr['style'] ) && is_string( $attr['style'] ) ? $attr['style'] : '';
$attr['style'] = '--dominant-color: #' . esc_attr( $image_meta['dominant_color'] ) . ';' . $style_attribute;
}

Expand Down Expand Up @@ -138,7 +139,7 @@
return $filtered_image;
}

if ( ! empty( $image_meta['dominant_color'] ) ) {
if ( isset( $image_meta['dominant_color'] ) && is_string( $image_meta['dominant_color'] ) && '' !== $image_meta['dominant_color'] ) {
$processor->set_attribute( 'data-dominant-color', $image_meta['dominant_color'] );

$style_attribute = '--dominant-color: #' . $image_meta['dominant_color'] . '; ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static function ( $value ) {
*/
public function use_output_buffer(): bool {
$options = (array) get_option( PERFLAB_SERVER_TIMING_SETTING, array() );
$enabled = ! empty( $options['output_buffering'] );
$enabled = isset( $options['output_buffering'] ) && (bool) $options['output_buffering'];

/**
* Filters whether an output buffer should be used to be able to gather additional Server-Timing metrics.
Expand All @@ -220,7 +220,7 @@ public function use_output_buffer(): bool {
*
* @since 1.8.0
*
* @param bool $use_output_buffer Whether to use an output buffer.
* @param bool $enabled Whether to use an output buffer.
*/
return (bool) apply_filters( 'perflab_server_timing_use_output_buffer', $enabled );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function perflab_aao_handle_update_autoload(): void {
wp_die( esc_html__( 'Permission denied.', 'performance-lab' ) );
}

if ( empty( $option_name ) ) {
if ( '' === $option_name ) {
wp_die( esc_html__( 'Invalid option name.', 'performance-lab' ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ function perflab_aea_audit_enqueued_scripts(): void {

// Add any extra data (inlined) that was passed with the script.
$inline_size = 0;
if ( ! empty( $script->extra ) && ! empty( $script->extra['after'] ) ) {
if (
property_exists( $script, 'extra' ) &&
isset( $script->extra['after'] ) &&
is_array( $script->extra['after'] )
) {
foreach ( $script->extra['after'] as $extra ) {
$inline_size += ( is_string( $extra ) ) ? mb_strlen( $extra, '8bit' ) : 0;
}
Expand Down Expand Up @@ -76,7 +80,12 @@ function perflab_aea_audit_enqueued_styles(): void {
}

// Check if we already have the style's path ( part of a refactor for block styles from 5.9 ).
if ( ! empty( $style->extra ) && ! empty( $style->extra['path'] ) ) {
if (
property_exists( $style, 'extra' ) &&
isset( $style->extra['path'] ) &&
is_string( $style->extra['path'] ) &&
'' !== $style->extra['path']
) {
$path = $style->extra['path'];
} else { // Fallback to getting the path from the style's src.
$path = perflab_aea_get_path_from_resource_url( $style->src );
Expand All @@ -87,7 +96,11 @@ function perflab_aea_audit_enqueued_styles(): void {

// Add any extra data (inlined) that was passed with the style.
$inline_size = 0;
if ( ! empty( $style->extra ) && ! empty( $style->extra['after'] ) ) {
if (
property_exists( $style, 'extra' ) &&
isset( $style->extra['after'] ) &&
is_array( $style->extra['after'] )
) {
foreach ( $style->extra['after'] as $extra ) {
$inline_size += ( is_string( $extra ) ) ? mb_strlen( $extra, '8bit' ) : 0;
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/webp-uploads/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
$metadata = wp_get_attachment_metadata( $attachment_id );

// Return full image size sources.
if ( 'full' === $size && ! empty( $metadata['sources'] ) ) {
if (
'full' === $size &&
isset( $metadata['sources'] ) &&
is_array( $metadata['sources'] ) &&
count( $metadata['sources'] ) > 0

Check warning on line 35 in plugins/webp-uploads/deprecated.php

View check run for this annotation

Codecov / codecov/patch

plugins/webp-uploads/deprecated.php#L32-L35

Added lines #L32 - L35 were not covered by tests
) {
return $metadata['sources'];
}

// Return the resized image sources.
if ( ! empty( $metadata['sizes'][ $size ]['sources'] ) ) {
if ( isset( $metadata['sizes'][ $size ]['sources'] ) && is_array( $metadata['sizes'][ $size ]['sources'] ) ) {

Check warning on line 41 in plugins/webp-uploads/deprecated.php

View check run for this annotation

Codecov / codecov/patch

plugins/webp-uploads/deprecated.php#L41

Added line #L41 was not covered by tests
return $metadata['sizes'][ $size ]['sources'];
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/webp-uploads/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function webp_uploads_get_upload_image_mime_transforms(): array {
// Ensure that all mime types have correct transforms. If a mime type has invalid transforms array,
// then fallback to the original mime type to make sure that the correct subsizes are created.
foreach ( $transforms as $mime_type => $transform_types ) {
if ( ! is_array( $transform_types ) || empty( $transform_types ) ) {
if ( ! is_array( $transform_types ) || 0 === count( $transform_types ) ) {
$transforms[ $mime_type ] = array( $mime_type );
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri

$image_meta = wp_get_attachment_metadata( $attachment_id );
// If stored EXIF data exists, rotate the source image before creating sub-sizes.
if ( ! empty( $image_meta['image_meta'] ) ) {
if ( isset( $image_meta['image_meta'] ) && is_array( $image_meta['image_meta'] ) && count( $image_meta['image_meta'] ) > 0 ) {
$editor->maybe_exif_rotate();
}

Expand All @@ -183,7 +183,7 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri
return $image;
}

if ( empty( $image['file'] ) ) {
if ( ! isset( $image['file'] ) ) {
return new WP_Error( 'image_file_not_present', __( 'The file key is not present on the image data', 'webp-uploads' ) );
}

Expand Down
Loading
Loading