Skip to content

Commit

Permalink
Update deps, fix phpstan issues, update baseline (1711, 49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 21, 2023
1 parent 62f12ab commit 5c3d8f3
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 207 deletions.
142 changes: 73 additions & 69 deletions composer.lock

Large diffs are not rendered by default.

122 changes: 6 additions & 116 deletions phpstan/baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ parameters:
count: 1
path: ../src/Composer/Command/BaseDependencyCommand.php

-
message: "#^Cannot access an offset on array\\<int, array\\<int, array\\<int, array\\<int, Composer\\\\Package\\\\Link\\>\\|Composer\\\\Package\\\\Link\\>\\|Composer\\\\Package\\\\Link\\>\\|Composer\\\\Package\\\\Link\\>\\|Composer\\\\Package\\\\Link\\.$#"
count: 1
path: ../src/Composer/Command/CheckPlatformReqsCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Semver\\\\Constraint\\\\ConstraintInterface\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -475,11 +470,6 @@ parameters:
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Left side of && is always false\\.$#"
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, string given\\.$#"
count: 1
Expand Down Expand Up @@ -510,11 +500,6 @@ parameters:
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Right side of && is always false\\.$#"
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 7
Expand Down Expand Up @@ -552,11 +537,6 @@ parameters:

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
path: ../src/Composer/Command/RequireCommand.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
path: ../src/Composer/Command/RequireCommand.php

Expand Down Expand Up @@ -590,11 +570,6 @@ parameters:
count: 1
path: ../src/Composer/Command/RequireCommand.php

-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../src/Composer/Command/RequireCommand.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
Expand Down Expand Up @@ -1085,16 +1060,6 @@ parameters:
count: 1
path: ../src/Composer/Config/JsonConfigSource.php

-
message: "#^Call to function is_array\\(\\) with array\\<Composer\\\\Command\\\\BaseCommand\\> will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Instanceof between Composer\\\\Command\\\\BaseCommand and Composer\\\\Command\\\\BaseCommand will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Only booleans are allowed in &&, array\\<string, array\\<int\\|string\\>\\|int\\|string\\> given on the left side\\.$#"
count: 1
Expand Down Expand Up @@ -1460,6 +1425,11 @@ parameters:
count: 2
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Method Composer\\\\DependencyResolver\\\\Solver\\:\\:enableDisableLearnedRules\\(\\) is unused\\.$#"
count: 1
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Only booleans are allowed in &&, Composer\\\\DependencyResolver\\\\Rule\\|null given on the left side\\.$#"
count: 1
Expand Down Expand Up @@ -2030,11 +2000,6 @@ parameters:
count: 1
path: ../src/Composer/EventDispatcher/EventDispatcher.php

-
message: "#^Call to function is_callable\\(\\) with callable\\(\\)\\: mixed will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/EventDispatcher/EventDispatcher.php

-
message: "#^Cannot access offset 0 on array\\{0\\: string, 1\\?\\: int\\}\\|int\\|string\\.$#"
count: 1
Expand Down Expand Up @@ -2180,11 +2145,6 @@ parameters:
count: 1
path: ../src/Composer/IO/BaseIO.php

-
message: "#^Instanceof between Symfony\\\\Component\\\\Console\\\\Input\\\\StringInput and Symfony\\\\Component\\\\Console\\\\Input\\\\StreamableInputInterface will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/IO/BufferIO.php

-
message: "#^Only booleans are allowed in a ternary operator condition, Symfony\\\\Component\\\\Console\\\\Formatter\\\\OutputFormatterInterface\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -2240,16 +2200,6 @@ parameters:
count: 1
path: ../src/Composer/InstalledVersions.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: ../src/Composer/InstalledVersions.php

-
message: "#^Parameter \\#1 \\$constraints of method Composer\\\\Semver\\\\VersionParser\\:\\:parseConstraints\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: ../src/Composer/InstalledVersions.php

-
message: "#^Cannot call method getPackages\\(\\) on Composer\\\\Repository\\\\LockArrayRepository\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -2647,12 +2597,7 @@ parameters:

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 4
path: ../src/Composer/Package/Archiver/ArchiveManager.php

-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 2
count: 3
path: ../src/Composer/Package/Archiver/ArchiveManager.php

-
Expand Down Expand Up @@ -3070,21 +3015,6 @@ parameters:
count: 1
path: ../src/Composer/Package/Version/VersionGuesser.php

-
message: "#^Strict comparison using \\!\\=\\= between null and array\\{version\\: string\\|null, commit\\: '', pretty_version\\: string\\|null\\} will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Package/Version/VersionGuesser.php

-
message: "#^Strict comparison using \\!\\=\\= between null and array\\{version\\: string\\|null, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\} will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Package/Version/VersionGuesser.php

-
message: "#^Strict comparison using \\!\\=\\= between null and string will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Package/Version/VersionGuesser.php

-
message: "#^Only booleans are allowed in an if condition, int\\<0, max\\>\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -3120,11 +3050,6 @@ parameters:
count: 1
path: ../src/Composer/Platform/Runtime.php

-
message: "#^Casting to array\\<string\\> something that's already array\\<string\\>\\.$#"
count: 1
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 3
Expand Down Expand Up @@ -3205,11 +3130,6 @@ parameters:
count: 2
path: ../src/Composer/Question/StrictConfirmationQuestion.php

-
message: "#^Casting to array\\<string\\> something that's already array\\<string\\>\\.$#"
count: 1
path: ../src/Composer/Repository/ArrayRepository.php

-
message: "#^Method Composer\\\\Repository\\\\ArrayRepository\\:\\:getProviders\\(\\) should return array\\<string, array\\{name\\: string, description\\: string, type\\: string\\}\\> but returns array\\<string, array\\{name\\: string, description\\: string\\|null, type\\: string\\}\\>\\.$#"
count: 1
Expand Down Expand Up @@ -3415,11 +3335,6 @@ parameters:
count: 2
path: ../src/Composer/Repository/FilesystemRepository.php

-
message: "#^Parameter \\#2 \\$content of method Composer\\\\Util\\\\Filesystem\\:\\:filePutContentsIfModified\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: ../src/Composer/Repository/FilesystemRepository.php

-
message: "#^Parameter \\#2 \\$installPaths of method Composer\\\\Repository\\\\FilesystemRepository\\:\\:generateInstalledVersions\\(\\) expects array\\<string, string\\>, array\\<string, string\\|null\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -3978,11 +3893,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/Vcs/SvnDriver.php

-
message: "#^Strict comparison using \\!\\=\\= between string and false will always evaluate to true\\.$#"
count: 2
path: ../src/Composer/Repository/Vcs/SvnDriver.php

-
message: "#^Cannot call method read\\(\\) on Composer\\\\Cache\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -4303,11 +4213,6 @@ parameters:
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php

-
message: "#^Call to function is_resource\\(\\) with resource will always evaluate to true\\.$#"
count: 2
path: ../src/Composer/Util/Http/CurlDownloader.php

-
message: "#^Cannot access offset 'features' on array\\|false\\.$#"
count: 2
Expand Down Expand Up @@ -4998,11 +4903,6 @@ parameters:
count: 1
path: ../src/Composer/Util/StreamContextFactory.php

-
message: "#^Casting to bool something that's already \\*NEVER\\*\\.$#"
count: 1
path: ../src/Composer/Util/Svn.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
Expand Down Expand Up @@ -5356,11 +5256,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/Installer/InstallerEventTest.php

-
message: "#^Call to function is_array\\(\\) with array\\<Composer\\\\Repository\\\\RepositoryInterface\\> will always evaluate to true\\.$#"
count: 1
path: ../tests/Composer/Test/InstallerTest.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 9
Expand Down Expand Up @@ -5511,11 +5406,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/Platform/VersionTest.php

-
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Command…' and Composer\\\\Command\\\\BaseCommand will always evaluate to true\\.$#"
count: 1
path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php

-
message: "#^Parameter \\#2 \\$capabilityClassName of method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\) expects class\\-string\\<Composer\\\\Plugin\\\\Capability\\\\Capability\\>, string given\\.$#"
count: 2
Expand Down
8 changes: 3 additions & 5 deletions src/Composer/Command/CheckPlatformReqsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
if (!$input->getOption('no-dev')) {
$requires += $composer->getPackage()->getDevRequires();
}

foreach ($requires as $require => $link) {
$requires[$require] = [$link];
foreach ($composer->getPackage()->getDevRequires() as $require => $link) {
$requires[$require] = [$link];
}
}

$installedRepo = new InstalledRepository([$installedRepo, new RootPackageRepository(clone $composer->getPackage())]);
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Command/PackageDiscoveryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function getMinimumStability(InputInterface $input): string
// @phpstan-ignore-next-line as RequireCommand does not have the option above so this code is reachable there
$file = Factory::getComposerFile();
if (is_file($file) && Filesystem::isReadable($file) && is_array($composer = json_decode((string) file_get_contents($file), true))) {
if (!empty($composer['minimum-stability'])) {
if (isset($composer['minimum-stability'])) {
return VersionParser::normalizeStability($composer['minimum-stability']);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Composer/Downloader/FileDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function download(PackageInterface $package, string $path, ?PackageInterf

$retries = 3;
$distUrls = $package->getDistUrls();
/** @var non-empty-array<array{base: non-empty-string, processed: non-empty-string, cacheKey: string}> $urls */
/** @var array<array{base: non-empty-string, processed: non-empty-string, cacheKey: string}> $urls */
$urls = [];
foreach ($distUrls as $index => $url) {
$processedUrl = $this->processUrl($package, $url);
Expand All @@ -146,6 +146,7 @@ public function download(PackageInterface $package, string $path, ?PackageInterf
'cacheKey' => $cacheKeyGenerator($package, $processedUrl),
];
}
assert(count($urls) > 0);

$fileName = $this->getFileName($package, $path);
$this->filesystem->ensureDirectoryExists($path);
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/InstalledVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}

Expand All @@ -119,7 +119,7 @@ public static function isInstalled($packageName, $includeDevRequirements = true)
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints($constraint);
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));

return $provided->matches($constraint);
Expand Down
8 changes: 5 additions & 3 deletions src/Composer/PHPStan/ConfigReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}

$keyType = $scope->getType($args[0]->value);
if ($keyType instanceof ConstantStringType) {
if (isset($this->properties[$keyType->getValue()])) {
return $this->properties[$keyType->getValue()];
if (count($keyType->getConstantStrings()) > 0) {
foreach ($keyType->getConstantStrings() as $constantString) {
if (isset($this->properties[$constantString->getValue()])) {
return $this->properties[$constantString->getValue()];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Package/Archiver/ZipArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function archive(string $sources, string $target, string $format, array $
if ($res === true) {
$files = new ArchivableFilesFinder($sources, $excludes, $ignoreFilters);
foreach ($files as $file) {
/** @var \SplFileInfo $file */
/** @var \Symfony\Component\Finder\SplFileInfo $file */
$filepath = strtr($file->getPath()."/".$file->getFilename(), '\\', '/');
$localname = $filepath;
if (strpos($localname, $sources . '/') === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Package/Version/VersionGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function guessVersion(array $packageConfig, string $path): ?array
}

$versionData = $this->guessGitVersion($packageConfig, $path);
if (null !== $versionData && null !== $versionData['version']) {
if (null !== $versionData['version']) {
return $this->postprocess($versionData);
}

Expand All @@ -86,7 +86,7 @@ public function guessVersion(array $packageConfig, string $path): ?array
}

$versionData = $this->guessFossilVersion($path);
if (null !== $versionData && null !== $versionData['version']) {
if (null !== $versionData['version']) {
return $this->postprocess($versionData);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/SelfUpdate/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function getChannel(): string

public function setChannel(string $channel, ?IOInterface $io = null): void
{
if (!in_array($channel, self::$channels, true)) {
throw new \InvalidArgumentException('Invalid channel '.$channel.', must be one of: ' . implode(', ', self::$channels));
if (!in_array($channel, self::CHANNELS, true)) {
throw new \InvalidArgumentException('Invalid channel '.$channel.', must be one of: ' . implode(', ', self::CHANNELS));
}

$channelFile = $this->config->get('home').'/update-channel';
Expand Down
3 changes: 0 additions & 3 deletions tests/Composer/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ public function testInstaller(RootPackageInterface $rootPackage, array $reposito
$repositoryManager = new RepositoryManager($io, $config, $httpDownloader, $eventDispatcher);
$repositoryManager->setLocalRepository(new InstalledArrayRepository());

if (!is_array($repositories)) {
$repositories = [$repositories];
}
foreach ($repositories as $repository) {
$repositoryManager->addRepository($repository);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Test/Mock/ProcessExecutorMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(MockBuilder $processMockBuilder)
*/
public function expects(array $expectations, bool $strict = false, array $defaultHandler = ['return' => 0, 'stdout' => '', 'stderr' => '']): void
{
/** @var array{cmd: string|list<string>, return: int, stdout: string, stderr: string, callback: callable} $default */
/** @var array{cmd: string|list<string>, return: int, stdout: string, stderr: string, callback: callable|null} $default */
$default = ['cmd' => '', 'return' => 0, 'stdout' => '', 'stderr' => '', 'callback' => null];
$this->expectations = array_map(static function ($expect) use ($default): array {
if (is_string($expect)) {
Expand Down

0 comments on commit 5c3d8f3

Please sign in to comment.