Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -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#'
11 changes: 4 additions & 7 deletions src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand All @@ -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',
Expand Down Expand Up @@ -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() ) {
Expand Down
7 changes: 3 additions & 4 deletions src/WP_CLI/JsonManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down Expand Up @@ -248,7 +248,7 @@ public function addSubNode($mainNode, $name, $value, $caseInsensitive = false) /
// child exists
$childRegex = '{'.self::$DEFINES.'(?P<start>"'.preg_quote($name).'"\s*:\s*)(?P<content>(?&json))(?P<end>,?)}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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
Expand Down