From 3cdca37e8588d262efbb3b589f8a68eea73738a2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Feb 2022 16:57:47 +0100 Subject: [PATCH 1/4] Fix strict type issues --- src/Composer/Command/CreateProjectCommand.php | 2 +- src/Composer/Command/SelfUpdateCommand.php | 2 +- src/Composer/Compiler.php | 12 +++++----- src/Composer/Console/Application.php | 14 +++++++----- src/Composer/Downloader/ArchiveDownloader.php | 2 +- .../Archiver/ArchivableFilesFinder.php | 2 +- src/Composer/Package/Loader/ArrayLoader.php | 7 ++++++ .../Package/Loader/ValidatingArrayLoader.php | 4 ++-- .../Repository/PlatformRepository.php | 4 ++-- src/Composer/Repository/RepositoryFactory.php | 2 +- src/Composer/Repository/Vcs/GitLabDriver.php | 6 ++++- tests/Composer/Test/AllFunctionalTest.php | 2 +- tests/Composer/Test/ApplicationTest.php | 8 +++---- tests/Composer/Test/CacheTest.php | 2 +- .../DependencyResolver/PoolBuilderTest.php | 8 +++---- .../DependencyResolver/PoolOptimizerTest.php | 7 +++--- .../Test/DependencyResolver/SolverTest.php | 3 ++- .../DependencyResolver/TransactionTest.php | 3 ++- .../Test/Downloader/FossilDownloaderTest.php | 8 +++---- .../Test/Downloader/HgDownloaderTest.php | 4 ++-- tests/Composer/Test/InstallerTest.php | 7 +++--- .../Test/Mock/ProcessExecutorMock.php | 4 ++-- .../Archiver/ArchivableFilesFinderTest.php | 2 +- .../Test/Repository/Vcs/GitLabDriverTest.php | 22 +++++++++---------- 24 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 4b185a6445da..d7da384e43cf 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -293,7 +293,7 @@ public function installProject(IOInterface $io, Config $config, InputInterface $ $dirs = iterator_to_array($finder); unset($finder); foreach ($dirs as $dir) { - if (!$fs->removeDirectory($dir)) { + if (!$fs->removeDirectory((string) $dir)) { throw new \RuntimeException('Could not remove '.$dir); } } diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 38390c0c0474..f8f49405a10e 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -510,7 +510,7 @@ protected function getLastBackupVersion(string $rollbackDir) $files = iterator_to_array($finder); if (count($files)) { - return basename(end($files), self::OLD_INSTALL_EXT); + return end($files)->getBasename(self::OLD_INSTALL_EXT); } return false; diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 76bc5ce7cc31..02e0ff022cb7 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -147,13 +147,13 @@ public function compile(string $pharFile = 'composer.phar'): void $unexpectedFiles = array(); foreach ($finder as $file) { - if (in_array(realpath($file), $extraFiles, true)) { - unset($extraFiles[array_search(realpath($file), $extraFiles, true)]); - } elseif (!Preg::isMatch('{([/\\\\]LICENSE|\.php)$}', $file)) { + if (false !== ($index = array_search($file->getRealPath(), $extraFiles, true))) { + unset($extraFiles[$index]); + } elseif (!Preg::isMatch('{(^LICENSE$|\.php$)}', $file->getFilename())) { $unexpectedFiles[] = (string) $file; } - if (Preg::isMatch('{\.php[\d.]*$}', $file)) { + if (Preg::isMatch('{\.php[\d.]*$}', $file->getFilename())) { $this->addFile($phar, $file); } else { $this->addFile($phar, $file, false); @@ -220,10 +220,10 @@ private function getRelativeFilePath(\SplFileInfo $file): string private function addFile(\Phar $phar, \SplFileInfo $file, bool $strip = true): void { $path = $this->getRelativeFilePath($file); - $content = file_get_contents($file); + $content = file_get_contents((string) $file); if ($strip) { $content = $this->stripWhitespace($content); - } elseif ('LICENSE' === basename($file)) { + } elseif ('LICENSE' === $file->getFilename()) { $content = "\n".$content."\n"; } diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index f2fac34fceed..ccb60e6cf291 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -150,7 +150,8 @@ public function doRun(InputInterface $input, OutputInterface $output): int } // switch working dir - if ($newWorkDir = $this->getNewWorkingDir($input)) { + $newWorkDir = $this->getNewWorkingDir($input); + if (null !== $newWorkDir) { $oldWorkingDir = Platform::getCwd(true); chdir($newWorkDir); $this->initialWorkingDirectory = $newWorkDir; @@ -171,7 +172,7 @@ public function doRun(InputInterface $input, OutputInterface $output): int } // prompt user for dir change if no composer.json is present in current dir - if ($io->isInteractive() && !$newWorkDir && !in_array($commandName, array('', 'list', 'init', 'about', 'help', 'diagnose', 'self-update', 'global', 'create-project', 'outdated'), true) && !file_exists(Factory::getComposerFile()) && ($useParentDirIfNoJsonAvailable = $this->getUseParentDirConfigValue()) !== false) { + if ($io->isInteractive() && null === $newWorkDir && !in_array($commandName, array('', 'list', 'init', 'about', 'help', 'diagnose', 'self-update', 'global', 'create-project', 'outdated'), true) && !file_exists(Factory::getComposerFile()) && ($useParentDirIfNoJsonAvailable = $this->getUseParentDirConfigValue()) !== false) { $dir = dirname(Platform::getCwd(true)); $home = realpath(Platform::getEnv('HOME') ?: Platform::getEnv('USERPROFILE') ?: '/'); @@ -357,12 +358,13 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow /** * @param InputInterface $input * @throws \RuntimeException - * @return string + * @return ?string */ - private function getNewWorkingDir(InputInterface $input): string + private function getNewWorkingDir(InputInterface $input): ?string { - $workingDir = $input->getParameterOption(array('--working-dir', '-d')); - if (false !== $workingDir && !is_dir($workingDir)) { + /** @var string|null $workingDir */ + $workingDir = $input->getParameterOption(array('--working-dir', '-d'), null, true); + if (null !== $workingDir && !is_dir($workingDir)) { throw new \RuntimeException('Invalid working directory specified, '.$workingDir.' does not exist.'); } diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index fc19004143bc..449593a6b2d2 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -175,7 +175,7 @@ public function install(PackageInterface $package, string $path, bool $output = } $contentDir = $getFolderContent($temporaryDir); - $singleDirAtTopLevel = 1 === count($contentDir) && is_dir(reset($contentDir)); + $singleDirAtTopLevel = 1 === count($contentDir) && is_dir((string) reset($contentDir)); if ($renameAsOne) { // if the target $path is clear, we can rename the whole package in one go instead of looping over the contents diff --git a/src/Composer/Package/Archiver/ArchivableFilesFinder.php b/src/Composer/Package/Archiver/ArchivableFilesFinder.php index fd589d7a2a67..9a53b719eb3e 100644 --- a/src/Composer/Package/Archiver/ArchivableFilesFinder.php +++ b/src/Composer/Package/Archiver/ArchivableFilesFinder.php @@ -99,7 +99,7 @@ public function accept(): bool return true; } - $iterator = new FilesystemIterator($current, FilesystemIterator::SKIP_DOTS); + $iterator = new FilesystemIterator((string) $current, FilesystemIterator::SKIP_DOTS); return !$iterator->valid(); } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index cd1f9e2bac73..5184eb01f487 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -408,6 +408,13 @@ private function createLink(string $source, string $sourceVersion, string $descr */ public function getBranchAlias(array $config): ?string { + if (!isset($config['version']) || !is_scalar($config['version'])) { + throw new \UnexpectedValueException('no/invalid version defined'); + } + if (!is_string($config['version'])) { + $config['version'] = (string) $config['version']; + } + if (strpos($config['version'], 'dev-') !== 0 && '-dev' !== substr($config['version'], -4)) { return null; } diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index eb7134eb90c3..9fb4a19cd847 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -286,8 +286,8 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa // check requires for exact constraints ($this->flags & self::CHECK_STRICT_CONSTRAINTS) && 'require' === $linkType - && strpos($linkConstraint, '=') === 0 - && $stableConstraint->versionCompare($stableConstraint, $linkConstraint, '<=') + && $linkConstraint instanceof Constraint && $linkConstraint->getOperator() === Constraint::STR_OP_EQ + && (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'; } diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 3c9c625fed86..6d8afe4a1c82 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -306,7 +306,7 @@ protected function initialize(): void } if (Preg::isMatch('/^libXpm Version => (?\d+)$/im', $info, $libxpmMatches)) { - $this->addLibrary($name.'-libxpm', Version::convertLibxpmVersionId($libxpmMatches['versionId']), 'libxpm version for gd'); + $this->addLibrary($name.'-libxpm', Version::convertLibxpmVersionId((int) $libxpmMatches['versionId']), 'libxpm version for gd'); } break; @@ -363,7 +363,7 @@ protected function initialize(): void $info = $this->runtime->getExtensionInfo($name); if (Preg::isMatch('/^Vendor Version => (?\d+)$/im', $info, $matches) && Preg::isMatch('/^Vendor Name => (?.+)$/im', $info, $vendorMatches)) { - $this->addLibrary($name.'-'.strtolower($vendorMatches['vendor']), Version::convertOpenldapVersionId($matches['versionId']), $vendorMatches['vendor'].' version of ldap'); + $this->addLibrary($name.'-'.strtolower($vendorMatches['vendor']), Version::convertOpenldapVersionId((int) $matches['versionId']), $vendorMatches['vendor'].' version of ldap'); } break; diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index 80e03eff89c3..25e86aa52a72 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -164,7 +164,7 @@ private static function createRepos(RepositoryManager $rm, array $repoConfigs): if ($repo['type'] === 'filesystem') { $repos[$name] = new FilesystemRepository($repo['json']); } else { - $repos[$name] = $rm->createRepository($repo['type'], $repo, $index); + $repos[$name] = $rm->createRepository($repo['type'], $repo, (string) $index); } } diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 2397b78d3ab9..a21ca6083ca2 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -105,7 +105,11 @@ public function initialize(): void ? $match['scheme'] : (isset($this->repoConfig['secure-http']) && $this->repoConfig['secure-http'] === false ? 'http' : 'https') ; - $this->originUrl = self::determineOrigin($configuredDomains, $guessedDomain, $urlParts, $match['port']); + $origin = self::determineOrigin($configuredDomains, $guessedDomain, $urlParts, $match['port']); + if (false === $origin) { + throw new \LogicException('It should not be possible to create a gitlab driver with an unparseable origin URL ('.$this->url.')'); + } + $this->originUrl = $origin; if ($protocol = $this->config->get('gitlab-protocol')) { // https treated as a synonym for http. diff --git a/tests/Composer/Test/AllFunctionalTest.php b/tests/Composer/Test/AllFunctionalTest.php index 2bebf801c758..a46b49859e76 100644 --- a/tests/Composer/Test/AllFunctionalTest.php +++ b/tests/Composer/Test/AllFunctionalTest.php @@ -184,7 +184,7 @@ public function getTestFiles(): array { $tests = array(); foreach (Finder::create()->in(__DIR__.'/Fixtures/functional')->name('*.test')->files() as $file) { - $tests[basename($file)] = array($file->getRealPath()); + $tests[$file->getFilename()] = array((string) $file); } return $tests; diff --git a/tests/Composer/Test/ApplicationTest.php b/tests/Composer/Test/ApplicationTest.php index e0674c4faad5..151eca5b4b24 100644 --- a/tests/Composer/Test/ApplicationTest.php +++ b/tests/Composer/Test/ApplicationTest.php @@ -55,8 +55,8 @@ public function testDevWarning(): void $inputMock->expects($this->once()) ->method('getParameterOption') - ->with($this->equalTo(array('--working-dir', '-d'))) - ->will($this->returnValue(false)); + ->with($this->equalTo(array('--working-dir', '-d')), $this->equalTo(null)) + ->will($this->returnValue(null)); $inputMock->expects($this->any()) ->method('getFirstArgument') @@ -116,8 +116,8 @@ public function ensureNoDevWarning(string $command): void $inputMock->expects($this->once()) ->method('getParameterOption') - ->with($this->equalTo(array('--working-dir', '-d'))) - ->will($this->returnValue(false)); + ->with($this->equalTo(array('--working-dir', '-d')), $this->equalTo(null)) + ->will($this->returnValue(null)); $inputMock->expects($this->any()) ->method('getFirstArgument') diff --git a/tests/Composer/Test/CacheTest.php b/tests/Composer/Test/CacheTest.php index 6b83ac961520..703650db31ad 100644 --- a/tests/Composer/Test/CacheTest.php +++ b/tests/Composer/Test/CacheTest.php @@ -17,7 +17,7 @@ class CacheTest extends TestCase { - /** @var string[] */ + /** @var array<\SplFileInfo> */ private $files; /** @var string */ private $root; diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index 913fa5470f49..847b374d4233 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -190,6 +190,8 @@ public function getIntegrationTests(): array $fixturesDir = realpath(__DIR__.'/Fixtures/poolbuilder/'); $tests = array(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + $file = (string) $file; + if (!Preg::isMatch('/\.test$/', $file)) { continue; } @@ -220,13 +222,11 @@ public function getIntegrationTests(): array } /** - * @param \SplFileInfo $file - * @param string $fixturesDir * @return array */ - protected function readTestFile(\SplFileInfo $file, string $fixturesDir): array + protected function readTestFile(string $file, string $fixturesDir): array { - $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); + $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); $sectionInfo = array( 'TEST' => true, diff --git a/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php b/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php index a9f87feaadb1..37e7346fc8d3 100644 --- a/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php @@ -76,6 +76,8 @@ public function provideIntegrationTests(): array $fixturesDir = realpath(__DIR__.'/Fixtures/pooloptimizer/'); $tests = array(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + $file = (string) $file; + if (!Preg::isMatch('/\.test$/', $file)) { continue; } @@ -97,12 +99,11 @@ public function provideIntegrationTests(): array } /** - * @param string $fixturesDir * @return mixed[] */ - protected function readTestFile(\SplFileInfo $file, string $fixturesDir): array + protected function readTestFile(string $file, string $fixturesDir): array { - $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); + $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); /** @var array $sectionInfo */ $sectionInfo = array( diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index f63e5167e21f..f3782f2fbd4c 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -24,6 +24,7 @@ use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Solver; use Composer\DependencyResolver\SolverProblemsException; +use Composer\Package\PackageInterface; use Composer\Package\Link; use Composer\Repository\RepositorySet; use Composer\Test\TestCase; @@ -1059,7 +1060,7 @@ protected function createSolver(): void } /** - * @param array> $expected + * @param array $expected * @return void */ protected function checkSolverResult(array $expected): void diff --git a/tests/Composer/Test/DependencyResolver/TransactionTest.php b/tests/Composer/Test/DependencyResolver/TransactionTest.php index 703fecf5630a..0f1182d849e1 100644 --- a/tests/Composer/Test/DependencyResolver/TransactionTest.php +++ b/tests/Composer/Test/DependencyResolver/TransactionTest.php @@ -19,6 +19,7 @@ use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\DependencyResolver\Transaction; use Composer\Package\Link; +use Composer\Package\PackageInterface; use Composer\Test\TestCase; class TransactionTest extends TestCase @@ -100,7 +101,7 @@ public function testTransactionGenerationAndSorting(): void /** * @param \Composer\DependencyResolver\Transaction $transaction - * @param array> $expected + * @param array $expected * @return void */ protected function checkTransactionOperations(Transaction $transaction, array $expected): void diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index 932fa5a36bb5..ebe9cf75e66e 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -62,7 +62,7 @@ public function testInstallForPackageWithoutSourceReference(): void self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); - $downloader->install($packageMock, '/path'); + $downloader->install($packageMock, $this->workingDir . '/path'); } public function testInstall(): void @@ -77,13 +77,13 @@ public function testInstall(): void $process = $this->getProcessExecutorMock(); $process->expects(array( - $this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \'repo.fossil\''), - $this->getCmd('fossil open --nested -- \'repo.fossil\''), + $this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \''.$this->workingDir.'.fossil\''), + $this->getCmd('fossil open --nested -- \''.$this->workingDir.'.fossil\''), $this->getCmd('fossil update -- \'trunk\''), ), true); $downloader = $this->getDownloaderMock(null, null, $process); - $downloader->install($packageMock, 'repo'); + $downloader->install($packageMock, $this->workingDir); } public function testUpdateforPackageWithoutSourceReference(): void diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index 135194263085..3c5712b4cf68 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -77,12 +77,12 @@ public function testDownload(): void $process = $this->getProcessExecutorMock(); $process->expects(array( - $this->getCmd('hg clone -- \'https://mercurial.dev/l3l0/composer\' \'composerPath\''), + $this->getCmd('hg clone -- \'https://mercurial.dev/l3l0/composer\' \''.$this->workingDir.'\''), $this->getCmd('hg up -- \'ref\''), ), true); $downloader = $this->getDownloaderMock(null, null, $process); - $downloader->install($packageMock, 'composerPath'); + $downloader->install($packageMock, $this->workingDir); } public function testUpdateforPackageWithoutSourceReference(): void diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 04e4346c062b..e22264338432 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -521,6 +521,8 @@ public function loadIntegrationTests(string $path): array $tests = array(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + $file = (string) $file; + if (!Preg::isMatch('/\.test$/', $file)) { continue; } @@ -598,12 +600,11 @@ public function loadIntegrationTests(string $path): array } /** - * @param string $fixturesDir * @return mixed[] */ - protected function readTestFile(\SplFileInfo $file, string $fixturesDir): array + protected function readTestFile(string $file, string $fixturesDir): array { - $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); + $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); $sectionInfo = array( 'TEST' => true, diff --git a/tests/Composer/Test/Mock/ProcessExecutorMock.php b/tests/Composer/Test/Mock/ProcessExecutorMock.php index 897d889ce4fb..b3e7d176eb60 100644 --- a/tests/Composer/Test/Mock/ProcessExecutorMock.php +++ b/tests/Composer/Test/Mock/ProcessExecutorMock.php @@ -103,7 +103,7 @@ public function assertComplete(): void Assert::assertTrue(true); // @phpstan-ignore-line } - public function execute($command, &$output = null, $cwd = null): int + public function execute($command, &$output = null, ?string $cwd = null): int { $cwd = $cwd ?? Platform::getCwd(); if (func_num_args() > 1) { @@ -113,7 +113,7 @@ public function execute($command, &$output = null, $cwd = null): int return $this->doExecute($command, $cwd, false); } - public function executeTty($command, $cwd = null): int + public function executeTty($command, ?string $cwd = null): int { $cwd = $cwd ?? Platform::getCwd(); if (Platform::isTty()) { diff --git a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php index 8ef013b278d8..2fb91a2b22cd 100644 --- a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php @@ -289,7 +289,7 @@ protected function getArchivedFiles(string $command): array $files = array(); foreach ($iterator as $file) { - $files[] = Preg::replace('#^phar://'.preg_quote($this->sources, '#').'/archive\.zip/archive#', '', $this->fs->normalizePath($file)); + $files[] = Preg::replace('#^phar://'.preg_quote($this->sources, '#').'/archive\.zip/archive#', '', $this->fs->normalizePath((string) $file)); } unset($archive, $iterator, $file); diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index 812c1bf05b4e..368655ec269f 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -52,18 +52,16 @@ class GitLabDriverTest extends TestCase public function setUp(): void { $this->home = $this->getUniqueTmpDirectory(); - $this->config = new Config(); - $this->config->merge(array( - 'config' => array( - 'home' => $this->home, - 'gitlab-domains' => array( - 'mycompany.com/gitlab', - 'gitlab.mycompany.com', - 'othercompany.com/nested/gitlab', - 'gitlab.com', - ), + $this->config = $this->getConfig([ + 'home' => $this->home, + 'gitlab-domains' => array( + 'mycompany.com/gitlab', + 'gitlab.mycompany.com', + 'othercompany.com/nested/gitlab', + 'gitlab.com', + 'gitlab.mycompany.local', ), - )); + ]); $this->io = $this->getMockBuilder('Composer\IO\IOInterface')->disableOriginalConstructor()->getMock(); $this->process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); @@ -593,7 +591,7 @@ public function testForwardsOptions(): void JSON; $this->httpDownloader->expects( - [['url' => 'https:///api/v4/projects/%2Fmyproject', 'body' => $projectData]], + [['url' => 'https://gitlab.mycompany.local/api/v4/projects/mygroup%2Fmyproject', 'body' => $projectData]], true ); From 6a466a120a404d1c5d492e5ca715841c491517fc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Feb 2022 16:58:18 +0100 Subject: [PATCH 2/4] Enable strict types on all files --- .php-cs-fixer.php | 2 +- src/Composer/Autoload/AutoloadGenerator.php | 2 +- src/Composer/Autoload/ClassMapGenerator.php | 2 +- src/Composer/Autoload/PhpFileCleaner.php | 2 +- src/Composer/Cache.php | 2 +- src/Composer/Command/AboutCommand.php | 2 +- src/Composer/Command/ArchiveCommand.php | 2 +- src/Composer/Command/BaseCommand.php | 2 +- src/Composer/Command/BaseDependencyCommand.php | 2 +- src/Composer/Command/CheckPlatformReqsCommand.php | 2 +- src/Composer/Command/ClearCacheCommand.php | 2 +- src/Composer/Command/ConfigCommand.php | 2 +- src/Composer/Command/CreateProjectCommand.php | 2 +- src/Composer/Command/DependsCommand.php | 2 +- src/Composer/Command/DiagnoseCommand.php | 2 +- src/Composer/Command/DumpAutoloadCommand.php | 2 +- src/Composer/Command/ExecCommand.php | 2 +- src/Composer/Command/FundCommand.php | 2 +- src/Composer/Command/GlobalCommand.php | 2 +- src/Composer/Command/HomeCommand.php | 2 +- src/Composer/Command/InitCommand.php | 2 +- src/Composer/Command/InstallCommand.php | 2 +- src/Composer/Command/LicensesCommand.php | 2 +- src/Composer/Command/OutdatedCommand.php | 2 +- src/Composer/Command/PackageDiscoveryTrait.php | 2 +- src/Composer/Command/ProhibitsCommand.php | 2 +- src/Composer/Command/ReinstallCommand.php | 2 +- src/Composer/Command/RemoveCommand.php | 2 +- src/Composer/Command/RequireCommand.php | 2 +- src/Composer/Command/RunScriptCommand.php | 2 +- src/Composer/Command/ScriptAliasCommand.php | 2 +- src/Composer/Command/SearchCommand.php | 2 +- src/Composer/Command/SelfUpdateCommand.php | 2 +- src/Composer/Command/ShowCommand.php | 2 +- src/Composer/Command/StatusCommand.php | 2 +- src/Composer/Command/SuggestsCommand.php | 2 +- src/Composer/Command/UpdateCommand.php | 2 +- src/Composer/Command/ValidateCommand.php | 2 +- src/Composer/Compiler.php | 2 +- src/Composer/Composer.php | 2 +- src/Composer/Config.php | 2 +- src/Composer/Config/ConfigSourceInterface.php | 2 +- src/Composer/Config/JsonConfigSource.php | 2 +- src/Composer/Console/Application.php | 2 +- src/Composer/Console/GithubActionError.php | 2 +- src/Composer/Console/HtmlOutputFormatter.php | 2 +- src/Composer/DependencyResolver/Decisions.php | 2 +- src/Composer/DependencyResolver/DefaultPolicy.php | 2 +- src/Composer/DependencyResolver/GenericRule.php | 2 +- src/Composer/DependencyResolver/LocalRepoTransaction.php | 2 +- src/Composer/DependencyResolver/LockTransaction.php | 2 +- src/Composer/DependencyResolver/MultiConflictRule.php | 2 +- src/Composer/DependencyResolver/Operation/InstallOperation.php | 2 +- .../Operation/MarkAliasInstalledOperation.php | 2 +- .../Operation/MarkAliasUninstalledOperation.php | 2 +- .../DependencyResolver/Operation/OperationInterface.php | 2 +- src/Composer/DependencyResolver/Operation/SolverOperation.php | 2 +- .../DependencyResolver/Operation/UninstallOperation.php | 2 +- src/Composer/DependencyResolver/Operation/UpdateOperation.php | 2 +- src/Composer/DependencyResolver/PolicyInterface.php | 2 +- src/Composer/DependencyResolver/Pool.php | 2 +- src/Composer/DependencyResolver/PoolBuilder.php | 2 +- src/Composer/DependencyResolver/PoolOptimizer.php | 2 +- src/Composer/DependencyResolver/Problem.php | 2 +- src/Composer/DependencyResolver/Request.php | 2 +- src/Composer/DependencyResolver/Rule.php | 2 +- src/Composer/DependencyResolver/Rule2Literals.php | 2 +- src/Composer/DependencyResolver/RuleSet.php | 2 +- src/Composer/DependencyResolver/RuleSetGenerator.php | 2 +- src/Composer/DependencyResolver/RuleSetIterator.php | 2 +- src/Composer/DependencyResolver/RuleWatchChain.php | 2 +- src/Composer/DependencyResolver/RuleWatchGraph.php | 2 +- src/Composer/DependencyResolver/RuleWatchNode.php | 2 +- src/Composer/DependencyResolver/Solver.php | 2 +- src/Composer/DependencyResolver/SolverBugException.php | 2 +- src/Composer/DependencyResolver/SolverProblemsException.php | 2 +- src/Composer/DependencyResolver/Transaction.php | 2 +- src/Composer/Downloader/ArchiveDownloader.php | 2 +- src/Composer/Downloader/ChangeReportInterface.php | 2 +- src/Composer/Downloader/DownloadManager.php | 2 +- src/Composer/Downloader/DownloaderInterface.php | 2 +- src/Composer/Downloader/DvcsDownloaderInterface.php | 2 +- src/Composer/Downloader/FileDownloader.php | 2 +- src/Composer/Downloader/FilesystemException.php | 2 +- src/Composer/Downloader/FossilDownloader.php | 2 +- src/Composer/Downloader/GitDownloader.php | 2 +- src/Composer/Downloader/GzipDownloader.php | 2 +- src/Composer/Downloader/HgDownloader.php | 2 +- src/Composer/Downloader/MaxFileSizeExceededException.php | 2 +- src/Composer/Downloader/PathDownloader.php | 2 +- src/Composer/Downloader/PerforceDownloader.php | 2 +- src/Composer/Downloader/PharDownloader.php | 2 +- src/Composer/Downloader/RarDownloader.php | 2 +- src/Composer/Downloader/SvnDownloader.php | 2 +- src/Composer/Downloader/TarDownloader.php | 2 +- src/Composer/Downloader/TransportException.php | 2 +- src/Composer/Downloader/VcsCapableDownloaderInterface.php | 2 +- src/Composer/Downloader/VcsDownloader.php | 2 +- src/Composer/Downloader/XzDownloader.php | 2 +- src/Composer/Downloader/ZipDownloader.php | 2 +- src/Composer/EventDispatcher/Event.php | 2 +- src/Composer/EventDispatcher/EventDispatcher.php | 2 +- src/Composer/EventDispatcher/EventSubscriberInterface.php | 2 +- src/Composer/EventDispatcher/ScriptExecutionException.php | 2 +- src/Composer/Exception/IrrecoverableDownloadException.php | 2 +- src/Composer/Exception/NoSslException.php | 2 +- src/Composer/Factory.php | 2 +- .../IgnoreAllPlatformRequirementFilter.php | 2 +- .../IgnoreListPlatformRequirementFilter.php | 2 +- .../IgnoreNothingPlatformRequirementFilter.php | 2 +- .../PlatformRequirementFilterFactory.php | 2 +- .../PlatformRequirementFilterInterface.php | 2 +- src/Composer/IO/BaseIO.php | 2 +- src/Composer/IO/BufferIO.php | 2 +- src/Composer/IO/ConsoleIO.php | 2 +- src/Composer/IO/IOInterface.php | 2 +- src/Composer/IO/NullIO.php | 2 +- src/Composer/Installer.php | 2 +- src/Composer/Installer/BinaryInstaller.php | 2 +- src/Composer/Installer/BinaryPresenceInterface.php | 2 +- src/Composer/Installer/InstallationManager.php | 2 +- src/Composer/Installer/InstallerEvent.php | 2 +- src/Composer/Installer/InstallerEvents.php | 2 +- src/Composer/Installer/InstallerInterface.php | 2 +- src/Composer/Installer/LibraryInstaller.php | 2 +- src/Composer/Installer/MetapackageInstaller.php | 2 +- src/Composer/Installer/NoopInstaller.php | 2 +- src/Composer/Installer/PackageEvent.php | 2 +- src/Composer/Installer/PackageEvents.php | 2 +- src/Composer/Installer/PluginInstaller.php | 2 +- src/Composer/Installer/ProjectInstaller.php | 2 +- src/Composer/Installer/SuggestedPackagesReporter.php | 2 +- src/Composer/Json/JsonFile.php | 2 +- src/Composer/Json/JsonFormatter.php | 2 +- src/Composer/Json/JsonManipulator.php | 2 +- src/Composer/Json/JsonValidationException.php | 2 +- src/Composer/Package/AliasPackage.php | 2 +- src/Composer/Package/Archiver/ArchivableFilesFilter.php | 2 +- src/Composer/Package/Archiver/ArchivableFilesFinder.php | 2 +- src/Composer/Package/Archiver/ArchiveManager.php | 2 +- src/Composer/Package/Archiver/ArchiverInterface.php | 2 +- src/Composer/Package/Archiver/BaseExcludeFilter.php | 2 +- src/Composer/Package/Archiver/ComposerExcludeFilter.php | 2 +- src/Composer/Package/Archiver/GitExcludeFilter.php | 2 +- src/Composer/Package/Archiver/PharArchiver.php | 2 +- src/Composer/Package/Archiver/ZipArchiver.php | 2 +- src/Composer/Package/BasePackage.php | 2 +- src/Composer/Package/Comparer/Comparer.php | 2 +- src/Composer/Package/CompleteAliasPackage.php | 2 +- src/Composer/Package/CompletePackage.php | 2 +- src/Composer/Package/CompletePackageInterface.php | 2 +- src/Composer/Package/Dumper/ArrayDumper.php | 2 +- src/Composer/Package/Link.php | 2 +- src/Composer/Package/Loader/ArrayLoader.php | 2 +- src/Composer/Package/Loader/InvalidPackageException.php | 2 +- src/Composer/Package/Loader/JsonLoader.php | 2 +- src/Composer/Package/Loader/LoaderInterface.php | 2 +- src/Composer/Package/Loader/RootPackageLoader.php | 2 +- src/Composer/Package/Loader/ValidatingArrayLoader.php | 2 +- src/Composer/Package/Locker.php | 2 +- src/Composer/Package/Package.php | 2 +- src/Composer/Package/PackageInterface.php | 2 +- src/Composer/Package/RootAliasPackage.php | 2 +- src/Composer/Package/RootPackage.php | 2 +- src/Composer/Package/RootPackageInterface.php | 2 +- src/Composer/Package/Version/StabilityFilter.php | 2 +- src/Composer/Package/Version/VersionGuesser.php | 2 +- src/Composer/Package/Version/VersionParser.php | 2 +- src/Composer/Package/Version/VersionSelector.php | 2 +- src/Composer/PartialComposer.php | 2 +- src/Composer/Platform/HhvmDetector.php | 2 +- src/Composer/Platform/Runtime.php | 2 +- src/Composer/Platform/Version.php | 2 +- src/Composer/Plugin/Capability/Capability.php | 2 +- src/Composer/Plugin/Capability/CommandProvider.php | 2 +- src/Composer/Plugin/Capable.php | 2 +- src/Composer/Plugin/CommandEvent.php | 2 +- src/Composer/Plugin/PluginEvents.php | 2 +- src/Composer/Plugin/PluginInterface.php | 2 +- src/Composer/Plugin/PluginManager.php | 2 +- src/Composer/Plugin/PostFileDownloadEvent.php | 2 +- src/Composer/Plugin/PreCommandRunEvent.php | 2 +- src/Composer/Plugin/PreFileDownloadEvent.php | 2 +- src/Composer/Plugin/PrePoolCreateEvent.php | 2 +- src/Composer/Question/StrictConfirmationQuestion.php | 2 +- src/Composer/Repository/ArrayRepository.php | 2 +- src/Composer/Repository/ArtifactRepository.php | 2 +- src/Composer/Repository/ComposerRepository.php | 2 +- src/Composer/Repository/CompositeRepository.php | 2 +- src/Composer/Repository/ConfigurableRepositoryInterface.php | 2 +- src/Composer/Repository/FilesystemRepository.php | 2 +- src/Composer/Repository/FilterRepository.php | 2 +- src/Composer/Repository/InstalledArrayRepository.php | 2 +- src/Composer/Repository/InstalledFilesystemRepository.php | 2 +- src/Composer/Repository/InstalledRepository.php | 2 +- src/Composer/Repository/InstalledRepositoryInterface.php | 2 +- src/Composer/Repository/InvalidRepositoryException.php | 2 +- src/Composer/Repository/LockArrayRepository.php | 2 +- src/Composer/Repository/PackageRepository.php | 2 +- src/Composer/Repository/PathRepository.php | 2 +- src/Composer/Repository/PearRepository.php | 2 +- src/Composer/Repository/PlatformRepository.php | 2 +- src/Composer/Repository/RepositoryFactory.php | 2 +- src/Composer/Repository/RepositoryInterface.php | 2 +- src/Composer/Repository/RepositoryManager.php | 2 +- src/Composer/Repository/RepositorySecurityException.php | 2 +- src/Composer/Repository/RepositorySet.php | 2 +- src/Composer/Repository/RootPackageRepository.php | 2 +- src/Composer/Repository/Vcs/FossilDriver.php | 2 +- src/Composer/Repository/Vcs/GitBitbucketDriver.php | 2 +- src/Composer/Repository/Vcs/GitDriver.php | 2 +- src/Composer/Repository/Vcs/GitHubDriver.php | 2 +- src/Composer/Repository/Vcs/GitLabDriver.php | 2 +- src/Composer/Repository/Vcs/HgDriver.php | 2 +- src/Composer/Repository/Vcs/PerforceDriver.php | 2 +- src/Composer/Repository/Vcs/SvnDriver.php | 2 +- src/Composer/Repository/Vcs/VcsDriver.php | 2 +- src/Composer/Repository/Vcs/VcsDriverInterface.php | 2 +- src/Composer/Repository/VcsRepository.php | 2 +- src/Composer/Repository/VersionCacheInterface.php | 2 +- src/Composer/Repository/WritableArrayRepository.php | 2 +- src/Composer/Repository/WritableRepositoryInterface.php | 2 +- src/Composer/Script/Event.php | 2 +- src/Composer/Script/ScriptEvents.php | 2 +- src/Composer/SelfUpdate/Keys.php | 2 +- src/Composer/SelfUpdate/Versions.php | 2 +- src/Composer/Util/AuthHelper.php | 2 +- src/Composer/Util/Bitbucket.php | 2 +- src/Composer/Util/ComposerMirror.php | 2 +- src/Composer/Util/ConfigValidator.php | 2 +- src/Composer/Util/ErrorHandler.php | 2 +- src/Composer/Util/Filesystem.php | 2 +- src/Composer/Util/Git.php | 2 +- src/Composer/Util/GitHub.php | 2 +- src/Composer/Util/GitLab.php | 2 +- src/Composer/Util/Hg.php | 2 +- src/Composer/Util/Http/CurlDownloader.php | 2 +- src/Composer/Util/Http/CurlResponse.php | 2 +- src/Composer/Util/Http/ProxyHelper.php | 2 +- src/Composer/Util/Http/ProxyManager.php | 2 +- src/Composer/Util/Http/RequestProxy.php | 2 +- src/Composer/Util/Http/Response.php | 2 +- src/Composer/Util/HttpDownloader.php | 2 +- src/Composer/Util/IniHelper.php | 2 +- src/Composer/Util/Loop.php | 2 +- src/Composer/Util/MetadataMinifier.php | 2 +- src/Composer/Util/NoProxyPattern.php | 2 +- src/Composer/Util/PackageInfo.php | 2 +- src/Composer/Util/PackageSorter.php | 2 +- src/Composer/Util/Perforce.php | 2 +- src/Composer/Util/Platform.php | 2 +- src/Composer/Util/ProcessExecutor.php | 2 +- src/Composer/Util/RemoteFilesystem.php | 2 +- src/Composer/Util/Silencer.php | 2 +- src/Composer/Util/StreamContextFactory.php | 2 +- src/Composer/Util/Svn.php | 2 +- src/Composer/Util/SyncHelper.php | 2 +- src/Composer/Util/Tar.php | 2 +- src/Composer/Util/TlsHelper.php | 2 +- src/Composer/Util/Url.php | 2 +- src/Composer/Util/Zip.php | 2 +- src/bootstrap.php | 2 +- tests/Composer/Test/AllFunctionalTest.php | 2 +- tests/Composer/Test/ApplicationTest.php | 2 +- tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 2 +- tests/Composer/Test/Autoload/ClassLoaderTest.php | 2 +- tests/Composer/Test/Autoload/ClassMapGeneratorTest.php | 2 +- tests/Composer/Test/CacheTest.php | 2 +- tests/Composer/Test/Command/ArchiveCommandTest.php | 2 +- tests/Composer/Test/Command/InitCommandTest.php | 2 +- tests/Composer/Test/Command/RunScriptCommandTest.php | 2 +- tests/Composer/Test/ComposerTest.php | 2 +- tests/Composer/Test/Config/JsonConfigSourceTest.php | 2 +- tests/Composer/Test/ConfigTest.php | 2 +- tests/Composer/Test/Console/HtmlOutputFormatterTest.php | 2 +- tests/Composer/Test/DefaultConfigTest.php | 2 +- tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php | 2 +- tests/Composer/Test/DependencyResolver/PoolBuilderTest.php | 2 +- tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php | 2 +- tests/Composer/Test/DependencyResolver/PoolTest.php | 2 +- tests/Composer/Test/DependencyResolver/RequestTest.php | 2 +- tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php | 2 +- tests/Composer/Test/DependencyResolver/RuleSetTest.php | 2 +- tests/Composer/Test/DependencyResolver/RuleTest.php | 2 +- tests/Composer/Test/DependencyResolver/SolverTest.php | 2 +- tests/Composer/Test/DependencyResolver/TransactionTest.php | 2 +- tests/Composer/Test/Downloader/ArchiveDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/DownloadManagerTest.php | 2 +- tests/Composer/Test/Downloader/FileDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/FossilDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/GitDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/HgDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/PerforceDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/XzDownloaderTest.php | 2 +- tests/Composer/Test/Downloader/ZipDownloaderTest.php | 2 +- tests/Composer/Test/EventDispatcher/EventDispatcherTest.php | 2 +- tests/Composer/Test/FactoryTest.php | 2 +- .../IgnoreAllPlatformRequirementFilterTest.php | 2 +- .../IgnoreListPlatformRequirementFilterTest.php | 2 +- .../IgnoreNothingPlatformRequirementFilterTest.php | 2 +- .../PlatformRequirementFilterFactoryTest.php | 2 +- tests/Composer/Test/IO/BufferIOTest.php | 2 +- tests/Composer/Test/IO/ConsoleIOTest.php | 2 +- tests/Composer/Test/IO/NullIOTest.php | 2 +- tests/Composer/Test/InstalledVersionsTest.php | 2 +- tests/Composer/Test/Installer/BinaryInstallerTest.php | 2 +- tests/Composer/Test/Installer/InstallationManagerTest.php | 2 +- tests/Composer/Test/Installer/InstallerEventTest.php | 2 +- tests/Composer/Test/Installer/LibraryInstallerTest.php | 2 +- tests/Composer/Test/Installer/MetapackageInstallerTest.php | 2 +- tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php | 2 +- tests/Composer/Test/InstallerTest.php | 2 +- tests/Composer/Test/Json/ComposerSchemaTest.php | 2 +- tests/Composer/Test/Json/JsonFileTest.php | 2 +- tests/Composer/Test/Json/JsonFormatterTest.php | 2 +- tests/Composer/Test/Json/JsonManipulatorTest.php | 2 +- tests/Composer/Test/Json/JsonValidationExceptionTest.php | 2 +- tests/Composer/Test/Mock/FactoryMock.php | 2 +- tests/Composer/Test/Mock/HttpDownloaderMock.php | 2 +- tests/Composer/Test/Mock/InstallationManagerMock.php | 2 +- tests/Composer/Test/Mock/InstalledFilesystemRepositoryMock.php | 2 +- tests/Composer/Test/Mock/ProcessExecutorMock.php | 2 +- tests/Composer/Test/Mock/VersionGuesserMock.php | 2 +- .../Test/Package/Archiver/ArchivableFilesFinderTest.php | 2 +- tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php | 2 +- tests/Composer/Test/Package/Archiver/ArchiverTest.php | 2 +- tests/Composer/Test/Package/Archiver/GitExcludeFilterTest.php | 2 +- tests/Composer/Test/Package/Archiver/PharArchiverTest.php | 2 +- tests/Composer/Test/Package/Archiver/ZipArchiverTest.php | 2 +- tests/Composer/Test/Package/BasePackageTest.php | 2 +- tests/Composer/Test/Package/CompletePackageTest.php | 2 +- tests/Composer/Test/Package/Dumper/ArrayDumperTest.php | 2 +- tests/Composer/Test/Package/Loader/ArrayLoaderTest.php | 2 +- tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php | 2 +- .../Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php | 2 +- tests/Composer/Test/Package/LockerTest.php | 2 +- tests/Composer/Test/Package/RootAliasPackageTest.php | 2 +- tests/Composer/Test/Package/Version/VersionGuesserTest.php | 2 +- tests/Composer/Test/Package/Version/VersionParserTest.php | 2 +- tests/Composer/Test/Package/Version/VersionSelectorTest.php | 2 +- tests/Composer/Test/Platform/HhvmDetectorTest.php | 2 +- tests/Composer/Test/Platform/VersionTest.php | 2 +- tests/Composer/Test/Plugin/Mock/Capability.php | 2 +- tests/Composer/Test/Plugin/Mock/CapablePluginInterface.php | 2 +- tests/Composer/Test/Plugin/PluginInstallerTest.php | 2 +- tests/Composer/Test/Question/StrictConfirmationQuestionTest.php | 2 +- tests/Composer/Test/Repository/ArrayRepositoryTest.php | 2 +- tests/Composer/Test/Repository/ArtifactRepositoryTest.php | 2 +- tests/Composer/Test/Repository/ComposerRepositoryTest.php | 2 +- tests/Composer/Test/Repository/CompositeRepositoryTest.php | 2 +- tests/Composer/Test/Repository/FilesystemRepositoryTest.php | 2 +- tests/Composer/Test/Repository/FilterRepositoryTest.php | 2 +- tests/Composer/Test/Repository/InstalledRepositoryTest.php | 2 +- tests/Composer/Test/Repository/PathRepositoryTest.php | 2 +- tests/Composer/Test/Repository/PlatformRepositoryTest.php | 2 +- tests/Composer/Test/Repository/RepositoryFactoryTest.php | 2 +- tests/Composer/Test/Repository/RepositoryManagerTest.php | 2 +- tests/Composer/Test/Repository/Vcs/FossilDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/HgDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php | 2 +- tests/Composer/Test/Repository/Vcs/SvnDriverTest.php | 2 +- tests/Composer/Test/Repository/VcsRepositoryTest.php | 2 +- tests/Composer/Test/Script/EventTest.php | 2 +- tests/Composer/Test/TestCase.php | 2 +- tests/Composer/Test/Util/AuthHelperTest.php | 2 +- tests/Composer/Test/Util/BitbucketTest.php | 2 +- tests/Composer/Test/Util/ConfigValidatorTest.php | 2 +- tests/Composer/Test/Util/ErrorHandlerTest.php | 2 +- tests/Composer/Test/Util/FilesystemTest.php | 2 +- tests/Composer/Test/Util/GitHubTest.php | 2 +- tests/Composer/Test/Util/GitLabTest.php | 2 +- tests/Composer/Test/Util/GitTest.php | 2 +- tests/Composer/Test/Util/Http/ProxyHelperTest.php | 2 +- tests/Composer/Test/Util/Http/ProxyManagerTest.php | 2 +- tests/Composer/Test/Util/Http/RequestProxyTest.php | 2 +- tests/Composer/Test/Util/HttpDownloaderTest.php | 2 +- tests/Composer/Test/Util/IniHelperTest.php | 2 +- tests/Composer/Test/Util/MetadataMinifierTest.php | 2 +- tests/Composer/Test/Util/NoProxyPatternTest.php | 2 +- tests/Composer/Test/Util/PackageSorterTest.php | 2 +- tests/Composer/Test/Util/PerforceTest.php | 2 +- tests/Composer/Test/Util/PlatformTest.php | 2 +- tests/Composer/Test/Util/ProcessExecutorTest.php | 2 +- tests/Composer/Test/Util/RemoteFilesystemTest.php | 2 +- tests/Composer/Test/Util/SilencerTest.php | 2 +- tests/Composer/Test/Util/StreamContextFactoryTest.php | 2 +- tests/Composer/Test/Util/SvnTest.php | 2 +- tests/Composer/Test/Util/TarTest.php | 2 +- tests/Composer/Test/Util/TlsHelperTest.php | 2 +- tests/Composer/Test/Util/UrlTest.php | 2 +- tests/Composer/Test/Util/ZipTest.php | 2 +- tests/bootstrap.php | 2 +- tests/console-application.php | 2 +- 396 files changed, 396 insertions(+), 396 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 62d1ac7f74fa..ed2e6cf2bae8 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -71,7 +71,7 @@ 'random_api_migration' => true, 'ternary_to_null_coalescing' => true, 'phpdoc_to_param_type' => true, - //'declare_strict_types' => true, + 'declare_strict_types' => true, // TODO php 7.4 migration (one day..) // 'phpdoc_to_property_type' => true, diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 5485565e0dd0..0ddcc9df1fd4 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1,4 +1,4 @@ - Date: Wed, 23 Feb 2022 17:57:03 +0100 Subject: [PATCH 3/4] Fix more issues, update baseline (2203/106) --- phpstan/baseline-8.1.neon | 30 --- phpstan/baseline.neon | 182 +----------------- phpstan/config.neon | 1 + src/Composer/Autoload/AutoloadGenerator.php | 4 +- src/Composer/Downloader/FileDownloader.php | 4 +- src/Composer/Downloader/GzipDownloader.php | 2 +- src/Composer/IO/BaseIO.php | 2 + .../Package/Loader/ValidatingArrayLoader.php | 2 +- .../Repository/ComposerRepository.php | 4 +- src/Composer/Util/Filesystem.php | 88 +++++---- src/Composer/Util/RemoteFilesystem.php | 2 +- tests/Composer/Test/Util/FilesystemTest.php | 36 ++-- 12 files changed, 78 insertions(+), 279 deletions(-) diff --git a/phpstan/baseline-8.1.neon b/phpstan/baseline-8.1.neon index 792be138f133..ee7346d3a8bd 100644 --- a/phpstan/baseline-8.1.neon +++ b/phpstan/baseline-8.1.neon @@ -130,11 +130,6 @@ parameters: count: 1 path: ../src/Composer/EventDispatcher/EventDispatcher.php - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Factory.php - - message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#" count: 1 @@ -215,31 +210,6 @@ parameters: count: 1 path: ../src/Composer/Util/AuthHelper.php - - - message: "#^Parameter \\#1 \\$from of function stream_copy_to_stream expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 4 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function feof expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function fread expects resource, resource\\|false given\\.$#" - count: 2 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#2 \\$to of function stream_copy_to_stream expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, string\\|null given\\.$#" count: 15 diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index f2e9f63da0e2..7eced10576a5 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -4305,16 +4275,6 @@ parameters: count: 1 path: ../src/Composer/Repository/FilesystemRepository.php - - - message: "#^Call to function is_array\\(\\) with array\\ 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 @@ -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 @@ -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 @@ -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\\\\|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 @@ -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 - @@ -6283,11 +6143,6 @@ parameters: count: 1 path: ../tests/Composer/Test/AllFunctionalTest.php - - - message: "#^Method Composer\\\\Test\\\\AllFunctionalTest\\:\\:getTestFiles\\(\\) should return array\\\\> but returns array\\\\>\\.$#" - count: 1 - path: ../tests/Composer/Test/AllFunctionalTest.php - - message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#" count: 1 @@ -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 @@ -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 @@ -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 @@ -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\\, array\\\\|null given\\.$#" count: 1 @@ -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 @@ -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 @@ -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\\\\|string, return\\?\\: int, stdout\\?\\: string, stderr\\?\\: string, callback\\?\\: callable\\(\\)\\: mixed\\}\\.$#" count: 1 diff --git a/phpstan/config.neon b/phpstan/config.neon index e5469b6a7364..5ac2cd37b1ca 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -17,6 +17,7 @@ parameters: - '../tests/Composer/Test/PolyfillTestCase.php' reportUnmatchedIgnoredErrors: false + treatPhpDocTypesAsCertain: false ignoreErrors: # unused parameters diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 0ddcc9df1fd4..ffb0cd83cfa5 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -744,11 +744,11 @@ protected function getPathCode(Filesystem $filesystem, string $basePath, string /** * @param array $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(); diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 738a386ae231..39eaf6528b40 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -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 @@ -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), '.'); } /** diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php index 60ab50549201..4e91b8023b4e 100644 --- a/src/Composer/Downloader/GzipDownloader.php +++ b/src/Composer/Downloader/GzipDownloader.php @@ -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 diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index d7247e411766..4f9bc1da926a 100644 --- a/src/Composer/IO/BaseIO.php +++ b/src/Composer/IO/BaseIO.php @@ -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(''.$message.''); } elseif ($level === LogLevel::WARNING) { diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index cce97be794ce..ac55d89e4959 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -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'; diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 72005682b2aa..3e0146b2ebcb 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -142,7 +142,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config, $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6); } - $urlBits = parse_url($repoConfig['url']); + $urlBits = parse_url(strtr($repoConfig['url'], '\\', '/')); if ($urlBits === false || empty($urlBits['scheme'])) { throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$repoConfig['url']); } @@ -998,7 +998,7 @@ private function isVersionAcceptable(?ConstraintInterface $constraint, string $n */ private function getPackagesJsonUrl(): string { - $jsonUrlParts = parse_url($this->url); + $jsonUrlParts = parse_url(strtr($this->url, '\\', '/')); if (isset($jsonUrlParts['path']) && false !== strpos($jsonUrlParts['path'], '.json')) { return $this->url; diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 6d089017e39a..21ea5711590b 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -291,7 +291,7 @@ public function unlink(string $path) if (!$unlinked) { $error = error_get_last(); - $message = 'Could not delete '.$path.': ' . @$error['message']; + $message = 'Could not delete '.$path.': ' . ($error['message'] ?? ''); if (Platform::isWindows()) { $message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed"; } @@ -322,7 +322,7 @@ public function rmdir(string $path) if (!$deleted) { $error = error_get_last(); - $message = 'Could not delete '.$path.': ' . @$error['message']; + $message = 'Could not delete '.$path.': ' . ($error['message'] ?? ''); if (Platform::isWindows()) { $message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed"; } @@ -375,7 +375,6 @@ public function copy(string $source, string $target) $this->ensureDirectoryExists($target); $result = true; - /** @var RecursiveDirectoryIterator $ri */ foreach ($ri as $file) { $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathname(); if ($file->isDir()) { @@ -451,8 +450,8 @@ public function findShortestPath(string $from, string $to, bool $directories = f throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to)); } - $from = lcfirst($this->normalizePath($from)); - $to = lcfirst($this->normalizePath($to)); + $from = $this->normalizePath($from); + $to = $this->normalizePath($to); if ($directories) { $from = rtrim($from, '/') . '/dummy_file'; @@ -463,7 +462,7 @@ public function findShortestPath(string $from, string $to, bool $directories = f } $commonPath = $to; - while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !Preg::isMatch('{^[a-z]:/?$}i', $commonPath)) { + while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !Preg::isMatch('{^[A-Z]:/?$}i', $commonPath)) { $commonPath = strtr(\dirname($commonPath), '\\', '/'); } @@ -472,10 +471,15 @@ public function findShortestPath(string $from, string $to, bool $directories = f } $commonPath = rtrim($commonPath, '/') . '/'; - $sourcePathDepth = substr_count(substr($from, \strlen($commonPath)), '/'); + $sourcePathDepth = substr_count((string) substr($from, \strlen($commonPath)), '/'); $commonPathCode = str_repeat('../', $sourcePathDepth); - return ($commonPathCode . substr($to, \strlen($commonPath))) ?: './'; + $result = $commonPathCode . substr($to, \strlen($commonPath)); + if (\strlen($result) === 0) { + return './'; + } + + return $result; } /** @@ -494,15 +498,15 @@ public function findShortestPathCode(string $from, string $to, bool $directories throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to)); } - $from = lcfirst($this->normalizePath($from)); - $to = lcfirst($this->normalizePath($to)); + $from = $this->normalizePath($from); + $to = $this->normalizePath($to); if ($from === $to) { return $directories ? '__DIR__' : '__FILE__'; } $commonPath = $to; - while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !Preg::isMatch('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) { + while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !Preg::isMatch('{^[A-Z]:/?$}i', $commonPath) && '.' !== $commonPath) { $commonPath = strtr(\dirname($commonPath), '\\', '/'); } @@ -512,17 +516,17 @@ public function findShortestPathCode(string $from, string $to, bool $directories $commonPath = rtrim($commonPath, '/') . '/'; if (strpos($to, $from.'/') === 0) { - return '__DIR__ . '.var_export(substr($to, \strlen($from)), true); + return '__DIR__ . '.var_export((string) substr($to, \strlen($from)), true); } - $sourcePathDepth = substr_count(substr($from, \strlen($commonPath)), '/') + $directories; + $sourcePathDepth = substr_count((string) substr($from, \strlen($commonPath)), '/') + (int) $directories; if ($staticCode) { $commonPathCode = "__DIR__ . '".str_repeat('/..', $sourcePathDepth)."'"; } else { $commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth); } - $relTarget = substr($to, \strlen($commonPath)); + $relTarget = (string) substr($to, \strlen($commonPath)); - return $commonPathCode . (\strlen($relTarget) ? '.' . var_export('/' . $relTarget, true) : ''); + return $commonPathCode . (\strlen($relTarget) > 0 ? '.' . var_export('/' . $relTarget, true) : ''); } /** @@ -553,7 +557,7 @@ public function size(string $path) return $this->directorySize($path); } - return filesize($path); + return (int) filesize($path); } /** @@ -589,16 +593,19 @@ public function normalizePath(string $path) $up = false; foreach (explode('/', $path) as $chunk) { - if ('..' === $chunk && ($absolute !== '' || $up)) { + if ('..' === $chunk && (\strlen($absolute) > 0 || $up)) { array_pop($parts); - $up = !(empty($parts) || '..' === end($parts)); + $up = !(\count($parts) === 0 || '..' === end($parts)); } elseif ('.' !== $chunk && '' !== $chunk) { $parts[] = $chunk; $up = '..' !== $chunk; } } - return $prefix.((string) $absolute).implode('/', $parts); + // ensure c: is normalized to C: + $prefix = Preg::replaceCallback('{(^|://)[a-z]:$}i', function (array $m) { return strtoupper($m[0]); }, $prefix); + + return $prefix.$absolute.implode('/', $parts); } /** @@ -640,7 +647,7 @@ public static function getPlatformPath(string $path) $path = Preg::replace('{^(?:file:///([a-z]):?/)}i', 'file://$1:/', $path); } - return (string) Preg::replace('{^file://}i', '', $path); + return Preg::replace('{^file://}i', '', $path); } /** @@ -695,7 +702,7 @@ protected function directorySize(string $directory) */ protected function getProcess() { - if (!$this->processExecutor) { + if (null === $this->processExecutor) { $this->processExecutor = new ProcessExecutor(); } @@ -789,7 +796,7 @@ private function resolveSymlinkedDirectorySymlink(string $pathname): string $resolved = rtrim($pathname, '/'); - if (!\strlen($resolved)) { + if (0 === \strlen($resolved)) { return $pathname; } @@ -859,7 +866,7 @@ public function isJunction(string $junction) $stat = lstat($junction); // S_ISDIR test (S_IFDIR is 0x4000, S_IFMT is 0xF000 bitmask) - return $stat ? 0x4000 !== ($stat['mode'] & 0xF000) : false; + return is_array($stat) ? 0x4000 !== ($stat['mode'] & 0xF000) : false; } /** @@ -889,8 +896,8 @@ public function removeJunction(string $junction) */ public function filePutContentsIfModified(string $path, string $content) { - $currentContent = @file_get_contents($path); - if (!$currentContent || ($currentContent != $content)) { + $currentContent = Silencer::call('file_get_contents', $path); + if (false === $currentContent || $currentContent !== $content) { return file_put_contents($path, $content); } @@ -908,23 +915,20 @@ public function filePutContentsIfModified(string $path, string $content) public function safeCopy(string $source, string $target) { if (!file_exists($target) || !file_exists($source) || !$this->filesAreEqual($source, $target)) { - $source = fopen($source, 'r'); - $target = fopen($target, 'w+'); + $sourceHandle = fopen($source, 'r'); + assert($sourceHandle !== false, 'Could not open "'.$source.'" for reading.'); + $targetHandle = fopen($target, 'w+'); + assert($targetHandle !== false, 'Could not open "'.$target.'" for writing.'); - stream_copy_to_stream($source, $target); - fclose($source); - fclose($target); + stream_copy_to_stream($sourceHandle, $targetHandle); + fclose($sourceHandle); + fclose($targetHandle); } } /** * compare 2 files * https://stackoverflow.com/questions/3060125/can-i-use-file-get-contents-to-compare-two-files - * - * @param string $a - * @param string $b - * - * @return bool */ private function filesAreEqual(string $a, string $b): bool { @@ -934,19 +938,21 @@ private function filesAreEqual(string $a, string $b): bool } // Check if content is different - $ah = fopen($a, 'rb'); - $bh = fopen($b, 'rb'); + $aHandle = fopen($a, 'rb'); + assert($aHandle !== false, 'Could not open "'.$a.'" for reading.'); + $bHandle = fopen($b, 'rb'); + assert($bHandle !== false, 'Could not open "'.$b.'" for reading.'); $result = true; - while (!feof($ah)) { - if (fread($ah, 8192) != fread($bh, 8192)) { + while (!feof($aHandle)) { + if (fread($aHandle, 8192) !== fread($bHandle, 8192)) { $result = false; break; } } - fclose($ah); - fclose($bh); + fclose($aHandle); + fclose($bHandle); return $result; } diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 5aa7d668522c..a22998e55aca 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -219,7 +219,7 @@ public function findStatusMessage(array $headers) */ protected function get(string $originUrl, string $fileUrl, array $additionalOptions = array(), string $fileName = null, bool $progress = true) { - $this->scheme = parse_url($fileUrl, PHP_URL_SCHEME); + $this->scheme = parse_url(strtr($fileUrl, '\\', '/'), PHP_URL_SCHEME); $this->bytesMax = 0; $this->originUrl = $originUrl; $this->fileUrl = $fileUrl; diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index e40e532674eb..e035f24fc6b1 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -74,19 +74,19 @@ public function providePathCouplesAsCode(): array array('/foo/bin/run', '/bar/bin/run', false, "'/bar/bin/run'"), array('c:/bin/run', 'c:/vendor/acme/bin/run', false, "dirname(__DIR__).'/vendor/acme/bin/run'"), array('c:\\bin\\run', 'c:/vendor/acme/bin/run', false, "dirname(__DIR__).'/vendor/acme/bin/run'"), - array('c:/bin/run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"), - array('c:\\bin\\run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"), + array('c:/bin/run', 'D:/vendor/acme/bin/run', false, "'D:/vendor/acme/bin/run'"), + array('c:\\bin\\run', 'd:/vendor/acme/bin/run', false, "'D:/vendor/acme/bin/run'"), array('/foo/bar', '/foo/bar', true, "__DIR__"), array('/foo/bar/', '/foo/bar', true, "__DIR__"), array('/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"), array('/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), array('/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"), array('/bin/run', '/bin/run', true, "__DIR__"), - array('c:/bin/run', 'c:\\bin/run', true, "__DIR__"), + array('c:/bin/run', 'C:\\bin/run', true, "__DIR__"), array('c:/bin/run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), array('c:\\bin\\run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), - array('c:/bin/run', 'd:/vendor/acme/bin/run', true, "'d:/vendor/acme/bin/run'"), - array('c:\\bin\\run', 'd:/vendor/acme/bin/run', true, "'d:/vendor/acme/bin/run'"), + array('c:/bin/run', 'd:/vendor/acme/bin/run', true, "'D:/vendor/acme/bin/run'"), + array('c:\\bin\\run', 'd:/vendor/acme/bin/run', true, "'D:/vendor/acme/bin/run'"), array('C:/Temp/test', 'C:\Temp', true, "dirname(__DIR__)"), array('C:/Temp', 'C:\Temp\test', true, "__DIR__ . '/test'"), array('/tmp/test', '/tmp', true, "dirname(__DIR__)"), @@ -96,7 +96,7 @@ public function providePathCouplesAsCode(): array array('/tmp/test/../vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"), array('/tmp/test/.././vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"), array('C:/Temp', 'c:\Temp\..\..\test', true, "dirname(__DIR__).'/test'"), - array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"), + array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'D:/test'"), array('/foo/bar', '/foo/bar_vendor', true, "dirname(__DIR__).'/bar_vendor'"), array('/foo/bar_vendor', '/foo/bar', true, "dirname(__DIR__).'/bar'"), array('/foo/bar_vendor', '/foo/bar/src', true, "dirname(__DIR__).'/bar/src'"), @@ -106,7 +106,7 @@ public function providePathCouplesAsCode(): array array('/tmp/test/../vendor', '/tmp/test', true, "__DIR__ . '/..'.'/test'", true), array('/tmp/test/.././vendor', '/tmp/test', true, "__DIR__ . '/..'.'/test'", true), array('C:/Temp', 'c:\Temp\..\..\test', true, "__DIR__ . '/..'.'/test'", true), - array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'", true), + array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'D:/test'", true), array('/foo/bar', '/foo/bar_vendor', true, "__DIR__ . '/..'.'/bar_vendor'", true), array('/foo/bar_vendor', '/foo/bar', true, "__DIR__ . '/..'.'/bar'", true), array('/foo/bar_vendor', '/foo/bar/src', true, "__DIR__ . '/..'.'/bar/src'", true), @@ -141,11 +141,11 @@ public function providePathCouples(): array array('/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"), array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run"), array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run", true), - array('c:/foo/bin/run', 'd:/bar/bin/run', "d:/bar/bin/run", true), + array('c:/foo/bin/run', 'd:/bar/bin/run', "D:/bar/bin/run", true), array('c:/bin/run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"), array('c:\\bin\\run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"), - array('c:/bin/run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"), - array('c:\\bin\\run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"), + array('c:/bin/run', 'd:/vendor/acme/bin/run', "D:/vendor/acme/bin/run"), + array('c:\\bin\\run', 'd:/vendor/acme/bin/run', "D:/vendor/acme/bin/run"), array('C:/Temp/test', 'C:\Temp', "./"), array('/tmp/test', '/tmp', "./"), array('C:/Temp/test/sub', 'C:\Temp', "../"), @@ -160,7 +160,7 @@ public function providePathCouples(): array array('/tmp/test/.././vendor', '/tmp/test', '../test', true), array('C:/Temp', 'c:\Temp\..\..\test', "../test", true), array('C:/Temp/../..', 'c:\Temp\..\..\test', "./test", true), - array('C:/Temp/../..', 'D:\Temp\..\..\test', "d:/test", true), + array('C:/Temp/../..', 'D:\Temp\..\..\test', "D:/test", true), array('/tmp', '/tmp/../../test', '/test', true), array('/foo/bar', '/foo/bar_vendor', '../bar_vendor', true), array('/foo/bar_vendor', '/foo/bar', '../bar', true), @@ -217,24 +217,24 @@ public function provideNormalizedPaths(): array { return array( array('../foo', '../foo'), - array('c:/foo/bar', 'c:/foo//bar'), + array('C:/foo/bar', 'c:/foo//bar'), array('C:/foo/bar', 'C:/foo/./bar'), array('C:/foo/bar', 'C://foo//bar'), array('C:/foo/bar', 'C:///foo//bar'), array('C:/bar', 'C:/foo/../bar'), array('/bar', '/foo/../bar/'), - array('phar://c:/Foo', 'phar://c:/Foo/Bar/..'), - array('phar://c:/Foo', 'phar://c:///Foo/Bar/..'), - array('phar://c:/', 'phar://c:/Foo/Bar/../../../..'), + array('phar://C:/Foo', 'phar://c:/Foo/Bar/..'), + array('phar://C:/Foo', 'phar://c:///Foo/Bar/..'), + array('phar://C:/', 'phar://c:/Foo/Bar/../../../..'), array('/', '/Foo/Bar/../../../..'), array('/', '/'), array('/', '//'), array('/', '///'), array('/Foo', '///Foo'), - array('c:/', 'c:\\'), + array('C:/', 'c:\\'), array('../src', 'Foo/Bar/../../../src'), - array('c:../b', 'c:.\\..\\a\\..\\b'), - array('phar://c:../Foo', 'phar://c:../Foo'), + array('C:../b', 'c:.\\..\\a\\..\\b'), + array('phar://C:../Foo', 'phar://c:../Foo'), array('//foo/bar', '\\\\foo\\bar'), ); } From 4fdcfb166f0e6526d3d6bc992a24b41fd9109bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Thu, 24 Feb 2022 13:21:22 +0100 Subject: [PATCH 4/4] Better ignore-by-php-version.neon.php --- phpstan/ignore-by-php-version.neon.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/phpstan/ignore-by-php-version.neon.php b/phpstan/ignore-by-php-version.neon.php index a88d63bced28..21212110c723 100644 --- a/phpstan/ignore-by-php-version.neon.php +++ b/phpstan/ignore-by-php-version.neon.php @@ -1,14 +1,12 @@ = 80000) { - $config = array_merge_recursive($config, $adapter->load(__DIR__ . '/baseline-8.1.neon')); + $includes[] = __DIR__ . '/baseline-8.1.neon'; } + +$config['includes'] = $includes; $config['parameters']['phpVersion'] = PHP_VERSION_ID; return $config;