From 80505e745efa759533fbb367cb54a7adcbf58fa3 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 7 Apr 2020 14:40:51 +0200 Subject: [PATCH] Fix phpstan issues --- .travis.yml | 2 +- phpstan/config.neon | 3 --- src/Composer/Autoload/ClassMapGenerator.php | 2 +- src/Composer/Command/CheckPlatformReqsCommand.php | 6 ++++++ src/Composer/DependencyResolver/Solver.php | 1 + src/Composer/Installer.php | 6 +++--- src/Composer/Installer/InstallationManager.php | 8 ++++---- src/Composer/Package/BasePackage.php | 2 ++ src/Composer/Package/PackageInterface.php | 2 ++ .../Composer/Test/DependencyResolver/PoolBuilderTest.php | 2 ++ 10 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c0ee0bc9..0cf228882 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ before_script: script: - if [[ $PHPSTAN == "1" ]]; then bin/composer require --dev phpstan/phpstan:^0.12 phpunit/phpunit:^7.5 --no-update && - bin/composer update phpstan/* phpunit/* sebastian/* --with-dependencies && + bin/composer update phpstan/* phpunit/* sebastian/* --with-all-dependencies && vendor/bin/phpstan analyse --configuration=phpstan/config.neon; else vendor/bin/simple-phpunit; diff --git a/phpstan/config.neon b/phpstan/config.neon index d3283e61b..7a489a9b0 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -35,9 +35,6 @@ parameters: # variable defined in eval - '~^Undefined variable: \$res$~' - # erroneous detection of missing const, see https://github.com/phpstan/phpstan/issues/2960 - - '~^Access to undefined constant ZipArchive::LIBZIP_VERSION.$~' - # we don't have different constructors for parent/child - '~^Unsafe usage of new static\(\)\.$~' diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index e5263e835..f242a0594 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -61,8 +61,8 @@ class ClassMapGenerator */ public static function createMap($path, $blacklist = null, IOInterface $io = null, $namespace = null, $autoloadType = null, &$scannedFiles = array()) { + $basePath = $path; if (is_string($path)) { - $basePath = $path; if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php index eba6d0946..e0e2b612b 100644 --- a/src/Composer/Command/CheckPlatformReqsCommand.php +++ b/src/Composer/Command/CheckPlatformReqsCommand.php @@ -86,6 +86,7 @@ EOT if ($candidates) { $reqResults = array(); foreach ($candidates as $candidate) { + $candidateConstraint = null; if ($candidate->getName() === $require) { $candidateConstraint = new Constraint('=', $candidate->getVersion()); $candidateConstraint->setPrettyString($candidate->getPrettyVersion()); @@ -98,6 +99,11 @@ EOT } } + // safety check for phpstan, but it should not be possible to get a candidate out of findPackagesWithReplacersAndProviders without a constraint matching $require + if (!$candidateConstraint) { + continue; + } + foreach ($links as $link) { if (!$link->getConstraint()->matches($candidateConstraint)) { $reqResults[] = array( diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 873f9d778..73a17b112 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -411,6 +411,7 @@ class Solver } } } + unset($literal); $l1retry = true; while ($l1retry) { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 15cfb78e1..9f3bd9ac9 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -396,7 +396,7 @@ class Installer $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher); // solve dependencies - $solver = new Solver($policy, $pool, $this->io, $repositorySet); + $solver = new Solver($policy, $pool, $this->io); try { $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs); $ruleSetSize = $solver->getRuleSetSize(); @@ -556,7 +556,7 @@ class Installer $pool = $repositorySet->createPoolWithAllPackages(); - $solver = new Solver($policy, $pool, $this->io, $repositorySet); + $solver = new Solver($policy, $pool, $this->io); try { $nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs); $solver = null; @@ -615,7 +615,7 @@ class Installer $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher); // solve dependencies - $solver = new Solver($policy, $pool, $this->io, $repositorySet); + $solver = new Solver($policy, $pool, $this->io); try { $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs); $solver = null; diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 40d2a7f83..c3b4b9242 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -210,12 +210,12 @@ class InstallationManager continue; } - if ($opType === 'install' || $opType === 'uninstall') { - $package = $operation->getPackage(); - $initialPackage = null; - } elseif ($opType === 'update') { + if ($opType === 'update') { $package = $operation->getTargetPackage(); $initialPackage = $operation->getInitialPackage(); + } else { + $package = $operation->getPackage(); + $initialPackage = null; } $installer = $this->getInstaller($package->getType()); diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 74cf3516e..480b5ee62 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -228,6 +228,8 @@ abstract class BasePackage implements PackageInterface case PackageInterface::DISPLAY_DIST_REF: $reference = $this->getDistReference(); break; + default: + throw new \UnexpectedValueException('Display mode '.$displayMode.' is not supported'); } // if source reference is a sha1 hash -- truncate diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 8f8087134..4db9b45ee 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -206,6 +206,8 @@ interface PackageInterface * @param bool $truncate If the source reference is a sha1 hash, truncate it * @param int $displayMode One of the DISPLAY_ constants on this interface determining display of references * @return string version + * + * @psalm-param self::DISPLAY_SOURCE_REF_IF_DEV|self::DISPLAY_SOURCE_REF|self::DISPLAY_DIST_REF $displayMode */ public function getFullPrettyVersion($truncate = true, $displayMode = self::DISPLAY_SOURCE_REF_IF_DEV); diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index f51661db6..58f8fda15 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -90,6 +90,7 @@ class PoolBuilderTest extends TestCase } $pool = $repositorySet->createPool($request, new NullIO()); + $result = array(); for ($i = 1, $count = count($pool); $i <= $count; $i++) { $result[] = $pool->packageById($i); } @@ -156,6 +157,7 @@ class PoolBuilderTest extends TestCase ); $section = null; + $data = array(); foreach ($tokens as $i => $token) { if (null === $section && empty($token)) { continue; // skip leading blank