Skip to content

Commit 48b09d2

Browse files
authored
Merge pull request #216 from wp-cli/copilot/add-phpstan-configuration
2 parents a198bca + fc8c0b9 commit 48b09d2

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

phpstan.neon.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
level: 1
3+
paths:
4+
- src
5+
- package-command.php
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli/php
8+
scanFiles:
9+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
10+
treatPhpDocTypesAsCertain: false
11+
ignoreErrors:
12+
# WP_CLI_VERSION is defined in wp-cli core at runtime
13+
- '#Constant WP_CLI_VERSION not found#'

src/Package_Command.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,8 @@ private function package_index() {
737737

738738
$io = new NullIO();
739739
try {
740-
if ( $this->is_composer_v2() ) {
741-
$http_downloader = new HttpDownloader( $io, $config );
742-
$package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config, $http_downloader );
743-
} else {
744-
$package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config );
745-
}
740+
$http_downloader = new HttpDownloader( $io, $config );
741+
$package_index = new ComposerRepository( [ 'url' => self::PACKAGE_INDEX_URL ], $io, $config, $http_downloader );
746742
} catch ( Exception $e ) {
747743
WP_CLI::error( $e->getMessage() );
748744
}
@@ -759,6 +755,7 @@ private function package_index() {
759755
* @param array
760756
*/
761757
private function show_packages( $context, $packages, $assoc_args ) {
758+
$default_fields = [];
762759
if ( 'list' === $context ) {
763760
$default_fields = [
764761
'name',
@@ -1074,7 +1071,7 @@ private function find_latest_package( PackageInterface $package, Composer $compo
10741071
$stability = $composer->getPackage()->getMinimumStability();
10751072
$flags = $composer->getPackage()->getStabilityFlags();
10761073
if ( isset( $flags[ $name ] ) ) {
1077-
$stability = array_search( $flags[ $name ], BasePackage::$stabilities, true );
1074+
$stability = array_search( $flags[ $name ], BasePackage::STABILITIES, true );
10781075
}
10791076
$best_stability = $stability;
10801077
if ( $composer->getPackage()->getPreferStable() ) {

src/WP_CLI/JsonManipulator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function addLink($type, $package, $constraint, $sortPackages = false, $ca
128128
private function sortPackages(array &$packages = array())
129129
{
130130
$prefix = function ($requirement) {
131-
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $requirement)) {
131+
if (PlatformRepository::isPlatformPackage($requirement)) {
132132
return preg_replace(
133133
array(
134134
'/^php/',
@@ -248,7 +248,7 @@ public function addSubNode($mainNode, $name, $value, $caseInsensitive = false) /
248248
// child exists
249249
$childRegex = '{'.self::$DEFINES.'(?P<start>"'.preg_quote($name).'"\s*:\s*)(?P<content>(?&json))(?P<end>,?)}x';
250250
if ($this->pregMatch($childRegex, $children, $matches)) {
251-
$children = preg_replace_callback($childRegex, function ($matches) use ($name, $subName, $value, $that) {
251+
$children = preg_replace_callback($childRegex, function ($matches) use ($subName, $value, $that) {
252252
if ($subName !== null) {
253253
$curVal = json_decode($matches['content'], true);
254254
if (!is_array($curVal)) {
@@ -362,6 +362,7 @@ public function removeSubNode($mainNode, $name, $caseInsensitive = false) // WP_
362362
}
363363

364364
// try and find a match for the subkey
365+
$childrenClean = $children;
365366
if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) {
366367
// find best match for the value of "name"
367368
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_
379380
}
380381
}
381382
}
382-
} else {
383-
$childrenClean = $children;
384383
}
385384

386385
// no child data left, $name was the only key in

0 commit comments

Comments
 (0)