From 63e39acb50819af2f7844a9c2e8d3b1795ceb702 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 11 Feb 2026 15:09:39 +0100 Subject: [PATCH] Fix newly reported PHPStan issues --- composer.json | 2 +- src/Fetch_Command.php | 38 +------------------------------------- src/Provider_Command.php | 2 ++ 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index b172bbe..e87b978 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "wp-cli/wp-cli": "^2.12" + "wp-cli/wp-cli": "^2.13" }, "require-dev": { "wp-cli/entity-command": "^1.3 || ^2", diff --git a/src/Fetch_Command.php b/src/Fetch_Command.php index 6ada816..d97b325 100644 --- a/src/Fetch_Command.php +++ b/src/Fetch_Command.php @@ -168,7 +168,7 @@ function ( $ret, $data, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunc if ( ! class_exists( 'SimpleXMLElement' ) ) { WP_CLI::error( "The PHP extension 'SimpleXMLElement' is not available but is required for XML-formatted output." ); } - WP_CLI::log( (string) $this->oembed_create_xml( (array) $data ) ); + WP_CLI::log( (string) _oembed_create_xml( (array) $data ) ); } else { WP_CLI::log( (string) json_encode( $data ) ); } @@ -211,40 +211,4 @@ function ( $ret, $data, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunc WP_CLI::log( $html ); } - - /** - * Creates an XML string from a given array. - * - * Same as `\_oembed_create_xml()` in "wp-includes\embed.php" introduced in WP 4.4.0. Polyfilled as marked private (and also to cater for older WP versions). - * - * @see _oembed_create_xml() - * - * @param array $data The original oEmbed response data. - * @param \SimpleXMLElement $node Optional. XML node to append the result to recursively. - * @return string|false XML string on success, false on error. - */ - protected function oembed_create_xml( $data, $node = null ) { - if ( ! is_array( $data ) || empty( $data ) ) { - return false; - } - - if ( null === $node ) { - $node = new \SimpleXMLElement( '' ); - } - - foreach ( $data as $key => $value ) { - if ( is_numeric( $key ) ) { - $key = 'oembed'; - } - - if ( is_array( $value ) ) { - $item = $node->addChild( $key ); - $this->oembed_create_xml( $value, $item ); - } else { - $node->addChild( $key, esc_html( $value ) ); - } - } - - return $node->asXML(); - } } diff --git a/src/Provider_Command.php b/src/Provider_Command.php index 2a56151..6e7187e 100644 --- a/src/Provider_Command.php +++ b/src/Provider_Command.php @@ -155,8 +155,10 @@ public function match_provider( $args, $assoc_args ) { $link_type = Utils\get_flag_value( $assoc_args, 'link-type' ); if ( ! $discover && ( null !== $response_size_limit || null !== $link_type ) ) { + // @phpstan-ignore notIdentical.alwaysTrue if ( null !== $response_size_limit && null !== $link_type ) { $msg = "The 'limit-response-size' and 'link-type' options can only be used with discovery."; + // @phpstan-ignore notIdentical.alwaysTrue } elseif ( null !== $response_size_limit ) { $msg = "The 'limit-response-size' option can only be used with discovery."; } else {