diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..533df9d1 --- /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 7a3fff80..0d698b7b 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 1a4e6dc7..95df1699 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