From 960077b019e0ebb7e76587e8a1d52e553367ef54 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:15:49 +0000 Subject: [PATCH 1/2] Initial plan From fc8c0b9e840f5c178ae2665fc855e381c22e32f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:22:15 +0000 Subject: [PATCH 2/2] Add PHPStan configuration and fix level 1 errors Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- phpstan.neon.dist | 13 +++++++++++++ src/Package_Command.php | 11 ++++------- src/WP_CLI/JsonManipulator.php | 7 +++---- 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 000000000..533df9d16 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,13 @@ +parameters: + level: 1 + paths: + - src + - package-command.php + scanDirectories: + - vendor/wp-cli/wp-cli/php + scanFiles: + - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php + treatPhpDocTypesAsCertain: false + ignoreErrors: + # WP_CLI_VERSION is defined in wp-cli core at runtime + - '#Constant WP_CLI_VERSION not found#' diff --git a/src/Package_Command.php b/src/Package_Command.php index 7a3fff80f..0d698b7b6 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -737,12 +737,8 @@ private function package_index() { $io = new NullIO(); try { - if ( $this->is_composer_v2() ) { - $http_downloader = new HttpDownloader( $io, $config ); - $package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config, $http_downloader ); - } else { - $package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config ); - } + $http_downloader = new HttpDownloader( $io, $config ); + $package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config, $http_downloader ); } catch ( Exception $e ) { WP_CLI::error( $e->getMessage() ); } @@ -759,6 +755,7 @@ private function package_index() { * @param array */ private function show_packages( $context, $packages, $assoc_args ) { + $default_fields = []; if ( 'list' === $context ) { $default_fields = [ 'name', @@ -1074,7 +1071,7 @@ private function find_latest_package( PackageInterface $package, Composer $compo $stability = $composer->getPackage()->getMinimumStability(); $flags = $composer->getPackage()->getStabilityFlags(); if ( isset( $flags[ $name ] ) ) { - $stability = array_search( $flags[ $name ], BasePackage::$stabilities, true ); + $stability = array_search( $flags[ $name ], BasePackage::STABILITIES, true ); } $best_stability = $stability; if ( $composer->getPackage()->getPreferStable() ) { diff --git a/src/WP_CLI/JsonManipulator.php b/src/WP_CLI/JsonManipulator.php index 1a4e6dc70..95df1699f 100644 --- a/src/WP_CLI/JsonManipulator.php +++ b/src/WP_CLI/JsonManipulator.php @@ -128,7 +128,7 @@ public function addLink($type, $package, $constraint, $sortPackages = false, $ca private function sortPackages(array &$packages = array()) { $prefix = function ($requirement) { - if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $requirement)) { + if (PlatformRepository::isPlatformPackage($requirement)) { return preg_replace( array( '/^php/', @@ -248,7 +248,7 @@ public function addSubNode($mainNode, $name, $value, $caseInsensitive = false) / // child exists $childRegex = '{'.self::$DEFINES.'(?P"'.preg_quote($name).'"\s*:\s*)(?P(?&json))(?P,?)}x'; if ($this->pregMatch($childRegex, $children, $matches)) { - $children = preg_replace_callback($childRegex, function ($matches) use ($name, $subName, $value, $that) { + $children = preg_replace_callback($childRegex, function ($matches) use ($subName, $value, $that) { if ($subName !== null) { $curVal = json_decode($matches['content'], true); if (!is_array($curVal)) { @@ -362,6 +362,7 @@ public function removeSubNode($mainNode, $name, $caseInsensitive = false) // WP_ } // try and find a match for the subkey + $childrenClean = $children; if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) { // find best match for the value of "name" if (preg_match_all('{'.self::$DEFINES.'"'.preg_quote($name).'"\s*:\s*(?:(?&json))}x', $children, $matches)) { @@ -379,8 +380,6 @@ public function removeSubNode($mainNode, $name, $caseInsensitive = false) // WP_ } } } - } else { - $childrenClean = $children; } // no child data left, $name was the only key in