Skip to content

Commit

Permalink
Fix more issues, update baseline (2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 24, 2022
1 parent 0d5488a commit e579b22
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 249 deletions.
182 changes: 1 addition & 181 deletions phpstan/baseline.neon
Expand Up @@ -1575,11 +1575,6 @@ parameters:
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Only booleans are allowed in a negated boolean, string given\\.$#"
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#"
count: 2
Expand All @@ -1595,11 +1590,6 @@ parameters:
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Only booleans are allowed in an if condition, string given\\.$#"
count: 1
path: ../src/Composer/Console/Application.php

-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 2
Expand Down Expand Up @@ -2295,11 +2285,6 @@ parameters:
count: 1
path: ../src/Composer/Downloader/FileDownloader.php

-
message: "#^Parameter \\#1 \\$url of function parse_url expects string, string\\|null given\\.$#"
count: 2
path: ../src/Composer/Downloader/FileDownloader.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 4
Expand Down Expand Up @@ -2395,11 +2380,6 @@ parameters:
count: 1
path: ../src/Composer/Downloader/GzipDownloader.php

-
message: "#^Parameter \\#1 \\$url of function parse_url expects string, string\\|null given\\.$#"
count: 1
path: ../src/Composer/Downloader/GzipDownloader.php

-
message: "#^Parameter \\#1 \\$zp of function gzclose expects resource, resource\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -3515,11 +3495,6 @@ parameters:
count: 10
path: ../src/Composer/Package/Loader/ArrayLoader.php

-
message: "#^Instanceof between Composer\\\\Package\\\\CompletePackage and Composer\\\\Package\\\\CompletePackage will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Package/Loader/ArrayLoader.php

-
message: "#^Instanceof between Composer\\\\Package\\\\CompletePackage and Composer\\\\Package\\\\CompletePackageInterface will always evaluate to true\\.$#"
count: 1
Expand Down Expand Up @@ -3555,11 +3530,6 @@ parameters:
count: 1
path: ../src/Composer/Package/Loader/ArrayLoader.php

-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Package/Loader/JsonLoader.php

-
message: "#^Parameter \\#1 \\$json of static method Composer\\\\Json\\\\JsonFile\\:\\:parseJson\\(\\) expects string\\|null, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -4305,16 +4275,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/FilesystemRepository.php

-
message: "#^Call to function is_array\\(\\) with array\\<string\\> will always evaluate to true\\.$#"
count: 2
path: ../src/Composer/Repository/FilterRepository.php

-
message: "#^Call to function is_bool\\(\\) with bool will always evaluate to true\\.$#"
count: 1
path: ../src/Composer/Repository/FilterRepository.php

-
message: "#^Only booleans are allowed in &&, string\\|null given on the left side\\.$#"
count: 1
Expand Down Expand Up @@ -4503,11 +4463,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/RepositoryFactory.php

-
message: "#^Parameter \\#3 \\$name of method Composer\\\\Repository\\\\RepositoryManager\\:\\:createRepository\\(\\) expects string\\|null, int\\|string given\\.$#"
count: 1
path: ../src/Composer/Repository/RepositoryFactory.php

-
message: "#^Only booleans are allowed in an if condition, Composer\\\\Package\\\\BasePackage\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -4793,21 +4748,11 @@ parameters:
count: 3
path: ../src/Composer/Repository/Vcs/GitLabDriver.php

-
message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#"
count: 2
path: ../src/Composer/Repository/Vcs/GitLabDriver.php

-
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
count: 1
path: ../src/Composer/Repository/Vcs/GitLabDriver.php

-
message: "#^Property Composer\\\\Repository\\\\Vcs\\\\VcsDriver\\:\\:\\$originUrl \\(string\\) does not accept string\\|false\\.$#"
count: 1
path: ../src/Composer/Repository/Vcs/GitLabDriver.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 2
Expand Down Expand Up @@ -5183,96 +5128,11 @@ parameters:
count: 1
path: ../src/Composer/Util/ErrorHandler.php

-
message: "#^Cannot call method getPathname\\(\\) on SplFileInfo\\|string\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Cannot call method isDir\\(\\) on SplFileInfo\\|string\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 2
path: ../src/Composer/Util/Filesystem.php

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

-
message: "#^Method Composer\\\\Util\\\\Filesystem\\:\\:size\\(\\) should return int but returns int\\<0, max\\>\\|false\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Offset 'message' does not exist on array\\{type\\: int, message\\: string, file\\: string, line\\: int\\}\\|null\\.$#"
count: 2
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Util\\\\ProcessExecutor\\|null given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only booleans are allowed in a ternary operator condition, array\\<int\\|string, int\\>\\|false given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only booleans are allowed in a ternary operator condition, int\\<0, max\\> given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Only numeric types are allowed in \\+, bool given on the right side\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
count: 4
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Parameter \\#1 \\$fp of function feof expects resource, resource\\|false given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#"
count: 2
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Parameter \\#1 \\$source of function stream_copy_to_stream expects resource, resource\\|false given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Parameter \\#2 \\$dest of function stream_copy_to_stream expects resource, resource\\|false given\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 1
path: ../src/Composer/Util/Filesystem.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
Expand Down Expand Up @@ -5385,7 +5245,7 @@ parameters:

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

-
Expand Down Expand Up @@ -6283,11 +6143,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/AllFunctionalTest.php

-
message: "#^Method Composer\\\\Test\\\\AllFunctionalTest\\:\\:getTestFiles\\(\\) should return array\\<string, array\\<string\\>\\> but returns array\\<string, array\\<int, string\\|false\\>\\>\\.$#"
count: 1
path: ../tests/Composer/Test/AllFunctionalTest.php

-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -6438,11 +6293,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php

-
message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#"
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php

-
message: "#^Parameter \\#2 \\$fixturesDir of method Composer\\\\Test\\\\DependencyResolver\\\\PoolBuilderTest\\:\\:readTestFile\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand All @@ -6458,11 +6308,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|string given\\.$#"
count: 2
path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
Expand All @@ -6478,11 +6323,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php

-
message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#"
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php

-
message: "#^Parameter \\#2 \\$fixturesDir of method Composer\\\\Test\\\\DependencyResolver\\\\PoolOptimizerTest\\:\\:readTestFile\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand All @@ -6493,11 +6333,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|string given\\.$#"
count: 2
path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php

-
message: "#^Parameter \\#1 \\$packages of class Composer\\\\DependencyResolver\\\\Pool constructor expects array\\<Composer\\\\Package\\\\BasePackage\\>, array\\<Composer\\\\Package\\\\BasePackage\\>\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -6696,11 +6531,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/InstallerTest.php

-
message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#"
count: 1
path: ../tests/Composer/Test/InstallerTest.php

-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false\\|null given\\.$#"
count: 1
Expand All @@ -6726,11 +6556,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/InstallerTest.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|string given\\.$#"
count: 2
path: ../tests/Composer/Test/InstallerTest.php

-
message: "#^Parameter \\#4 \\$composerFileContents of class Composer\\\\Package\\\\Locker constructor expects string, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -6791,11 +6616,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php

-
message: "#^Offset 'return' on array\\{return\\: int, stdout\\?\\: string, stderr\\?\\: string\\} on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php

-
message: "#^Offset 'stderr' does not exist on array\\{cmd\\: array\\<int, string\\>\\|string, return\\?\\: int, stdout\\?\\: string, stderr\\?\\: string, callback\\?\\: callable\\(\\)\\: mixed\\}\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions phpstan/config.neon
Expand Up @@ -17,6 +17,7 @@ parameters:
- '../tests/Composer/Test/PolyfillTestCase.php'

reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false

ignoreErrors:
# unused parameters
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Autoload/AutoloadGenerator.php
Expand Up @@ -744,11 +744,11 @@ protected function getPathCode(Filesystem $filesystem, string $basePath, string

/**
* @param array<int, array{0: PackageInterface, 1: string}> $packageMap
* @param bool $checkPlatform
* @param bool|'php-only' $checkPlatform
* @param string[] $devPackageNames
* @return ?string
*/
protected function getPlatformCheck(array $packageMap, bool $checkPlatform, array $devPackageNames)
protected function getPlatformCheck(array $packageMap, $checkPlatform, array $devPackageNames)
{
$lowestPhpVersion = Bound::zero();
$requiredExtensions = array();
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Downloader/FileDownloader.php
Expand Up @@ -343,7 +343,7 @@ public function install(PackageInterface $package, string $path, bool $output =

$this->filesystem->emptyDirectory($path);
$this->filesystem->ensureDirectoryExists($path);
$this->filesystem->rename($this->getFileName($package, $path), $path . '/' . pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME));
$this->filesystem->rename($this->getFileName($package, $path), $path . '/' . pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_BASENAME));

if ($package->getBinaries()) {
// Single files can not have a mode set like files in archives
Expand Down Expand Up @@ -436,7 +436,7 @@ public function remove(PackageInterface $package, string $path, bool $output = t
*/
protected function getFileName(PackageInterface $package, string $path): string
{
return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_EXTENSION), '.');
return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_EXTENSION), '.');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Downloader/GzipDownloader.php
Expand Up @@ -26,7 +26,7 @@ class GzipDownloader extends ArchiveDownloader
{
protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface
{
$filename = pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_FILENAME);
$filename = pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_FILENAME);
$targetFilepath = $path . DIRECTORY_SEPARATOR . $filename;

// Try to use gunzip on *nix
Expand Down
2 changes: 2 additions & 0 deletions src/Composer/IO/BaseIO.php
Expand Up @@ -201,6 +201,8 @@ public function debug($message, array $context = array()): void

public function log($level, $message, array $context = array()): void
{
$message = (string) $message;

if (in_array($level, array(LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR))) {
$this->writeError('<error>'.$message.'</error>');
} elseif ($level === LogLevel::WARNING) {
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Package/Loader/ValidatingArrayLoader.php
Expand Up @@ -286,7 +286,7 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
// check requires for exact constraints
($this->flags & self::CHECK_STRICT_CONSTRAINTS)
&& 'require' === $linkType
&& $linkConstraint instanceof Constraint && $linkConstraint->getOperator() === Constraint::STR_OP_EQ
&& $linkConstraint instanceof Constraint && in_array($linkConstraint->getOperator(), ['==', '='], true)
&& (new Constraint('>=', '1.0.0.0-dev'))->matches($linkConstraint)
) {
$this->warnings[] = $linkType.'.'.$package.' : exact version constraints ('.$constraint.') should be avoided if the package follows semantic versioning';
Expand Down

0 comments on commit e579b22

Please sign in to comment.