Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
94f4f22
Add phpstan-strict-rules
westonruter May 23, 2024
211d192
Ignore staticMethod.dynamicCall, booleanNot.exprNotBoolean, and if.co…
westonruter May 23, 2024
f2c5120
Fix cast.useless
westonruter May 23, 2024
0c5c42b
Fix method.childReturnType
westonruter May 23, 2024
66dd4d6
Fix plus.leftNonNumeric
westonruter May 23, 2024
db11733
Disable strictArrayFilter rule
westonruter May 23, 2024
165b15b
Fix variable.implicitArray
westonruter May 23, 2024
d3e0f22
Fix instance of booleanAnd.leftNotBoolean
westonruter May 23, 2024
db82f1e
Update phpstan to 1.11.4
westonruter Jun 13, 2024
7de2d96
Fix interface.nameCase
westonruter Jun 13, 2024
87ecaad
Fix booleanNot.exprNotBoolean
westonruter Jun 13, 2024
44d8375
Fix ternary.condNotBoolean
westonruter Jun 13, 2024
94884c5
Fix booleanOr.rightNotBoolean
westonruter Jun 13, 2024
5b5cd68
Fix booleanAnd.leftNotBoolean
westonruter Jun 13, 2024
dad5312
Fix if.condNotBoolean
westonruter Jun 13, 2024
228035f
Ignore empty.notAllowed temporarily
westonruter Jun 13, 2024
831105c
Treat a boolean src attribute as if it is an inline script
westonruter Jul 11, 2024
b99c7c0
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter Jul 22, 2024
0413c60
Fix remaining strict rule violations
westonruter Jul 23, 2024
350ddbf
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter Jul 23, 2024
d4af3a6
Fix and improve conditions in auto_sizes_filter_image_tag and add typing
westonruter Jul 23, 2024
8e90f62
Remove unnecessary casting to int
westonruter Jul 23, 2024
4f4f6bd
Remove unnecessary casting
westonruter Jul 23, 2024
eaf1f65
Fix logic inversion
westonruter Jul 23, 2024
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
Prev Previous commit
Next Next commit
Fix if.condNotBoolean
  • Loading branch information
westonruter committed Jun 13, 2024
commit dad531239a9309f1d74a4204e8cd21979a8da229
4 changes: 2 additions & 2 deletions plugins/dominant-color-images/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ function dominant_color_img_tag_add_dominant_color( $filtered_image, string $con
$extra_class = $image_meta['has_transparency'] ? 'has-transparency' : 'not-transparent';
}

if ( $data ) {
if ( '' !== $data ) {
$filtered_image = str_replace( '<img ', '<img ' . $data, $filtered_image );
}

if ( $extra_class ) {
if ( '' !== $extra_class ) {
$filtered_image = str_replace( ' class="', ' class="' . $extra_class . ' ', $filtered_image );
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/embed-optimizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function embed_optimizer_filter_oembed_html( string $html ): string {
if ( 1 === $script_count && ! $has_inline_script && $html_processor->has_bookmark( 'script' ) ) {
add_action( 'wp_footer', 'embed_optimizer_lazy_load_scripts' );
if ( $html_processor->seek( 'script' ) ) {
if ( $html_processor->get_attribute( 'type' ) ) {
if ( is_string( $html_processor->get_attribute( 'type' ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Suggested change
if ( is_string( $html_processor->get_attribute( 'type' ) ) ) {
if ( null !== $html_processor->get_attribute( 'type' ) ) ) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I think the code should stay as-is. Since get_attribute can return true in the case of a boolean attribute, we wouldn't want to try passing a true to set_attrbute(). I believe PHPStan would complain about that anyway.

$html_processor->set_attribute( 'data-original-type', $html_processor->get_attribute( 'type' ) );
}
$html_processor->set_attribute( 'type', 'application/vnd.embed-optimizer.javascript' );
Expand All @@ -79,7 +79,7 @@ function embed_optimizer_filter_oembed_html( string $html ): string {
// For post embeds, use visibility:hidden instead of clip since browsers will consistently load the
// lazy-loaded iframe (where Chromium is unreliably with clip) while at the same time improve accessibility
// by preventing links in the hidden iframe from receiving focus.
if ( $html_processor->has_class( 'wp-embedded-content' ) ) {
if ( true === $html_processor->has_class( 'wp-embedded-content' ) ) {
$style = $html_processor->get_attribute( 'style' );
if ( is_string( $style ) ) {
// WordPress core injects this clip CSS property:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function get_lcp_element(): ?array {
}

// Now sort by the breadcrumb counts in descending order, so the remaining first key is the most common breadcrumb.
if ( $seen_breadcrumbs ) {
if ( count( $seen_breadcrumbs ) > 0 ) {
arsort( $breadcrumb_counts );
$most_common_breadcrumb_index = key( $breadcrumb_counts );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function get_url_metrics_from_post( WP_Post $post ): array {
};

$url_metrics_data = json_decode( $post->post_content, true );
if ( json_last_error() ) {
if ( json_last_error() !== 0 ) {
$trigger_warning(
sprintf(
/* translators: 1: Post type slug, 2: Post ID, 3: JSON error message */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private function get_valid_params( array $extras = array() ): array {
$data
);
unset( $data['timestamp'] ); // Since provided by default args.
if ( $extras ) {
if ( count( $extras ) > 0 ) {
$data = $this->recursive_merge( $data, $extras );
}
return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function data_provider(): array {
* @param string $error Error.
*/
public function test_constructor( array $data, string $error = '' ): void {
if ( $error ) {
if ( '' !== $error ) {
$this->expectException( OD_Data_Validation_Exception::class );
$this->expectExceptionMessage( $error );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function data_provider_test_construction(): array {
* @param int $sample_size Sample size.
*/
public function test_construction( array $url_metrics, array $breakpoints, int $sample_size, int $freshness_ttl, string $exception ): void {
if ( $exception ) {
if ( '' !== $exception ) {
$this->expectException( $exception );
}
$group_collection = new OD_URL_Metrics_Group_Collection( $url_metrics, $breakpoints, $sample_size, $freshness_ttl );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function data_provider_test_construction(): array {
* @param string $exception Expected exception.
*/
public function test_construction( array $url_metrics, int $minimum_viewport_width, int $maximum_viewport_width, int $sample_size, int $freshness_ttl, string $exception ): void {
if ( $exception ) {
if ( '' !== $exception ) {
$this->expectException( $exception );
}
$group = new OD_URL_Metrics_Group( $url_metrics, $minimum_viewport_width, $maximum_viewport_width, $sample_size, $freshness_ttl );
Expand Down Expand Up @@ -195,7 +195,7 @@ public function data_provider_test_add_url_metric(): array {
* @dataProvider data_provider_test_add_url_metric
*/
public function test_add_url_metric( int $viewport_width, string $exception ): void {
if ( $exception ) {
if ( '' !== $exception ) {
$this->expectException( $exception );
}
$group = new OD_URL_Metrics_Group( array(), 100, 200, 1, HOUR_IN_SECONDS );
Expand Down
4 changes: 2 additions & 2 deletions plugins/performance-lab/includes/admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ static function ( $name ) {
$activated_plugin_slug = perflab_sanitize_plugin_slug( wp_unslash( $_GET['activate'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}

if ( $activated_plugin_slug ) {
if ( null !== $activated_plugin_slug ) {
$message = __( 'Feature activated.', 'performance-lab' );

$plugin_settings_url = perflab_get_plugin_settings_url( $activated_plugin_slug );
if ( $plugin_settings_url ) {
if ( null !== $plugin_settings_url ) {
/* translators: %s is the settings URL */
$message .= ' ' . sprintf( __( 'Review <a href="%s">settings</a>.', 'performance-lab' ), esc_url( $plugin_settings_url ) );
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/performance-lab/includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
function perflab_query_plugin_info( string $plugin_slug ) {
$plugin = get_transient( 'perflab_plugin_info_' . $plugin_slug );

if ( $plugin ) {
if ( is_array( $plugin ) ) {
/**
* Validated (mostly) plugin data.
*
* @var array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], download_link: string, version: string} $plugin
*/
return $plugin;
}

Expand Down Expand Up @@ -400,7 +405,7 @@ function perflab_render_plugin_card( array $plugin_data ): void {

if ( $availability['activated'] ) {
$settings_url = perflab_get_plugin_settings_url( $plugin_data['slug'] );
if ( $settings_url ) {
if ( null !== $settings_url ) {
/* translators: %s is the settings URL */
$action_links[] = sprintf( '<a href="%s">%s</a>', esc_url( $settings_url ), esc_html__( 'Settings', 'performance-lab' ) );
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/performance-lab/includes/server-timing/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function perflab_rest_post_dispatch_add_server_timing( $response ) {

$header_value = $server_timing->get_header();

if ( $header_value ) {
if ( '' !== $header_value ) {
$response->header( 'Server-Timing', $header_value, false );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function perflab_aea_get_total_size_bytes_enqueued_scripts() {
function perflab_aea_get_total_enqueued_styles() {
$enqueued_styles = false;
$list_enqueued_styles = get_transient( 'aea_enqueued_front_page_styles' );
if ( $list_enqueued_styles ) {
if ( is_array( $list_enqueued_styles ) ) {
$enqueued_styles = count( $list_enqueued_styles );
}
return $enqueued_styles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PLSR_URL_Pattern_Prefixer {
* by the {@see PLSR_URL_Pattern_Prefixer::get_default_contexts()} method.
*/
public function __construct( array $contexts = array() ) {
if ( $contexts ) {
if ( count( $contexts ) > 0 ) {
$this->contexts = array_map(
static function ( string $str ): string {
return self::escape_pattern_string( trailingslashit( $str ) );
Expand Down
4 changes: 2 additions & 2 deletions plugins/webp-uploads/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ function webp_uploads_create_sources_property( array $metadata, int $attachment_
if ( ! empty( $metadata['original_image'] ) ) {
$uploadpath = wp_get_upload_dir();
$attached_file = get_attached_file( $attachment_id );
if ( $attached_file ) {
if ( false !== $attached_file ) {
wp_delete_file_from_directory( $attached_file, $uploadpath['basedir'] );
}
}

// Replace the attached file with the custom MIME type version.
if ( $original_image ) {
if ( false !== $original_image ) {
$metadata = _wp_image_meta_replace_original( $saved_data, $original_image, $metadata, $attachment_id );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
exit( 1 );
}

if ( preg_match( '/^ \* Requires Plugins:\s*(.+)$/m', (string) file_get_contents( $plugin_file ), $matches ) ) {
if ( 0 < (int) preg_match( '/^ \* Requires Plugins:\s*(.+)$/m', (string) file_get_contents( $plugin_file ), $matches ) ) {
foreach ( (array) preg_split( '/\s*,\s*/', $matches[1] ) as $requires_plugin ) {
$load_plugin( (string) $requires_plugin );
}
Expand Down