From 65c41e59e147a12251a5aaf0e07cecfa81d5fe7f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 25 Jun 2024 17:13:13 +0200 Subject: [PATCH] More type fixes --- includes/Admin/Customizer.php | 4 +++- includes/Infrastructure/ServiceBasedPlugin.php | 10 +++++++--- includes/Integrations/Site_Kit.php | 2 +- includes/KSES.php | 2 +- includes/Media/Media_Source_Taxonomy.php | 3 +++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/Admin/Customizer.php b/includes/Admin/Customizer.php index 98a582a5df1a..69f1a7f8ea38 100644 --- a/includes/Admin/Customizer.php +++ b/includes/Admin/Customizer.php @@ -726,7 +726,9 @@ private function parse_args( array $args, array $defaults = [] ): array { * * @var array|bool|int|string>>> $def */ - $def = $parsed_args[ $key ]; + $def = $parsed_args[ $key ]; + + // @phpstan-ignore argument.type (TODO: improve type for recursion) $parsed_args[ $key ] = $this->parse_args( $value, $def ); } else { $parsed_args[ $key ] = $value; diff --git a/includes/Infrastructure/ServiceBasedPlugin.php b/includes/Infrastructure/ServiceBasedPlugin.php index 351ffcb8bb3c..4eb0d75b66ee 100644 --- a/includes/Infrastructure/ServiceBasedPlugin.php +++ b/includes/Infrastructure/ServiceBasedPlugin.php @@ -401,7 +401,7 @@ protected function get_registration_action_priority( string $class_name, array & /** * Missing requirement. * - * @phpstan-var class-string $missing_requirement + * @phpstan-var class-string $missing_requirement */ $requirement_priority = $this->get_registration_action_priority( $missing_requirement, $services ); @@ -570,11 +570,14 @@ protected function validate_services( array $services ): array { // Verify that the FQCN is valid and points to an existing class. // If not, skip this service. - if ( empty( $fqcn ) || ! \is_string( $fqcn ) || ! class_exists( $fqcn ) ) { + if ( empty( $fqcn ) || ! class_exists( $fqcn ) ) { unset( $services[ $identifier ] ); } } + /** + * @phpstan-var array> $services + */ return $services; } @@ -692,6 +695,7 @@ protected function instantiate_service( $class_name ): Service { // The service needs to be registered, so instantiate right away. $service = $this->injector->make( $class_name ); + // @phpstan-ignore instanceof.alwaysTrue if ( ! $service instanceof Service ) { throw InvalidService::from_service( $service ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } @@ -916,7 +920,7 @@ protected function get_delegations(): array { * @phpstan-return class-string Resolved or unchanged value. */ protected function maybe_resolve( $value ): string { - if ( \is_callable( $value ) && ! ( \is_string( $value ) && \function_exists( $value ) ) ) { + if ( ! ( \is_string( $value ) && \function_exists( $value ) ) && \is_callable( $value ) ) { $value = $value( $this->injector, $this->service_container ); } diff --git a/includes/Integrations/Site_Kit.php b/includes/Integrations/Site_Kit.php index 888328bf3d15..2ed0592f93e3 100644 --- a/includes/Integrations/Site_Kit.php +++ b/includes/Integrations/Site_Kit.php @@ -135,7 +135,7 @@ public function filter_site_kit_gtag_opt( $gtag_opt ) { ! \is_array( $gtag_opt ) || ! \is_array( $gtag_opt['vars'] ) || ! isset( $gtag_opt['vars']['gtag_id'] ) || - ! is_string( $gtag_opt['vars']['gtag_id'] ) || + ! \is_string( $gtag_opt['vars']['gtag_id'] ) || ! $this->context->is_web_story() ) { return $gtag_opt; diff --git a/includes/KSES.php b/includes/KSES.php index 4c9ba21e37cc..abdc39a52d97 100644 --- a/includes/KSES.php +++ b/includes/KSES.php @@ -136,7 +136,7 @@ public function filter_insert_post_data( $data, $postarr, $unsanitized_postarr ) } if ( - ! \is_string( $data['post_type'] ) || + ! \is_string( $data['post_type'] ) || ! $this->is_allowed_post_type( $data['post_type'], $data['post_parent'] ) ) { return $data; diff --git a/includes/Media/Media_Source_Taxonomy.php b/includes/Media/Media_Source_Taxonomy.php index 5ba473c7466e..e1c84aac1cdb 100644 --- a/includes/Media/Media_Source_Taxonomy.php +++ b/includes/Media/Media_Source_Taxonomy.php @@ -184,6 +184,7 @@ public function wp_prepare_attachment_for_js( $response ) { return $response; } + // @phpstan-ignore argument.type (TODO: improve type) $response[ self::MEDIA_SOURCE_KEY ] = $this->get_callback_media_source( $response ); return $response; @@ -249,6 +250,7 @@ public function filter_ajax_query_attachments_args( $args ) { return $args; } + // @phpstan-ignore argument.type (TODO: improve type) $args['tax_query'] = $this->get_exclude_tax_query( $args ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query return $args; @@ -290,6 +292,7 @@ public function filter_rest_generated_media_attachments( $args ) { return $args; } + // @phpstan-ignore argument.type (TODO: improve type) $args['tax_query'] = $this->get_exclude_tax_query( $args ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query return $args;