From f509c41280768b1d3047271ec5b50da33184d98d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 14 Nov 2021 20:42:24 +0100 Subject: [PATCH] Upgrade PHPStan to 1.0 (#10253) Co-authored-by: Martin Herndl --- .github/workflows/phpstan.yml | 2 +- composer.json | 4 ++-- phpstan/baseline.neon | 8 +++++++- phpstan/config.neon | 4 ++-- src/Composer/Autoload/AutoloadGenerator.php | 2 +- src/Composer/Autoload/ClassLoader.php | 2 +- src/Composer/Command/BaseCommand.php | 2 +- src/Composer/Command/BaseDependencyCommand.php | 9 ++------- .../Command/CheckPlatformReqsCommand.php | 2 +- src/Composer/Command/ConfigCommand.php | 8 ++++---- src/Composer/Command/FundCommand.php | 4 ++-- src/Composer/Command/InitCommand.php | 11 +---------- src/Composer/Command/ShowCommand.php | 17 ++++++++++------- src/Composer/Console/HtmlOutputFormatter.php | 14 +++++++------- src/Composer/DependencyResolver/PoolBuilder.php | 2 +- src/Composer/DependencyResolver/Problem.php | 6 ++++-- src/Composer/DependencyResolver/Solver.php | 2 +- src/Composer/Downloader/PerforceDownloader.php | 2 +- src/Composer/Downloader/ZipDownloader.php | 2 +- .../EventDispatcher/EventDispatcher.php | 6 ++---- .../Installer/SuggestedPackagesReporter.php | 2 +- src/Composer/Package/Package.php | 10 +++++----- src/Composer/Plugin/PluginManager.php | 6 ++---- src/Composer/Repository/ComposerRepository.php | 10 +++++----- src/Composer/Repository/PackageRepository.php | 2 +- src/Composer/Repository/PathRepository.php | 2 +- src/Composer/Repository/RepositoryFactory.php | 4 ++-- src/Composer/Util/Http/CurlDownloader.php | 6 +++--- src/Composer/Util/Http/ProxyHelper.php | 4 ++-- src/Composer/Util/Http/ProxyManager.php | 12 +----------- src/Composer/Util/Http/Response.php | 2 +- src/Composer/Util/Perforce.php | 8 ++++---- src/Composer/Util/StreamContextFactory.php | 2 +- src/Composer/Util/Svn.php | 6 ++---- .../EventDispatcher/EventDispatcherTest.php | 2 +- tests/Composer/Test/InstallerTest.php | 2 +- .../Repository/Vcs/GitBitbucketDriverTest.php | 2 -- 37 files changed, 85 insertions(+), 106 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index c90525791..3614de87f 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -51,7 +51,7 @@ jobs: - name: "Install PHPStan" # Locked to phpunit 7.5 here as newer ones have void return types which break inheritance - run: "bin/composer require --dev phpstan/phpstan:^0.12.93 phpstan/phpstan-phpunit:^0.12.17 phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}" + run: "bin/composer require --dev phpstan/phpstan:^1.0 phpstan/phpstan-phpunit:^1.0 phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}" - name: "Run PHPStan" run: "vendor/bin/phpstan analyse --configuration=phpstan/config.neon" diff --git a/composer.json b/composer.json index 3895a36e7..8ab7d831a 100644 --- a/composer.json +++ b/composer.json @@ -81,8 +81,8 @@ "test": "simple-phpunit", "phpstan-setup": [ "@composer config platform --unset", - "@php composer.phar update", - "@composer require --dev phpstan/phpstan:^0.12.93 phpstan/phpstan-phpunit:^0.12.17 phpunit/phpunit:^7.5.20 --with-all-dependencies", + "@composer update", + "@composer require --dev phpstan/phpstan:^1.0 phpstan/phpstan-phpunit:^1.0 phpunit/phpunit:^7.5.20 --with-all-dependencies", "git checkout composer.json composer.lock" ], "phpstan": "@php vendor/bin/phpstan analyse --configuration=phpstan/config.neon" diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 1eef49077..d26311763 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -1,7 +1,13 @@ parameters: ignoreErrors: + # reported as https://github.com/phpstan/phpstan/issues/6008 - - message: "#^Parameter \\#1 \\$autoload_function of function spl_autoload_register expects callable\\(string\\)\\: void, array\\(\\$this\\(Composer\\\\Autoload\\\\ClassLoader\\), 'loadClass'\\) given\\.$#" + message: "#^Offset 'curl_id' on array{curl_id:#" + count: 1 + path: ../src/Composer/Util/HttpDownloader.php + + - + message: "#^Parameter \\#1 \\$autoload_function of function spl_autoload_register expects callable\\(string\\)\\: void, array\\{\\$this\\(Composer\\\\Autoload\\\\ClassLoader\\), 'loadClass'\\} given\\.$#" count: 1 path: ../src/Composer/Autoload/ClassLoader.php diff --git a/phpstan/config.neon b/phpstan/config.neon index 75e399f20..d36542cda 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -40,8 +40,8 @@ parameters: - '~^Call to an undefined method (PHPUnit\\Framework\\MockObject\\MockObject|Prophecy\\Prophecy\\ObjectProphecy)::.*$~' # Ignore some irrelevant errors in test files - - '~Method Composer\\Test\\[^:]+::(setUp(BeforeClass)?|tearDown(AfterClass)?|test[^(]+)\(\) has no return typehint specified.~' - - '~Method Composer\\Test\\[^:]+::(data\w+|provide\w+|\w+?Provider)\(\) has no return typehint specified.~' + - '~Method Composer\\Test\\[^:]+::(setUp(BeforeClass)?|tearDown(AfterClass)?|test[^(]+)\(\) has no return type specified.~' + - '~Method Composer\\Test\\[^:]+::(data\w+|provide\w+|\w+?Provider)\(\) has no return type specified.~' bootstrapFiles: - ../tests/bootstrap.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index f284f309c..79039e4f7 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -585,7 +585,7 @@ EOF; /** * Registers an autoloader based on an autoload-map returned by parseAutoloads * - * @param array $autoloads see parseAutoloads return value + * @param array $autoloads see parseAutoloads return value * @param ?string $vendorDir * @return ClassLoader */ diff --git a/src/Composer/Autoload/ClassLoader.php b/src/Composer/Autoload/ClassLoader.php index 0cd6055d1..afef3fa2a 100644 --- a/src/Composer/Autoload/ClassLoader.php +++ b/src/Composer/Autoload/ClassLoader.php @@ -149,7 +149,7 @@ class ClassLoader /** * @return string[] Array of classname => path - * @psalm-var array + * @psalm-return array */ public function getClassMap() { diff --git a/src/Composer/Command/BaseCommand.php b/src/Composer/Command/BaseCommand.php index 5e98226f4..4561dc2af 100644 --- a/src/Composer/Command/BaseCommand.php +++ b/src/Composer/Command/BaseCommand.php @@ -244,7 +244,7 @@ abstract class BaseCommand extends Command } /** - * @param array $table + * @param array $table * * @return void */ diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index ae91abae6..ba48173da 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -132,7 +132,7 @@ class BaseDependencyCommand extends BaseCommand /** * Assembles and prints a bottom-up table of the dependencies. * - * @param array[] $results + * @param array{PackageInterface, Link, mixed}[] $results * * @return void */ @@ -191,7 +191,7 @@ class BaseDependencyCommand extends BaseCommand /** * Recursively prints a tree of the selected results. * - * @param array[] $results Results to be printed at this level. + * @param array{PackageInterface, Link, mixed[]|bool}[] $results Results to be printed at this level. * @param string $prefix Prefix of the current tree level. * @param int $level Current level of recursion. * @@ -202,11 +202,6 @@ class BaseDependencyCommand extends BaseCommand $count = count($results); $idx = 0; foreach ($results as $result) { - /** - * @var PackageInterface $package - * @var Link $link - * @var mixed[]|bool $children - */ list($package, $link, $children) = $result; $color = $this->colors[$level % count($this->colors)]; diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php index 170e25f29..73aee9551 100644 --- a/src/Composer/Command/CheckPlatformReqsCommand.php +++ b/src/Composer/Command/CheckPlatformReqsCommand.php @@ -173,7 +173,7 @@ EOT } /** - * @param array[] $results + * @param mixed[] $results * * @return void */ diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index e9a22ab46..b6dec7073 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -826,10 +826,10 @@ EOT /** * Display the contents of the file in a pretty formatted way * - * @param array $contents - * @param array $rawContents - * @param string|null $k - * @param bool $showSource + * @param array $contents + * @param array $rawContents + * @param string|null $k + * @param bool $showSource * * @return void */ diff --git a/src/Composer/Command/FundCommand.php b/src/Composer/Command/FundCommand.php index 00bbca4af..d6d9c75bc 100644 --- a/src/Composer/Command/FundCommand.php +++ b/src/Composer/Command/FundCommand.php @@ -132,8 +132,8 @@ class FundCommand extends BaseCommand } /** - * @param array[] $fundings - * @return array[] + * @param mixed[] $fundings + * @return mixed[] */ private function insertFundingData(array $fundings, CompletePackageInterface $package) { diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 5ed9b684a..b249ce507 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -489,15 +489,6 @@ EOT ); } - /** - * @param string $name - * @return list - */ - protected function findPackages($name) - { - return $this->getRepos()->search($name); - } - /** * @return CompositeRepository */ @@ -573,7 +564,7 @@ EOT $io = $this->getIO(); while (null !== $package = $io->ask('Search for a package: ')) { - $matches = $this->findPackages($package); + $matches = $this->getRepos()->search($package); if (count($matches)) { // Remove existing packages from search results. diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index ea9c1dac8..8f80f2808 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -299,7 +299,9 @@ EOT if ($input->getOption('tree')) { $rootRequires = $this->getRootRequires(); $packages = $installedRepo->getPackages(); - usort($packages, 'strcmp'); + usort($packages, function (BasePackage $a, BasePackage $b) { + return strcmp((string) $a, (string) $b); + }); $arrayTree = array(); foreach ($packages as $package) { if (in_array($package->getName(), $rootRequires, true)) { @@ -704,7 +706,8 @@ EOT if ($package->getAutoload()) { $io->write("\nautoload"); - foreach ($package->getAutoload() as $type => $autoloads) { + $autoloadConfig = $package->getAutoload(); + foreach ($autoloadConfig as $type => $autoloads) { $io->write('' . $type . ''); if ($type === 'psr-0' || $type === 'psr-4') { @@ -712,7 +715,7 @@ EOT $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.'))); } } elseif ($type === 'classmap') { - $io->write(implode(', ', $autoloads)); + $io->write(implode(', ', $autoloadConfig[$type])); } } if ($package->getIncludePaths()) { @@ -1005,7 +1008,7 @@ EOT /** * Display the tree * - * @param array> $arrayTree + * @param array> $arrayTree * @return void */ protected function displayPackageTree(array $arrayTree) @@ -1051,7 +1054,7 @@ EOT /** * Generate the package tree * - * @return array>|string|null> + * @return array>|string|null> */ protected function generatePackageTree( PackageInterface $package, @@ -1093,8 +1096,8 @@ EOT /** * Display a package tree * - * @param array>|string|null>|string $package - * @param array $packagesInTree + * @param array>|string|null>|string $package + * @param array $packagesInTree * @param string $previousTreeBar * @param int $level * diff --git a/src/Composer/Console/HtmlOutputFormatter.php b/src/Composer/Console/HtmlOutputFormatter.php index f15494b58..a94ad4d57 100644 --- a/src/Composer/Console/HtmlOutputFormatter.php +++ b/src/Composer/Console/HtmlOutputFormatter.php @@ -60,7 +60,7 @@ class HtmlOutputFormatter extends OutputFormatter } /** - * @param string $message + * @param ?string $message * * @return string */ @@ -82,12 +82,12 @@ class HtmlOutputFormatter extends OutputFormatter { $out = ''); } diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index aec0a33d1..72fb02a43 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -384,6 +384,8 @@ class Problem $hasDefaultBranch[$package->getName()] = true; } } + + $preparedStrings = array(); foreach ($prepared as $name => $package) { // remove the implicit default branch alias to avoid cruft in the display if (isset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS], $hasDefaultBranch[$name])) { @@ -395,10 +397,10 @@ class Problem if (!$isVerbose) { $package['versions'] = self::condenseVersionList($package['versions'], 4); } - $prepared[$name] = $package['name'].'['.implode(', ', $package['versions']).']'; + $preparedStrings[] = $package['name'].'['.implode(', ', $package['versions']).']'; } - return implode(', ', $prepared); + return implode(', ', $preparedStrings); } /** diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index c3bdbfff0..9b112d87f 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -42,7 +42,7 @@ class Solver /** @var int */ protected $propagateIndex; - /** @var array[] */ + /** @var mixed[] */ protected $branches = array(); /** @var Problem[] */ protected $problems = array(); diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 0c0c5d74d..c7d0e7985 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -21,7 +21,7 @@ use Composer\Util\Perforce; */ class PerforceDownloader extends VcsDownloader { - /** @var Perforce */ + /** @var Perforce|null */ protected $perforce; /** diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index 30fa1c9da..a86d1da6b 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -33,7 +33,7 @@ class ZipDownloader extends ArchiveDownloader private static $isWindows; /** @var ZipArchive|null */ - private $zipArchiveObject; + private $zipArchiveObject; // @phpstan-ignore-line helper property that is set via reflection for testing purposes /** * @inheritDoc diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index ade63b128..b43a92fb3 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -508,10 +508,8 @@ class EventDispatcher $this->loader = $generator->createLoader($map, $this->composer->getConfig()->get('vendor-dir')); $this->loader->register(false); - if (isset($map['files'])) { - foreach ($map['files'] as $fileIdentifier => $file) { - \Composer\Autoload\composerRequire($fileIdentifier, $file); - } + foreach ($map['files'] as $fileIdentifier => $file) { + \Composer\Autoload\composerRequire($fileIdentifier, $file); } return $scripts[$event->getName()]; diff --git a/src/Composer/Installer/SuggestedPackagesReporter.php b/src/Composer/Installer/SuggestedPackagesReporter.php index 901852307..144ce4735 100644 --- a/src/Composer/Installer/SuggestedPackagesReporter.php +++ b/src/Composer/Installer/SuggestedPackagesReporter.php @@ -180,7 +180,7 @@ class SuggestedPackagesReporter /** * @param InstalledRepository|null $installedRepo If passed in, suggested packages which are installed already will be skipped * @param PackageInterface|null $onlyDependentsOf If passed in, only the suggestions from direct dependents of that package, or from the package itself, will be shown - * @return array[] + * @return mixed[] */ private function getFilteredSuggestions(InstalledRepository $installedRepo = null, PackageInterface $onlyDependentsOf = null) { diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index e5238f0c2..c2713f663 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -456,7 +456,7 @@ class Package extends BasePackage */ public function setRequires(array $requires) { - if (isset($requires[0])) { + if (isset($requires[0])) { // @phpstan-ignore-line $requires = $this->convertLinksToMap($requires, 'setRequires'); } @@ -480,7 +480,7 @@ class Package extends BasePackage */ public function setConflicts(array $conflicts) { - if (isset($conflicts[0])) { + if (isset($conflicts[0])) { // @phpstan-ignore-line $conflicts = $this->convertLinksToMap($conflicts, 'setConflicts'); } @@ -505,7 +505,7 @@ class Package extends BasePackage */ public function setProvides(array $provides) { - if (isset($provides[0])) { + if (isset($provides[0])) { // @phpstan-ignore-line $provides = $this->convertLinksToMap($provides, 'setProvides'); } @@ -530,7 +530,7 @@ class Package extends BasePackage */ public function setReplaces(array $replaces) { - if (isset($replaces[0])) { + if (isset($replaces[0])) { // @phpstan-ignore-line $replaces = $this->convertLinksToMap($replaces, 'setReplaces'); } @@ -555,7 +555,7 @@ class Package extends BasePackage */ public function setDevRequires(array $devRequires) { - if (isset($devRequires[0])) { + if (isset($devRequires[0])) { // @phpstan-ignore-line $devRequires = $this->convertLinksToMap($devRequires, 'setDevRequires'); } diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 0918d9c02..87dc2d6d5 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -201,10 +201,8 @@ class PluginManager $classLoader = $generator->createLoader($map, $this->composer->getConfig()->get('vendor-dir')); $classLoader->register(false); - if (isset($map['files'])) { - foreach ($map['files'] as $fileIdentifier => $file) { - \Composer\Autoload\composerRequire($fileIdentifier, $file); - } + foreach ($map['files'] as $fileIdentifier => $file) { + \Composer\Autoload\composerRequire($fileIdentifier, $file); } foreach ($classes as $class) { diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 90a3d7010..33e93f44c 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -1045,7 +1045,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } /** - * @return array[] + * @return mixed[] */ private function loadDataFromServer() { @@ -1067,7 +1067,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } /** - * @param array{providers?: array, provider-includes?: array} $data + * @param array{providers?: mixed[], provider-includes?: mixed[]} $data * * @return void */ @@ -1097,9 +1097,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } /** - * @param array[] $data + * @param mixed[] $data * - * @return array[] + * @return mixed[] */ private function loadIncludes($data) { @@ -1144,7 +1144,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * TODO v3 should make this private once we can drop PHP 5.3 support * @private * - * @param array[] $packages + * @param mixed[] $packages * @param string|null $source * * @return list diff --git a/src/Composer/Repository/PackageRepository.php b/src/Composer/Repository/PackageRepository.php index 06f987d43..70ba559b4 100644 --- a/src/Composer/Repository/PackageRepository.php +++ b/src/Composer/Repository/PackageRepository.php @@ -28,7 +28,7 @@ class PackageRepository extends ArrayRepository /** * Initializes filesystem repository. * - * @param array{package: array} $config package definition + * @param array{package: mixed[]} $config package definition */ public function __construct(array $config) { diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 630413d36..ff1480dac 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -95,7 +95,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn /** * Initializes path repository. * - * @param array{url: string, options?: array{symlink?: bool, relative?: bool, versions?: array}} $repoConfig + * @param array{url?: string, options?: array{symlink?: bool, relative?: bool, versions?: array}} $repoConfig * @param IOInterface $io * @param Config $config */ diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index a5e0e9f31..7143501fb 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -81,7 +81,7 @@ class RepositoryFactory if (!$rm) { $rm = static::manager($io, $config, Factory::createHttpDownloader($io, $config)); } - $repos = static::createRepos($rm, array($repoConfig)); + $repos = self::createRepos($rm, array($repoConfig)); return reset($repos); } @@ -107,7 +107,7 @@ class RepositoryFactory $rm = static::manager($io, $config, Factory::createHttpDownloader($io, $config)); } - return static::createRepos($rm, $config->getRepositories()); + return self::createRepos($rm, $config->getRepositories()); } /** diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index 6b5d3a061..6ecac347d 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -286,10 +286,10 @@ class CurlDownloader */ public function abortRequest($id) { - if (isset($this->jobs[$id], $this->jobs[$id]['handle'])) { + if (isset($this->jobs[$id], $this->jobs[$id]['curlHandle'])) { $job = $this->jobs[$id]; - curl_multi_remove_handle($this->multiHandle, $job['handle']); - curl_close($job['handle']); + curl_multi_remove_handle($this->multiHandle, $job['curlHandle']); + curl_close($job['curlHandle']); if (is_resource($job['headerHandle'])) { fclose($job['headerHandle']); } diff --git a/src/Composer/Util/Http/ProxyHelper.php b/src/Composer/Util/Http/ProxyHelper.php index 001fb9b83..febcfc73d 100644 --- a/src/Composer/Util/Http/ProxyHelper.php +++ b/src/Composer/Util/Http/ProxyHelper.php @@ -156,8 +156,8 @@ class ProxyHelper /** * Formats a url from its component parts * - * @param array{scheme: string, host: string, port?: int, user?: string, pass?: string} $proxy - * @param bool $includeAuth + * @param array{scheme?: string, host: string, port?: int, user?: string, pass?: string} $proxy + * @param bool $includeAuth * * @return string The formatted value */ diff --git a/src/Composer/Util/Http/ProxyManager.php b/src/Composer/Util/Http/ProxyManager.php index 00ecd398d..352ab8d35 100644 --- a/src/Composer/Util/Http/ProxyManager.php +++ b/src/Composer/Util/Http/ProxyManager.php @@ -34,8 +34,6 @@ class ProxyManager private $hasProxy; /** @var ?string */ private $info = null; - /** @var ?string */ - private $lastProxy = null; /** @var ?NoProxyPattern */ private $noProxyHandler = null; @@ -188,14 +186,6 @@ class ProxyManager */ private function noProxy($requestUrl) { - if ($this->noProxyHandler) { - if ($this->noProxyHandler->test($requestUrl)) { - $this->lastProxy = 'excluded by no_proxy'; - - return true; - } - } - - return false; + return $this->noProxyHandler && $this->noProxyHandler->test($requestUrl); } } diff --git a/src/Composer/Util/Http/Response.php b/src/Composer/Util/Http/Response.php index 5f3cf73e5..46f0b3bf7 100644 --- a/src/Composer/Util/Http/Response.php +++ b/src/Composer/Util/Http/Response.php @@ -37,7 +37,7 @@ class Response */ public function __construct(array $request, $code, array $headers, $body) { - if (!isset($request['url'])) { + if (!isset($request['url'])) { // @phpstan-ignore-line throw new \LogicException('url key missing from request array'); } $this->request = $request; diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 7d3929c94..abf22dc45 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -26,7 +26,7 @@ class Perforce protected $path; /** @var ?string */ protected $p4Depot; - /** @var string */ + /** @var ?string */ protected $p4Client; /** @var ?string */ protected $p4User; @@ -34,7 +34,7 @@ class Perforce protected $p4Password; /** @var string */ protected $p4Port; - /** @var string */ + /** @var ?string */ protected $p4Stream; /** @var string */ protected $p4ClientSpec; @@ -54,7 +54,7 @@ class Perforce /** @var IOInterface */ protected $io; - /** @var Filesystem */ + /** @var ?Filesystem */ protected $filesystem; /** @@ -743,7 +743,7 @@ class Perforce */ public function getFilesystem() { - if (empty($this->filesystem)) { + if (null === $this->filesystem) { $this->filesystem = new Filesystem($this->process); } diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index c63c6118d..4fc3316fa 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -60,7 +60,7 @@ final class StreamContextFactory * @param string $url * @param mixed[] $options * @param bool $forCurl When true, will not add proxy values as these are handled separately - * @phpstan-return array{http: array{header: string[], proxy?: string, request_fulluri: bool}, ssl: array} + * @phpstan-return array{http: array{header: string[], proxy?: string, request_fulluri: bool}, ssl?: mixed[]} * @return array formatted as a stream context array */ public static function initOptions($url, array $options, $forCurl = false) diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index 0bc489de6..4c59eab06 100644 --- a/src/Composer/Util/Svn.php +++ b/src/Composer/Util/Svn.php @@ -283,7 +283,7 @@ class Svn throw new \LogicException("No svn auth detected."); } - return isset($this->credentials['password']) ? $this->credentials['password'] : ''; + return $this->credentials['password']; } /** @@ -366,9 +366,7 @@ class Svn } $this->credentials['username'] = $uri['user']; - if (!empty($uri['pass'])) { - $this->credentials['password'] = $uri['pass']; - } + $this->credentials['password'] = !empty($uri['pass']) ? $uri['pass'] : ''; return $this->hasAuth = true; } diff --git a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php index 4bde2c2ab..9065c61ec 100644 --- a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php +++ b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php @@ -151,7 +151,7 @@ class EventDispatcherTest extends TestCase ->will($this->returnValue(array())); $generator ->method('parseAutoloads') - ->will($this->returnValue(array())); + ->will($this->returnValue(array('psr-0' => array(), 'psr-4' => array(), 'classmap' => array(), 'files' => array(), 'exclude-from-classmap' => array(),))); $generator ->method('createLoader') ->will($this->returnValue($this->getMockBuilder('Composer\Autoload\ClassLoader')->getMock())); diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 20d157c11..973ea2c7a 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -70,7 +70,7 @@ class InstallerTest extends TestCase * @dataProvider provideInstaller * @param RootPackageInterface&BasePackage $rootPackage * @param RepositoryInterface[] $repositories - * @param array[] $options + * @param mixed[] $options */ public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options) { diff --git a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php index 43e9293d8..e685b9dfd 100644 --- a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php @@ -32,8 +32,6 @@ class GitBitbucketDriverTest extends TestCase private $httpDownloader; /** @var string */ private $home; - /** @var string */ - private $originUrl = 'bitbucket.org'; protected function setUp() {