diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 73ec3d5e7..cbabb867b 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -441,7 +441,7 @@ EOF; * @param array $scannedFiles * @return array */ - private function addClassMapCode(Filesystem $filesystem, $basePath, $vendorPath, $dir, $excluded, $namespaceFilter, $autoloadType, array $classMap, array &$ambiguousClasses, array &$scannedFiles) + private function addClassMapCode(Filesystem $filesystem, $basePath, $vendorPath, $dir, $excluded, $namespaceFilter, $autoloadType, array $classMap, array &$ambiguousClasses, array &$scannedFiles): array { foreach ($this->generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, true, $scannedFiles) as $class => $path) { $pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n"; @@ -464,7 +464,7 @@ EOF; * @param array $scannedFiles * @return array */ - private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, $showAmbiguousWarning, array &$scannedFiles) + private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, $showAmbiguousWarning, array &$scannedFiles): array { if ($excluded) { // filter excluded patterns here to only use those matching $dir diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 9d0c73f1f..babb3d892 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -157,7 +157,7 @@ class ClassMapGenerator * @param ?IOInterface $io IO object * @return array valid classes */ - private static function filterByNamespace($classes, $filePath, $baseNamespace, $namespaceType, $basePath, $io) + private static function filterByNamespace($classes, $filePath, $baseNamespace, $namespaceType, $basePath, $io): array { $validClasses = array(); $rejectedClasses = array(); @@ -215,7 +215,7 @@ class ClassMapGenerator * @throws \RuntimeException * @return array The found classes */ - private static function findClasses($path) + private static function findClasses($path): array { $extraTypes = self::getExtraTypes(); @@ -296,7 +296,7 @@ class ClassMapGenerator /** * @return string */ - private static function getExtraTypes() + private static function getExtraTypes(): string { static $extraTypes = null; diff --git a/src/Composer/Autoload/PhpFileCleaner.php b/src/Composer/Autoload/PhpFileCleaner.php index 17341a935..8fc077418 100644 --- a/src/Composer/Autoload/PhpFileCleaner.php +++ b/src/Composer/Autoload/PhpFileCleaner.php @@ -78,7 +78,7 @@ class PhpFileCleaner /** * @return string */ - public function clean() + public function clean(): string { $clean = ''; @@ -260,7 +260,7 @@ class PhpFileCleaner * @param string $char * @return bool */ - private function peek($char) + private function peek($char): bool { return $this->index + 1 < $this->len && $this->contents[$this->index + 1] === $char; } @@ -270,7 +270,7 @@ class PhpFileCleaner * @param ?array $match * @return bool */ - private function match($regex, array &$match = null) + private function match($regex, array &$match = null): bool { return Preg::isMatch($regex, $this->contents, $match, 0, $this->index); } diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index a39ffd541..9d231e247 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -260,7 +260,8 @@ EOT try { $this->httpDownloader->get($proto . '://repo.packagist.org/packages.json'); } catch (TransportException $e) { - if ($hints = HttpDownloader::getExceptionHints($e)) { + $hints = HttpDownloader::getExceptionHints($e); + if (null !== $hints && count($hints) > 0) { foreach ($hints as $hint) { $result[] = $hint; } @@ -436,7 +437,7 @@ EOT /** * @return string */ - private function getCurlVersion() + private function getCurlVersion(): string { if (extension_loaded('curl')) { if (!HttpDownloader::isCurlEnabled()) { @@ -458,7 +459,7 @@ EOT * * @return void */ - private function outputResult($result) + private function outputResult($result): void { $io = $this->getIO(); if (true === $result) { diff --git a/src/Composer/Command/FundCommand.php b/src/Composer/Command/FundCommand.php index 5d397f058..c6287dac9 100644 --- a/src/Composer/Command/FundCommand.php +++ b/src/Composer/Command/FundCommand.php @@ -134,7 +134,7 @@ class FundCommand extends BaseCommand * @param mixed[] $fundings * @return mixed[] */ - private function insertFundingData(array $fundings, CompletePackageInterface $package) + private function insertFundingData(array $fundings, CompletePackageInterface $package): array { foreach ($package->getFunding() as $fundingOption) { list($vendor, $packageName) = explode('/', $package->getPrettyName()); diff --git a/src/Composer/Command/HomeCommand.php b/src/Composer/Command/HomeCommand.php index eaab9fdab..b83f31e03 100644 --- a/src/Composer/Command/HomeCommand.php +++ b/src/Composer/Command/HomeCommand.php @@ -101,7 +101,7 @@ EOT * @param bool $showOnly * @return bool */ - private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly) + private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly): bool { $support = $package->getSupport(); $url = $support['source'] ?? $package->getSourceUrl(); @@ -158,7 +158,7 @@ EOT * * @return RepositoryInterface[] */ - private function initializeRepos() + private function initializeRepos(): array { $composer = $this->tryComposer(); diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 6869d4068..6a52fd246 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -623,7 +623,7 @@ EOT /** * @return void */ - private function updateDependencies(OutputInterface $output) + private function updateDependencies(OutputInterface $output): void { try { $updateCommand = $this->getApplication()->find('update'); @@ -637,7 +637,7 @@ EOT /** * @return void */ - private function runDumpAutoloadCommand(OutputInterface $output) + private function runDumpAutoloadCommand(OutputInterface $output): void { try { $command = $this->getApplication()->find('dump-autoload'); @@ -652,7 +652,7 @@ EOT * @param array> $options * @return bool */ - private function hasDependencies($options) + private function hasDependencies($options): bool { $requires = (array) $options['require']; $devRequires = isset($options['require-dev']) ? (array) $options['require-dev'] : array(); diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index de51bba87..49a54c2fb 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -163,7 +163,7 @@ EOT * @param array $bucket * @return array */ - private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()) + private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()): array { $requires = array_keys($package->getRequires()); diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index c46a96518..5ad66a794 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -296,7 +296,7 @@ EOT * @param string $requireKey * @return string[] */ - private function getInconsistentRequireKeys(array $newRequirements, $requireKey) + private function getInconsistentRequireKeys(array $newRequirements, $requireKey): array { $requireKeys = $this->getPackagesByRequireKey(); $inconsistentRequirements = array(); @@ -315,7 +315,7 @@ EOT /** * @return array */ - private function getPackagesByRequireKey() + private function getPackagesByRequireKey(): array { $composerDefinition = $this->json->read(); $require = array(); @@ -351,7 +351,7 @@ EOT * @return int * @throws \Exception */ - private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey) + private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey): int { // Update packages $this->resetComposer(); @@ -449,7 +449,7 @@ EOT * @param bool $sortPackages * @return bool */ - private function updateFileCleanly(JsonFile $json, array $new, $requireKey, $removeKey, $sortPackages) + private function updateFileCleanly(JsonFile $json, array $new, $requireKey, $removeKey, $sortPackages): bool { $contents = file_get_contents($json->getPath()); diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 5a80f1db9..ab8861031 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -923,7 +923,7 @@ EOT * @param array $versions * @return array */ - private function appendVersions($json, array $versions) + private function appendVersions($json, array $versions): array { uasort($versions, 'version_compare'); $versions = array_keys(array_reverse($versions)); @@ -936,7 +936,7 @@ EOT * @param array $json * @return array */ - private function appendLicenses($json, CompletePackageInterface $package) + private function appendLicenses($json, CompletePackageInterface $package): array { if ($licenses = $package->getLicense()) { $spdxLicenses = new SpdxLicenses(); @@ -963,7 +963,7 @@ EOT * @param array $json * @return array */ - private function appendAutoload($json, CompletePackageInterface $package) + private function appendAutoload($json, CompletePackageInterface $package): array { if ($package->getAutoload()) { $autoload = array(); @@ -996,7 +996,7 @@ EOT * @param array $json * @return array */ - private function appendLinks($json, CompletePackageInterface $package) + private function appendLinks($json, CompletePackageInterface $package): array { foreach (Link::$TYPES as $linkType) { $json = $this->appendLink($json, $package, $linkType); @@ -1010,7 +1010,7 @@ EOT * @param string $linkType * @return array */ - private function appendLink($json, CompletePackageInterface $package, $linkType) + private function appendLink($json, CompletePackageInterface $package, $linkType): array { $links = $package->{'get' . ucfirst($linkType)}(); @@ -1240,7 +1240,7 @@ EOT * @param string $updateStatus * @return string */ - private function updateStatusToVersionStyle($updateStatus) + private function updateStatusToVersionStyle($updateStatus): string { // 'up-to-date' is printed green // 'semver-safe-update' is printed red @@ -1251,7 +1251,7 @@ EOT /** * @return string */ - private function getUpdateStatus(PackageInterface $latestPackage, PackageInterface $package) + private function getUpdateStatus(PackageInterface $latestPackage, PackageInterface $package): string { if ($latestPackage->getFullPrettyVersion() === $package->getFullPrettyVersion()) { return 'up-to-date'; @@ -1275,7 +1275,7 @@ EOT * * @return void */ - private function writeTreeLine($line) + private function writeTreeLine($line): void { $io = $this->getIO(); if (!$io->isDecorated()) { @@ -1326,7 +1326,7 @@ EOT /** * @return RepositorySet */ - private function getRepositorySet(Composer $composer) + private function getRepositorySet(Composer $composer): RepositorySet { if (!$this->repositorySet) { $this->repositorySet = new RepositorySet($composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags()); @@ -1342,7 +1342,7 @@ EOT * @param array $bucket * @return array */ - private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()) + private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()): array { $requires = $package->getRequires(); diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 99cd983d1..4a7bfe223 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -80,7 +80,7 @@ EOT /** * @return int */ - private function doExecute(InputInterface $input) + private function doExecute(InputInterface $input): int { // init repos $composer = $this->requireComposer(); diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index c2efd014b..119fab20e 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -245,7 +245,7 @@ EOT * @param array $packages * @return array */ - private function getPackagesInteractively(IOInterface $io, InputInterface $input, OutputInterface $output, Composer $composer, array $packages) + private function getPackagesInteractively(IOInterface $io, InputInterface $input, OutputInterface $output, Composer $composer, array $packages): array { if (!$input->isInteractive()) { throw new \InvalidArgumentException('--interactive cannot be used in non-interactive terminals.'); @@ -312,7 +312,7 @@ EOT * @param string $constraint * @return Link */ - private function appendConstraintToLink(Link $link, $constraint) + private function appendConstraintToLink(Link $link, $constraint): Link { $parser = new VersionParser; $oldPrettyString = $link->getConstraint()->getPrettyString(); diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 619ac4ea8..6c30d2b6d 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -201,7 +201,7 @@ class Compiler * @param \SplFileInfo $file * @return string */ - private function getRelativeFilePath($file) + private function getRelativeFilePath($file): string { $realPath = $file->getRealPath(); $pathPrefix = dirname(__DIR__, 2).DIRECTORY_SEPARATOR; @@ -258,7 +258,7 @@ class Compiler * @param string $source A PHP string * @return string The PHP string with the whitespace removed */ - private function stripWhitespace($source) + private function stripWhitespace($source): string { if (!function_exists('token_get_all')) { return $source; @@ -289,7 +289,7 @@ class Compiler /** * @return string */ - private function getStub() + private function getStub(): string { $stub = <<<'EOF' #!/usr/bin/env php diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 1dd2f0773..d6b3da4e8 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -531,7 +531,7 @@ class Config * @param string $path * @return string */ - private function realpath($path) + private function realpath($path): string { if (Preg::isMatch('{^(?:/|[a-z]:|[a-z0-9.]+://)}i', $path)) { return $path; diff --git a/src/Composer/Config/JsonConfigSource.php b/src/Composer/Config/JsonConfigSource.php index 604c41f9a..798e0af1c 100644 --- a/src/Composer/Config/JsonConfigSource.php +++ b/src/Composer/Config/JsonConfigSource.php @@ -214,7 +214,7 @@ class JsonConfigSource implements ConfigSourceInterface * * @return void */ - private function manipulateJson($method, $fallback, ...$args) + private function manipulateJson($method, $fallback, ...$args): void { if ($this->file->exists()) { if (!is_writable($this->file->getPath())) { @@ -297,7 +297,7 @@ class JsonConfigSource implements ConfigSourceInterface * @param mixed $value * @return int */ - private function arrayUnshiftRef(&$array, &$value) + private function arrayUnshiftRef(&$array, &$value): int { $return = array_unshift($array, ''); $array[0] = &$value; diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 4762396af..24811b34b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -358,7 +358,7 @@ class Application extends BaseApplication * @throws \RuntimeException * @return string */ - private function getNewWorkingDir(InputInterface $input) + private function getNewWorkingDir(InputInterface $input): string { $workingDir = $input->getParameterOption(array('--working-dir', '-d')); if (false !== $workingDir && !is_dir($workingDir)) { @@ -371,7 +371,7 @@ class Application extends BaseApplication /** * @return void */ - private function hintCommonErrors(\Exception $exception) + private function hintCommonErrors(\Exception $exception): void { $io = $this->getIO(); @@ -408,7 +408,8 @@ class Application extends BaseApplication $io->writeError('Check https://getcomposer.org/doc/06-config.md#process-timeout for details', true, IOInterface::QUIET); } - if ($hints = HttpDownloader::getExceptionHints($exception)) { + $hints = HttpDownloader::getExceptionHints($exception); + if (null !== $hints && count($hints) > 0) { foreach ($hints as $hint) { $io->writeError($hint, true, IOInterface::QUIET); } @@ -553,7 +554,7 @@ class Application extends BaseApplication /** * @return Command\BaseCommand[] */ - private function getPluginCommands() + private function getPluginCommands(): array { $commands = array(); diff --git a/src/Composer/Console/GithubActionError.php b/src/Composer/Console/GithubActionError.php index 6f8710261..578ac8eca 100644 --- a/src/Composer/Console/GithubActionError.php +++ b/src/Composer/Console/GithubActionError.php @@ -55,7 +55,7 @@ final class GithubActionError * @param string $data * @return string */ - private function escapeData($data) + private function escapeData($data): string { // see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L80-L85 $data = str_replace("%", '%25', $data); @@ -69,7 +69,7 @@ final class GithubActionError * @param string $property * @return string */ - private function escapeProperty($property) + private function escapeProperty($property): string { // see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L87-L94 $property = str_replace("%", '%25', $property); diff --git a/src/Composer/DependencyResolver/LockTransaction.php b/src/Composer/DependencyResolver/LockTransaction.php index e46b66c1a..75da918ae 100644 --- a/src/Composer/DependencyResolver/LockTransaction.php +++ b/src/Composer/DependencyResolver/LockTransaction.php @@ -106,7 +106,7 @@ class LockTransaction extends Transaction * @param bool $updateMirrors * @return BasePackage[] */ - public function getNewLockPackages($devMode, $updateMirrors = false) + public function getNewLockPackages($devMode, $updateMirrors = false): array { $packages = array(); foreach ($this->resultPackages[$devMode ? 'dev' : 'non-dev'] as $package) { @@ -137,7 +137,7 @@ class LockTransaction extends Transaction * @param array $aliases * @return array */ - public function getAliases($aliases) + public function getAliases($aliases): array { $usedAliases = array(); diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 3888ef8a5..981e40fe6 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -159,7 +159,7 @@ class Pool implements \Countable * packages must match or null to return all * @return BasePackage[] */ - private function computeWhatProvides($name, ConstraintInterface $constraint = null) + private function computeWhatProvides($name, ConstraintInterface $constraint = null): array { if (!isset($this->packageByName[$name])) { return array(); diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index c0b2ed4d2..b80ff7a44 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -499,7 +499,7 @@ class PoolBuilder * @param string $name packageName * @return bool */ - private function isRootRequire(Request $request, $name) + private function isRootRequire(Request $request, $name): bool { $rootRequires = $request->getRequires(); @@ -510,7 +510,7 @@ class PoolBuilder * @param string $name * @return string[] */ - private function getSkippedRootRequires(Request $request, $name) + private function getSkippedRootRequires(Request $request, $name): array { if (!isset($this->skippedLoad[$name])) { return array(); @@ -553,7 +553,7 @@ class PoolBuilder * * @return bool */ - private function isUpdateAllowed(BasePackage $package) + private function isUpdateAllowed(BasePackage $package): bool { foreach ($this->updateAllowList as $pattern => $void) { $patternRegexp = BasePackage::packageNameToRegexp($pattern); @@ -684,7 +684,7 @@ class PoolBuilder /** * @return Pool */ - private function runOptimizer(Request $request, Pool $pool) + private function runOptimizer(Request $request, Pool $pool): Pool { if (null === $this->poolOptimizer) { return $pool; diff --git a/src/Composer/DependencyResolver/PoolOptimizer.php b/src/Composer/DependencyResolver/PoolOptimizer.php index 420c1ec66..3ae0c61c7 100644 --- a/src/Composer/DependencyResolver/PoolOptimizer.php +++ b/src/Composer/DependencyResolver/PoolOptimizer.php @@ -173,7 +173,7 @@ class PoolOptimizer /** * @return Pool Optimized pool */ - private function applyRemovalsToPool(Pool $pool) + private function applyRemovalsToPool(Pool $pool): Pool { $packages = array(); $removedVersions = array(); @@ -278,7 +278,7 @@ class PoolOptimizer /** * @return string */ - private function calculateDependencyHash(BasePackage $package) + private function calculateDependencyHash(BasePackage $package): string { $hash = ''; diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 124a544cb..101187e16 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -117,7 +117,7 @@ class Problem * @return string * @internal */ - public static function formatDeduplicatedRules($rules, $indent, RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, array $installedMap = array(), array $learnedPool = array()) + public static function formatDeduplicatedRules($rules, $indent, RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, array $installedMap = array(), array $learnedPool = array()): string { $messages = array(); $templates = array(); @@ -210,7 +210,7 @@ class Problem * @param string $packageName * @return array{0: string, 1: string} */ - public static function getMissingPackageReason(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $packageName, ConstraintInterface $constraint = null) + public static function getMissingPackageReason(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $packageName, ConstraintInterface $constraint = null): array { if (PlatformRepository::isPlatformPackage($packageName)) { // handle php/php-*/hhvm @@ -382,7 +382,7 @@ class Problem * @param bool $useRemovedVersionGroup * @return string */ - public static function getPackageList(array $packages, $isVerbose, Pool $pool = null, ConstraintInterface $constraint = null, $useRemovedVersionGroup = false) + public static function getPackageList(array $packages, $isVerbose, Pool $pool = null, ConstraintInterface $constraint = null, $useRemovedVersionGroup = false): string { $prepared = array(); $hasDefaultBranch = array(); @@ -427,7 +427,7 @@ class Problem * @param string $version the effective runtime version of the platform package * @return ?string a version string or null if it appears the package was artificially disabled */ - private static function getPlatformPackageVersion(Pool $pool, $packageName, $version) + private static function getPlatformPackageVersion(Pool $pool, $packageName, $version): ?string { $available = $pool->whatProvides($packageName); @@ -471,7 +471,7 @@ class Problem * @param int $maxDev * @return list a list of pretty versions and '...' where versions were removed */ - private static function condenseVersionList(array $versions, $max, $maxDev = 16) + private static function condenseVersionList(array $versions, $max, $maxDev = 16): array { if (count($versions) <= $max) { return $versions; @@ -505,7 +505,7 @@ class Problem * @param PackageInterface[] $packages * @return bool */ - private static function hasMultipleNames(array $packages) + private static function hasMultipleNames(array $packages): bool { $name = null; foreach ($packages as $package) { @@ -527,7 +527,7 @@ class Problem * @param string $reason * @return array{0: string, 1: string} */ - private static function computeCheckForLowerPrioRepo(Pool $pool, $isVerbose, $packageName, array $higherRepoPackages, array $allReposPackages, $reason, ConstraintInterface $constraint = null) + private static function computeCheckForLowerPrioRepo(Pool $pool, $isVerbose, $packageName, array $higherRepoPackages, array $allReposPackages, $reason, ConstraintInterface $constraint = null): array { $nextRepoPackages = array(); $nextRepo = null; diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index c5f324038..4a1ba886e 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -232,7 +232,7 @@ abstract class Rule * @internal * @return BasePackage */ - public function getSourcePackage(Pool $pool) + public function getSourcePackage(Pool $pool): BasePackage { $literals = $this->getLiterals(); @@ -498,7 +498,7 @@ abstract class Rule /** * @return BasePackage */ - private function deduplicateDefaultBranchAlias(BasePackage $package) + private function deduplicateDefaultBranchAlias(BasePackage $package): BasePackage { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) { $package = $package->getAliasOf(); diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 45814c36e..37f079d68 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -302,7 +302,7 @@ class Solver * @param string|int $literal * @return int */ - private function setPropagateLearn($level, $literal, Rule $rule) + private function setPropagateLearn($level, $literal, Rule $rule): int { $level++; @@ -351,7 +351,7 @@ class Solver * @param int[] $decisionQueue * @return int */ - private function selectAndInstall($level, array $decisionQueue, Rule $rule) + private function selectAndInstall($level, array $decisionQueue, Rule $rule): int { // choose best package to install from decisionQueue $literals = $this->policy->selectPreferredPackages($this->pool, $decisionQueue, $rule->getRequiredPackage()); @@ -548,7 +548,7 @@ class Solver /** * @return int */ - private function analyzeUnsolvable(Rule $conflictRule) + private function analyzeUnsolvable(Rule $conflictRule): int { $problem = new Problem(); $problem->addRule($conflictRule); diff --git a/src/Composer/DependencyResolver/SolverProblemsException.php b/src/Composer/DependencyResolver/SolverProblemsException.php index deaec7d24..12196b561 100644 --- a/src/Composer/DependencyResolver/SolverProblemsException.php +++ b/src/Composer/DependencyResolver/SolverProblemsException.php @@ -109,7 +109,7 @@ class SolverProblemsException extends \RuntimeException * @param string[] $missingExtensions * @return string */ - private function createExtensionHint(array $missingExtensions) + private function createExtensionHint(array $missingExtensions): string { $paths = IniHelper::getAll(); @@ -133,7 +133,7 @@ class SolverProblemsException extends \RuntimeException * @param Rule[][] $reasonSets * @return string[] */ - private function getExtensionProblems(array $reasonSets) + private function getExtensionProblems(array $reasonSets): array { $missingExtensions = array(); foreach ($reasonSets as $reasonSet) { diff --git a/src/Composer/DependencyResolver/Transaction.php b/src/Composer/DependencyResolver/Transaction.php index 265474123..2e6640eee 100644 --- a/src/Composer/DependencyResolver/Transaction.php +++ b/src/Composer/DependencyResolver/Transaction.php @@ -60,7 +60,7 @@ class Transaction /** * @return OperationInterface[] */ - public function getOperations() + public function getOperations(): array { return $this->operations; } @@ -101,7 +101,7 @@ class Transaction /** * @return OperationInterface[] */ - protected function calculateOperations() + protected function calculateOperations(): array { $operations = array(); @@ -218,7 +218,7 @@ class Transaction * * @return array */ - protected function getRootPackages() + protected function getRootPackages(): array { $roots = $this->resultPackageMap; @@ -244,7 +244,7 @@ class Transaction /** * @return PackageInterface[] */ - protected function getProvidersInResult(Link $link) + protected function getProvidersInResult(Link $link): array { if (!isset($this->resultPackagesByName[$link->getTarget()])) { return array(); @@ -266,7 +266,7 @@ class Transaction * @param OperationInterface[] $operations * @return OperationInterface[] reordered operation list */ - private function movePluginsToFront(array $operations) + private function movePluginsToFront(array $operations): array { $dlModifyingPluginsNoDeps = array(); $dlModifyingPluginsWithDeps = array(); @@ -343,7 +343,7 @@ class Transaction * @param OperationInterface[] $operations * @return OperationInterface[] reordered operation list */ - private function moveUninstallsToFront(array $operations) + private function moveUninstallsToFront(array $operations): array { $uninstOps = array(); foreach ($operations as $idx => $op) { diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 71eb87ee6..7b40784f4 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -406,7 +406,7 @@ class DownloadManager * @return string[] * @phpstan-return array<'dist'|'source'>&non-empty-array */ - private function getAvailableSources(PackageInterface $package, PackageInterface $prevPackage = null) + private function getAvailableSources(PackageInterface $package, PackageInterface $prevPackage = null): array { $sourceType = $package->getSourceType(); $distType = $package->getDistType(); @@ -456,7 +456,7 @@ class DownloadManager * * @return string */ - private function normalizeTargetDir($dir) + private function normalizeTargetDir($dir): string { if ($dir === '\\' || $dir === '/') { return $dir; diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 74c36f136..122e5a9b6 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -295,7 +295,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter * * @return bool */ - private function safeJunctions() + private function safeJunctions(): bool { // We need to call mklink, and rmdir on Windows 7 (version 6.1) return function_exists('proc_open') && diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 8f2427727..0a4e59413 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -57,7 +57,7 @@ class PerforceDownloader extends VcsDownloader * * @return string|null */ - private function getLabelFromSourceReference($ref) + private function getLabelFromSourceReference($ref): ?string { $pos = strpos($ref, '@'); if (false !== $pos) { @@ -92,7 +92,7 @@ class PerforceDownloader extends VcsDownloader /** * @return array */ - private function getRepoConfig(VcsRepository $repository) + private function getRepoConfig(VcsRepository $repository): array { return $repository->getRepoConfig(); } diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index eaea3d9da..b87deb044 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -346,7 +346,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa * * @return string[] */ - private function prepareUrls(array $urls) + private function prepareUrls(array $urls): array { foreach ($urls as $index => $url) { if (Filesystem::isLocalPath($url)) { diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index 23ad6db76..1347f296d 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -105,7 +105,7 @@ class ZipDownloader extends ArchiveDownloader * @param string $path Path where to extract file * @return PromiseInterface */ - private function extractWithSystemUnzip(PackageInterface $package, $file, $path) + private function extractWithSystemUnzip(PackageInterface $package, $file, $path): PromiseInterface { // Force Exception throwing if the other alternative extraction method is not available $isLastChance = !self::$hasZipArchive; @@ -172,7 +172,7 @@ class ZipDownloader extends ArchiveDownloader * @param string $path Path where to extract file * @return PromiseInterface */ - private function extractWithZipArchive(PackageInterface $package, $file, $path) + private function extractWithZipArchive(PackageInterface $package, $file, $path): PromiseInterface { $processError = null; $zipArchive = $this->zipArchiveObject ?: new ZipArchive(); diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 29b1f5de7..704c1e403 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -556,7 +556,7 @@ class EventDispatcher /** * @return void */ - private function ensureBinDirIsInPath() + private function ensureBinDirIsInPath(): void { $pathEnv = 'PATH'; if (false === Platform::getEnv('PATH') && false !== Platform::getEnv('Path')) { diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 5911b6633..4f7c6fb2d 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -696,7 +696,7 @@ class Factory /** * @return bool */ - private static function useXdg() + private static function useXdg(): bool { foreach (array_keys($_SERVER) as $key) { if (strpos($key, 'XDG_') === 0) { @@ -715,7 +715,7 @@ class Factory * @throws \RuntimeException * @return string */ - private static function getUserDir() + private static function getUserDir(): string { $home = Platform::getEnv('HOME'); if (!$home) { diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php index d1fb51b8f..ca37baea4 100644 --- a/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php @@ -20,7 +20,7 @@ final class IgnoreAllPlatformRequirementFilter implements PlatformRequirementFil * @param string $req * @return bool */ - public function isIgnored($req) + public function isIgnored($req): bool { return PlatformRepository::isPlatformPackage($req); } diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php index 6c3adf14b..e51d59b39 100644 --- a/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php @@ -55,7 +55,7 @@ final class IgnoreListPlatformRequirementFilter implements PlatformRequirementFi * @param string $req * @return bool */ - public function isIgnored($req) + public function isIgnored($req): bool { if (!PlatformRepository::isPlatformPackage($req)) { return false; @@ -68,7 +68,7 @@ final class IgnoreListPlatformRequirementFilter implements PlatformRequirementFi * @param string $req * @return ConstraintInterface */ - public function filterConstraint($req, ConstraintInterface $constraint) + public function filterConstraint($req, ConstraintInterface $constraint): ConstraintInterface { if (!PlatformRepository::isPlatformPackage($req)) { return $constraint; diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php index 7c4bddbab..2262326c3 100644 --- a/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php @@ -18,7 +18,7 @@ final class IgnoreNothingPlatformRequirementFilter implements PlatformRequiremen * @param string $req * @return false */ - public function isIgnored($req) + public function isIgnored($req): bool { return false; } diff --git a/src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php b/src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php index ac8a83cd7..302bdd915 100644 --- a/src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php +++ b/src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php @@ -19,7 +19,7 @@ final class PlatformRequirementFilterFactory * * @return PlatformRequirementFilterInterface */ - public static function fromBoolOrList($boolOrList) + public static function fromBoolOrList($boolOrList): PlatformRequirementFilterInterface { if (is_bool($boolOrList)) { return $boolOrList ? self::ignoreAll() : self::ignoreNothing(); @@ -40,7 +40,7 @@ final class PlatformRequirementFilterFactory /** * @return PlatformRequirementFilterInterface */ - public static function ignoreAll() + public static function ignoreAll(): PlatformRequirementFilterInterface { return new IgnoreAllPlatformRequirementFilter(); } @@ -48,7 +48,7 @@ final class PlatformRequirementFilterFactory /** * @return PlatformRequirementFilterInterface */ - public static function ignoreNothing() + public static function ignoreNothing(): PlatformRequirementFilterInterface { return new IgnoreNothingPlatformRequirementFilter(); } diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 63337ec93..b4e19846f 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -157,7 +157,7 @@ class ConsoleIO extends BaseIO * * @return void */ - private function doWrite($messages, $newline, $stderr, $verbosity, $raw = false) + private function doWrite($messages, $newline, $stderr, $verbosity, $raw = false): void { $sfVerbosity = $this->verbosityMap[$verbosity]; if ($sfVerbosity > $this->output->getVerbosity()) { @@ -216,7 +216,7 @@ class ConsoleIO extends BaseIO * * @return void */ - private function doOverwrite($messages, $newline, $size, $stderr, $verbosity) + private function doOverwrite($messages, $newline, $size, $stderr, $verbosity): void { // messages can be an array, let's convert it to string anyway $messages = implode($newline ? "\n" : '', (array) $messages); @@ -345,7 +345,7 @@ class ConsoleIO extends BaseIO /** * @return OutputInterface */ - private function getErrorOutput() + private function getErrorOutput(): OutputInterface { if ($this->output instanceof ConsoleOutputInterface) { return $this->output->getErrorOutput(); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 43af3fde5..8e397d603 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -789,7 +789,7 @@ class Installer * * @phpstan-param list $rootAliases */ - private function createRepositorySet($forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null) + private function createRepositorySet($forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null): RepositorySet { if ($forUpdate) { $minimumStability = $this->package->getMinimumStability(); @@ -858,7 +858,7 @@ class Installer * * @return DefaultPolicy */ - private function createPolicy($forUpdate) + private function createPolicy($forUpdate): DefaultPolicy { $preferStable = null; $preferLowest = null; @@ -882,7 +882,7 @@ class Installer * @param RootPackageInterface&BasePackage $rootPackage * @return Request */ - private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, LockArrayRepository $lockedRepository = null) + private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, LockArrayRepository $lockedRepository = null): Request { $request = new Request($lockedRepository); @@ -953,7 +953,7 @@ class Installer * * @phpstan-return list */ - private function getRootAliases($forUpdate) + private function getRootAliases($forUpdate): array { if ($forUpdate) { $aliases = $this->package->getAliases(); @@ -969,7 +969,7 @@ class Installer * * @return array */ - private function extractPlatformRequirements(array $links) + private function extractPlatformRequirements(array $links): array { $platformReqs = array(); foreach ($links as $link) { @@ -1009,7 +1009,7 @@ class Installer /** * @return PoolOptimizer|null */ - private function createPoolOptimizer(PolicyInterface $policy) + private function createPoolOptimizer(PolicyInterface $policy): ?PoolOptimizer { // Not the best architectural decision here, would need to be able // to configure from the outside of Installer but this is only diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 71aa3d986..cb3aafbd8 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -316,7 +316,7 @@ class InstallationManager * * @return void */ - private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, $devMode, $runScripts, array $allOperations) + private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, $devMode, $runScripts, array $allOperations): void { $promises = array(); @@ -400,7 +400,7 @@ class InstallationManager * * @return void */ - private function executeBatch(InstalledRepositoryInterface $repo, array $operations, array $cleanupPromises, $devMode, $runScripts, array $allOperations) + private function executeBatch(InstalledRepositoryInterface $repo, array $operations, array $cleanupPromises, $devMode, $runScripts, array $allOperations): void { $promises = array(); $postExecCallbacks = array(); @@ -481,7 +481,7 @@ class InstallationManager * * @return void */ - private function waitOnPromises(array $promises) + private function waitOnPromises(array $promises): void { $progress = null; if ( @@ -700,7 +700,7 @@ class InstallationManager /** * @return void */ - private function markForNotification(PackageInterface $package) + private function markForNotification(PackageInterface $package): void { if ($package->getNotificationUrl()) { $this->notifiablePackages[$package->getNotificationUrl()][$package->getName()] = $package; diff --git a/src/Composer/Installer/SuggestedPackagesReporter.php b/src/Composer/Installer/SuggestedPackagesReporter.php index 840e63f51..15e86b6d2 100644 --- a/src/Composer/Installer/SuggestedPackagesReporter.php +++ b/src/Composer/Installer/SuggestedPackagesReporter.php @@ -183,7 +183,7 @@ class SuggestedPackagesReporter * @param PackageInterface|null $onlyDependentsOf If passed in, only the suggestions from direct dependents of that package, or from the package itself, will be shown * @return mixed[] */ - private function getFilteredSuggestions(InstalledRepository $installedRepo = null, PackageInterface $onlyDependentsOf = null) + private function getFilteredSuggestions(InstalledRepository $installedRepo = null, PackageInterface $onlyDependentsOf = null): array { $suggestedPackages = $this->getPackages(); $installedNames = array(); @@ -220,7 +220,7 @@ class SuggestedPackagesReporter * @param string $string * @return string */ - private function escapeOutput($string) + private function escapeOutput($string): string { return OutputFormatter::escape( $this->removeControlCharacters($string) @@ -231,7 +231,7 @@ class SuggestedPackagesReporter * @param string $string * @return string */ - private function removeControlCharacters($string) + private function removeControlCharacters($string): string { return Preg::replace( '/[[:cntrl:]]/', diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 35661c925..aa81fb61a 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -256,7 +256,7 @@ class JsonFile * @throws \RuntimeException * @return void */ - private static function throwEncodeError($code) + private static function throwEncodeError($code): void { switch ($code) { case JSON_ERROR_DEPTH: diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 1e51f4dcc..60cbef0c1 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -133,7 +133,7 @@ class JsonManipulator * @param array $packages * @return void */ - private function sortPackages(array &$packages = array()) + private function sortPackages(array &$packages = array()): void { $prefix = function ($requirement) { if (PlatformRepository::isPlatformPackage($requirement)) { diff --git a/src/Composer/Package/Archiver/ZipArchiver.php b/src/Composer/Package/Archiver/ZipArchiver.php index 4e83a2f4d..036e353a8 100644 --- a/src/Composer/Package/Archiver/ZipArchiver.php +++ b/src/Composer/Package/Archiver/ZipArchiver.php @@ -86,7 +86,7 @@ class ZipArchiver implements ArchiverInterface /** * @return bool */ - private function compressionAvailable() + private function compressionAvailable(): bool { return class_exists('ZipArchive'); } diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 9b6e40946..31655d73b 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -148,7 +148,7 @@ class ArrayDumper * * @return array */ - private function dumpValues(PackageInterface $package, array $keys, array $data) + private function dumpValues(PackageInterface $package, array $keys, array $data): array { foreach ($keys as $method => $key) { if (is_numeric($method)) { diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 403da9a45..16cede400 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -321,7 +321,7 @@ class ArrayLoader implements LoaderInterface * * @return void */ - private function configureCachedLinks(&$linkCache, $package, array $config) + private function configureCachedLinks(&$linkCache, $package, array $config): void { $name = $package->getName(); $prettyVersion = $package->getPrettyVersion(); @@ -385,7 +385,7 @@ class ArrayLoader implements LoaderInterface * @param string $prettyConstraint constraint string * @return Link */ - private function createLink($source, $sourceVersion, $description, $target, $prettyConstraint) + private function createLink($source, $sourceVersion, $description, $target, $prettyConstraint): Link { if (!\is_string($prettyConstraint)) { throw new \UnexpectedValueException('Link constraint in '.$source.' '.$description.' > '.$target.' should be a string, got '.\gettype($prettyConstraint) . ' (' . var_export($prettyConstraint, true) . ')'); diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index cd061941c..9c0c47c8f 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -194,7 +194,7 @@ class RootPackageLoader extends ArrayLoader * * @return list */ - private function extractAliases(array $requires, array $aliases) + private function extractAliases(array $requires, array $aliases): array { foreach ($requires as $reqName => $reqVersion) { if (Preg::isMatch('{^([^,\s#]+)(?:#[^ ]+)? +as +([^,\s]+)$}', $reqVersion, $match)) { @@ -224,7 +224,7 @@ class RootPackageLoader extends ArrayLoader * @phpstan-param array $stabilityFlags * @phpstan-return array */ - public static function extractStabilityFlags(array $requires, $minimumStability, array $stabilityFlags) + public static function extractStabilityFlags(array $requires, $minimumStability, array $stabilityFlags): array { $stabilities = BasePackage::$stabilities; /** @var int $minimumStability */ @@ -286,7 +286,7 @@ class RootPackageLoader extends ArrayLoader * * @return array */ - public static function extractReferences(array $requires, array $references) + public static function extractReferences(array $requires, array $references): array { foreach ($requires as $reqName => $reqVersion) { $reqVersion = Preg::replace('{^([^,\s@]+) as .+$}', '$1', $reqVersion); diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 7fb2c3b79..662f84861 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -494,7 +494,7 @@ class ValidatingArrayLoader implements LoaderInterface * @phpstan-param non-empty-string $property * @phpstan-param non-empty-string $regex */ - private function validateRegex($property, $regex, $mandatory = false) + private function validateRegex($property, $regex, $mandatory = false): bool { if (!$this->validateString($property, $mandatory)) { return false; @@ -523,7 +523,7 @@ class ValidatingArrayLoader implements LoaderInterface * * @phpstan-param non-empty-string $property */ - private function validateString($property, $mandatory = false) + private function validateString($property, $mandatory = false): bool { if (isset($this->config[$property]) && !is_string($this->config[$property])) { $this->errors[] = $property.' : should be a string, '.gettype($this->config[$property]).' given'; @@ -552,7 +552,7 @@ class ValidatingArrayLoader implements LoaderInterface * * @phpstan-param non-empty-string $property */ - private function validateArray($property, $mandatory = false) + private function validateArray($property, $mandatory = false): bool { if (isset($this->config[$property]) && !is_array($this->config[$property])) { $this->errors[] = $property.' : should be an array, '.gettype($this->config[$property]).' given'; @@ -583,7 +583,7 @@ class ValidatingArrayLoader implements LoaderInterface * @phpstan-param non-empty-string $property * @phpstan-param non-empty-string|null $regex */ - private function validateFlatArray($property, $regex = null, $mandatory = false) + private function validateFlatArray($property, $regex = null, $mandatory = false): bool { if (!$this->validateArray($property, $mandatory)) { return false; @@ -617,7 +617,7 @@ class ValidatingArrayLoader implements LoaderInterface * * @phpstan-param non-empty-string $property */ - private function validateUrl($property, $mandatory = false) + private function validateUrl($property, $mandatory = false): bool { if (!$this->validateString($property, $mandatory)) { return false; @@ -639,7 +639,7 @@ class ValidatingArrayLoader implements LoaderInterface * * @return bool */ - private function filterUrl($value, array $schemes = array('http', 'https')) + private function filterUrl($value, array $schemes = array('http', 'https')): bool { if ($value === '') { return true; diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 5a306d14d..be9466ea3 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -419,7 +419,7 @@ class Locker * * @phpstan-return list> */ - private function lockPackages(array $packages) + private function lockPackages(array $packages): array { $locked = array(); @@ -477,7 +477,7 @@ class Locker * @param PackageInterface $package The package to scan. * @return string|null The formatted datetime or null if none was found. */ - private function getPackageTime(PackageInterface $package) + private function getPackageTime(PackageInterface $package): ?string { if (!function_exists('proc_open')) { return null; diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index a0be96f3d..7549c4008 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -788,7 +788,7 @@ class Package extends BasePackage * @param string $source * @return array */ - private function convertLinksToMap(array $links, $source) + private function convertLinksToMap(array $links, $source): array { trigger_error('Package::'.$source.' must be called with a map of lowercased package name => Link object, got a indexed array, this is deprecated and you should fix your usage.'); $newLinks = array(); diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 7927fa726..d10c02951 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -103,7 +103,7 @@ class VersionGuesser * @return array * @phpstan-return Version */ - private function postprocess(array $versionData) + private function postprocess(array $versionData): array { if (!empty($versionData['feature_version']) && $versionData['feature_version'] === $versionData['version'] && $versionData['feature_pretty_version'] === $versionData['pretty_version']) { unset($versionData['feature_version'], $versionData['feature_pretty_version']); @@ -126,7 +126,7 @@ class VersionGuesser * * @return array{version: string|null, commit: string|null, pretty_version: string|null, feature_version?: string|null, feature_pretty_version?: string|null} */ - private function guessGitVersion(array $packageConfig, $path) + private function guessGitVersion(array $packageConfig, $path): array { GitUtil::cleanEnv(); $commit = null; @@ -211,7 +211,7 @@ class VersionGuesser * * @return array{version: string, pretty_version: string}|null */ - private function versionFromGitTags($path) + private function versionFromGitTags($path): ?array { // try to fetch current version from git tags if (0 === $this->process->execute('git describe --exact-match --tags', $output, $path)) { @@ -232,7 +232,7 @@ class VersionGuesser * * @return array{version: string|null, commit: ''|null, pretty_version: string|null, feature_version?: string|null, feature_pretty_version?: string|null}|null */ - private function guessHgVersion(array $packageConfig, $path) + private function guessHgVersion(array $packageConfig, $path): ?array { // try to fetch current version from hg branch if (0 === $this->process->execute('hg branch', $output, $path)) { @@ -276,7 +276,7 @@ class VersionGuesser * * @return array{version: string|null, pretty_version: string|null} */ - private function guessFeatureVersion(array $packageConfig, $version, array $branches, $scmCmdline, $path) + private function guessFeatureVersion(array $packageConfig, $version, array $branches, $scmCmdline, $path): array { $prettyVersion = $version; @@ -340,7 +340,7 @@ class VersionGuesser * * @return bool */ - private function isFeatureBranch(array $packageConfig, $branchName) + private function isFeatureBranch(array $packageConfig, $branchName): bool { $nonFeatureBranches = ''; if (!empty($packageConfig['non-feature-branches'])) { @@ -355,7 +355,7 @@ class VersionGuesser * * @return array{version: string|null, commit: '', pretty_version: string|null} */ - private function guessFossilVersion($path) + private function guessFossilVersion($path): array { $version = null; $prettyVersion = null; @@ -385,7 +385,7 @@ class VersionGuesser * * @return array{version: string, commit: '', pretty_version: string}|null */ - private function guessSvnVersion(array $packageConfig, $path) + private function guessSvnVersion(array $packageConfig, $path): ?array { SvnUtil::cleanEnv(); diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 8e4b45faa..a1a6e57df 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -211,7 +211,7 @@ class VersionSelector * * @return string */ - private function transformVersion($version, $prettyVersion, $stability) + private function transformVersion($version, $prettyVersion, $stability): string { // attempt to transform 2.1.1 to 2.1 // this allows you to upgrade through minor versions @@ -242,7 +242,7 @@ class VersionSelector /** * @return VersionParser */ - private function getParser() + private function getParser(): VersionParser { if ($this->parser === null) { $this->parser = new VersionParser(); diff --git a/src/Composer/Platform/Version.php b/src/Composer/Platform/Version.php index 6c9cd8fa5..7f957ae5c 100644 --- a/src/Composer/Platform/Version.php +++ b/src/Composer/Platform/Version.php @@ -71,7 +71,7 @@ class Version * @param string $alpha * @return int */ - private static function convertAlphaVersionToIntVersion($alpha) + private static function convertAlphaVersionToIntVersion($alpha): int { return strlen($alpha) * (-ord('a') + 1) + array_sum(array_map('ord', str_split($alpha))); } @@ -100,7 +100,7 @@ class Version * * @return string */ - private static function convertVersionId($versionId, $base) + private static function convertVersionId($versionId, $base): string { return sprintf( '%d.%d.%d', diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 5f3390ef7..f6fa3cd73 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -530,7 +530,7 @@ class PluginManager * * @return array Map of package names to packages */ - private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package) + private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package): array { foreach ($package->getRequires() as $requireLink) { foreach ($installedRepo->findPackagesWithReplacersAndProviders($requireLink->getTarget()) as $requiredPackage) { @@ -552,7 +552,7 @@ class PluginManager * * @return string Install path */ - private function getInstallPath(PackageInterface $package, $global = false) + private function getInstallPath(PackageInterface $package, $global = false): string { if (!$global) { return $this->composer->getInstallationManager()->getInstallPath($package); @@ -647,7 +647,7 @@ class PluginManager * @param array|bool|null $allowPluginsConfig * @return array|null */ - private function parseAllowedPlugins($allowPluginsConfig) + private function parseAllowedPlugins($allowPluginsConfig): ?array { if (null === $allowPluginsConfig) { return null; @@ -674,7 +674,7 @@ class PluginManager * @param bool $isGlobalPlugin * @return bool */ - private function isPluginAllowed($package, $isGlobalPlugin) + private function isPluginAllowed($package, $isGlobalPlugin): bool { static $warned = array(); $rules = $isGlobalPlugin ? $this->allowGlobalPluginRules : $this->allowPluginRules; diff --git a/src/Composer/Question/StrictConfirmationQuestion.php b/src/Composer/Question/StrictConfirmationQuestion.php index 301bb91b0..5ec5577c1 100644 --- a/src/Composer/Question/StrictConfirmationQuestion.php +++ b/src/Composer/Question/StrictConfirmationQuestion.php @@ -53,7 +53,7 @@ class StrictConfirmationQuestion extends Question * * @return callable */ - private function getDefaultNormalizer() + private function getDefaultNormalizer(): callable { $default = $this->getDefault(); $trueRegex = $this->trueAnswerRegex; @@ -84,7 +84,7 @@ class StrictConfirmationQuestion extends Question * * @return callable */ - private function getDefaultValidator() + private function getDefaultValidator(): callable { return function ($answer) { if (!is_bool($answer)) { diff --git a/src/Composer/Repository/ArtifactRepository.php b/src/Composer/Repository/ArtifactRepository.php index e8140162c..7db28bcab 100644 --- a/src/Composer/Repository/ArtifactRepository.php +++ b/src/Composer/Repository/ArtifactRepository.php @@ -73,7 +73,7 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito * * @return void */ - private function scanDirectory($path) + private function scanDirectory($path): void { $io = $this->io; @@ -102,7 +102,7 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito /** * @return ?BasePackage */ - private function getComposerInformation(\SplFileInfo $file) + private function getComposerInformation(\SplFileInfo $file): ?BasePackage { $json = null; $fileType = null; diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 8fa6bf03b..a5a99f9f5 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -39,6 +39,7 @@ use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Util\Http\Response; use Composer\MetadataMinifier\MetadataMinifier; use Composer\Util\Url; +use React\Promise\PromiseInterface; /** * @author Jordi Boggiano @@ -399,7 +400,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return list */ - private function getVendorNames() + private function getVendorNames(): array { $cacheKey = 'vendor-list.txt'; $cacheAge = $this->cache->getAge($cacheKey); @@ -430,7 +431,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * @param string|null $packageFilter * @return list */ - private function loadPackageList($packageFilter = null) + private function loadPackageList($packageFilter = null): array { if (null === $this->listUrl) { throw new \LogicException('Make sure to call loadRootServerFile before loadPackageList'); @@ -640,7 +641,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return string[] */ - private function getProviderNames() + private function getProviderNames(): array { $this->loadRootServerFile(); @@ -677,7 +678,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return bool */ - private function hasProviders() + private function hasProviders(): bool { $this->loadRootServerFile(); @@ -694,7 +695,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return array */ - private function whatProvides($name, array $acceptableStabilities = null, array $stabilityFlags = null, array $alreadyLoaded = array()) + private function whatProvides($name, array $acceptableStabilities = null, array $stabilityFlags = null, array $alreadyLoaded = array()): array { $packagesSource = null; if (!$this->hasPartialPackages() || !isset($this->partialPackagesByName[$name])) { @@ -862,7 +863,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return array{namesFound: array, packages: array} */ - private function loadAsyncPackages(array $packageNames, array $acceptableStabilities = null, array $stabilityFlags = null, array $alreadyLoaded = array()) + private function loadAsyncPackages(array $packageNames, array $acceptableStabilities = null, array $stabilityFlags = null, array $alreadyLoaded = array()): array { $this->loadRootServerFile(); @@ -972,7 +973,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return bool */ - private function isVersionAcceptable($constraint, $name, $versionData, array $acceptableStabilities = null, array $stabilityFlags = null) + private function isVersionAcceptable($constraint, $name, $versionData, array $acceptableStabilities = null, array $stabilityFlags = null): bool { $versions = array($versionData['version_normalized']); @@ -998,7 +999,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return string */ - private function getPackagesJsonUrl() + private function getPackagesJsonUrl(): string { $jsonUrlParts = parse_url($this->url); @@ -1135,7 +1136,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return string */ - private function canonicalizeUrl($url) + private function canonicalizeUrl($url): string { if ('/' === $url[0]) { if (Preg::isMatch('{^[^:]++://[^/]*+}', $this->url, $matches)) { @@ -1151,7 +1152,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return mixed[] */ - private function loadDataFromServer() + private function loadDataFromServer(): array { $data = $this->loadRootServerFile(); @@ -1161,7 +1162,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @return bool */ - private function hasPartialPackages() + private function hasPartialPackages(): bool { if ($this->hasPartialPackages && null === $this->partialPackagesByName) { $this->initializePartialPackages(); @@ -1175,7 +1176,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return void */ - private function loadProviderListings($data) + private function loadProviderListings($data): void { if (isset($data['providers'])) { if (!is_array($this->providerListing)) { @@ -1205,7 +1206,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return mixed[] */ - private function loadIncludes($data) + private function loadIncludes($data): array { $packages = array(); @@ -1250,7 +1251,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return list */ - private function createPackages(array $packages, $source = null) + private function createPackages(array $packages, $source = null): array { if (!$packages) { return array(); @@ -1457,10 +1458,8 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * @param string $filename * @param string $cacheKey * @param string|null $lastModifiedTime - * - * @return \React\Promise\PromiseInterface */ - private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null) + private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null): PromiseInterface { if (isset($this->packagesNotFoundCache[$filename])) { return \React\Promise\resolve(array('packages' => array())); @@ -1566,7 +1565,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito * * @return void */ - private function initializePartialPackages() + private function initializePartialPackages(): void { $rootData = $this->loadRootServerFile(); diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index 6138514fc..a6e949445 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -173,7 +173,7 @@ class FilesystemRepository extends WritableArrayRepository * * @return string */ - private function dumpToPhpCode(array $array = array(), $level = 0) + private function dumpToPhpCode(array $array = array(), $level = 0): string { $lines = "array(\n"; $level++; @@ -211,7 +211,7 @@ class FilesystemRepository extends WritableArrayRepository * * @return ?array */ - private function generateInstalledVersions(InstallationManager $installationManager, array $installPaths, $devMode, $repoDir) + private function generateInstalledVersions(InstallationManager $installationManager, array $installPaths, $devMode, $repoDir): ?array { if (!$this->dumpVersions) { return null; diff --git a/src/Composer/Repository/FilterRepository.php b/src/Composer/Repository/FilterRepository.php index 078f66f8f..72b041582 100644 --- a/src/Composer/Repository/FilterRepository.php +++ b/src/Composer/Repository/FilterRepository.php @@ -195,7 +195,7 @@ class FilterRepository implements RepositoryInterface * * @return bool */ - private function isAllowed($name) + private function isAllowed($name): bool { if (!$this->only && !$this->exclude) { return true; diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index bc86a9201..8a262c858 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -240,7 +240,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn * * @return string[] */ - private function getUrlMatches() + private function getUrlMatches(): array { $flags = GLOB_MARK | GLOB_ONLYDIR; diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index c1495f64d..e43fd3c93 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -586,7 +586,7 @@ class PlatformRepository extends ArrayRepository * * @return CompletePackage */ - private function addOverriddenPackage(array $override, $name = null) + private function addOverriddenPackage(array $override, $name = null): CompletePackage { $version = $this->versionParser->normalize($override['version']); $package = new CompletePackage($name ?: $override['name'], $version, $override['version']); @@ -653,7 +653,7 @@ class PlatformRepository extends ArrayRepository * @param string $name * @return string */ - private function buildPackageName($name) + private function buildPackageName($name): string { return 'ext-' . str_replace(' ', '-', strtolower($name)); } @@ -725,7 +725,7 @@ class PlatformRepository extends ArrayRepository * @internal * @return string|null */ - public static function getPlatformPhpVersion() + public static function getPlatformPhpVersion(): ?string { return self::$lastSeenPlatformPhp; } diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index 5891d0f7a..09568a18a 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -145,7 +145,7 @@ class RepositoryFactory * * @return RepositoryInterface[] */ - private static function createRepos(RepositoryManager $rm, array $repoConfigs) + private static function createRepos(RepositoryManager $rm, array $repoConfigs): array { $repos = array(); diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index 18b988b46..beb237edc 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -336,7 +336,7 @@ class RepositorySet * * @return array> */ - private static function getRootAliasesPerPackage(array $aliases) + private static function getRootAliasesPerPackage(array $aliases): array { $normalizedAliases = array(); diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 795f29e14..6d2e99e67 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -333,7 +333,7 @@ class GitLabDriver extends VcsDriver * @param string $string * @return string */ - private function urlEncodeAll($string) + private function urlEncodeAll($string): string { $encoded = ''; for ($i = 0; isset($string[$i]); $i++) { diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 75a61037c..b178257f2 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -55,7 +55,7 @@ class PerforceDriver extends VcsDriver * * @return void */ - private function initPerforce($repoConfig) + private function initPerforce($repoConfig): void { if (!empty($this->perforce)) { return; diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index b5b85cd14..11d8df0e9 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -542,7 +542,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt /** * @return bool */ - private function shouldRethrowTransportException(TransportException $e) + private function shouldRethrowTransportException(TransportException $e): bool { return in_array($e->getCode(), array(401, 403, 429), true) || $e->getCode() >= 500; } diff --git a/src/Composer/Script/Event.php b/src/Composer/Script/Event.php index 83aef267a..3ddf2eae0 100644 --- a/src/Composer/Script/Event.php +++ b/src/Composer/Script/Event.php @@ -121,7 +121,7 @@ class Event extends BaseEvent * @param BaseEvent $event * @return BaseEvent */ - private function calculateOriginatingEvent(BaseEvent $event) + private function calculateOriginatingEvent(BaseEvent $event): BaseEvent { if ($event instanceof Event && $event->getOriginatingEvent()) { return $this->calculateOriginatingEvent($event->getOriginatingEvent()); diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index b6ba9c48f..2197e855a 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -95,7 +95,7 @@ class Versions /** * @return array> */ - private function getVersionsData() + private function getVersionsData(): array { if (!$this->versionsData) { if ($this->config->get('disable-tls') === true) { diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index e0104a64b..abbb8cd45 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -92,7 +92,7 @@ class Bitbucket /** * @return bool */ - private function requestAccessToken() + private function requestAccessToken(): bool { try { $response = $this->httpDownloader->get(self::OAUTH2_ACCESS_TOKEN_URL, array( @@ -246,7 +246,7 @@ class Bitbucket * @param string $originUrl * @return bool */ - private function getTokenFromConfig($originUrl) + private function getTokenFromConfig($originUrl): bool { $authConfig = $this->config->get('bitbucket-oauth'); diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 3bd1c86fa..99aa803c9 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -177,7 +177,7 @@ class Filesystem * * @return bool|null Returns null, when no edge case was hit. Otherwise a bool whether removal was successful */ - private function removeEdgeCases($directory, $fallbackToPhp = true) + private function removeEdgeCases($directory, $fallbackToPhp = true): ?bool { if ($this->isSymlinkedDirectory($directory)) { return $this->unlinkSymlinkedDirectory($directory); @@ -711,7 +711,7 @@ class Filesystem * * @return bool */ - private function unlinkImplementation($path) + private function unlinkImplementation($path): bool { if (Platform::isWindows() && is_dir($path) && is_link($path)) { return rmdir($path); @@ -767,7 +767,7 @@ class Filesystem * * @return bool */ - private function unlinkSymlinkedDirectory($directory) + private function unlinkSymlinkedDirectory($directory): bool { $resolved = $this->resolveSymlinkedDirectorySymlink($directory); @@ -781,7 +781,7 @@ class Filesystem * * @return string resolved path to symbolic link or original pathname (unresolved) */ - private function resolveSymlinkedDirectorySymlink($pathname) + private function resolveSymlinkedDirectorySymlink($pathname): string { if (!is_dir($pathname)) { return $pathname; @@ -926,7 +926,7 @@ class Filesystem * * @return bool */ - private function filesAreEqual($a, $b) + private function filesAreEqual($a, $b): bool { // Check if filesize is different if (filesize($a) !== filesize($b)) { diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index f2ea4dc24..4b92c2f77 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -349,7 +349,7 @@ class Git * * @return bool */ - private function checkRefIsInMirror($dir, $ref) + private function checkRefIsInMirror($dir, $ref): bool { if (is_dir($dir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $dir) && trim($output) === '.') { $escapedRef = ProcessExecutor::escape($ref.'^{commit}'); @@ -368,7 +368,7 @@ class Git * * @return bool */ - private function isAuthenticationFailure($url, &$match) + private function isAuthenticationFailure($url, &$match): bool { if (!Preg::isMatch('{^(https?://)([^/]+)(.*)$}i', $url, $match)) { return false; @@ -441,7 +441,7 @@ class Git * * @return never */ - private function throwException($message, $url) + private function throwException($message, $url): void { // git might delete a directory when it fails and php will not know clearstatcache(); @@ -476,7 +476,7 @@ class Git * * @return string */ - private function maskCredentials($error, array $credentials) + private function maskCredentials($error, array $credentials): string { $maskedCredentials = array(); diff --git a/src/Composer/Util/GitLab.php b/src/Composer/Util/GitLab.php index 4c1376ad4..86800dc33 100644 --- a/src/Composer/Util/GitLab.php +++ b/src/Composer/Util/GitLab.php @@ -169,7 +169,7 @@ class GitLab * * @see https://docs.gitlab.com/ee/api/oauth2.html#resource-owner-password-credentials-flow */ - private function createToken($scheme, $originUrl) + private function createToken($scheme, $originUrl): array { $username = $this->io->ask('Username: '); $password = $this->io->askAndHideAnswer('Password: '); diff --git a/src/Composer/Util/Hg.php b/src/Composer/Util/Hg.php index 34dc00623..aa82bb323 100644 --- a/src/Composer/Util/Hg.php +++ b/src/Composer/Util/Hg.php @@ -89,7 +89,7 @@ class Hg * * @return never */ - private function throwException($message, $url) + private function throwException($message, $url): void { if (null === self::getVersion($this->process)) { throw new \RuntimeException(Url::sanitize('Failed to clone ' . $url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput())); diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index 8ae18ee4c..eeff04e1f 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -133,7 +133,7 @@ class CurlDownloader * * @return int internal job id */ - public function download($resolve, $reject, $origin, $url, $options, $copyTo = null) + public function download($resolve, $reject, $origin, $url, $options, $copyTo = null): int { $attributes = array(); if (isset($options['retry-auth-failure'])) { @@ -156,7 +156,7 @@ class CurlDownloader * * @return int internal job id */ - private function initDownload($resolve, $reject, $origin, $url, $options, $copyTo = null, array $attributes = array()) + private function initDownload($resolve, $reject, $origin, $url, $options, $copyTo = null, array $attributes = array()): int { // set defaults in a PHPStan-happy way (array_merge is not well supported) $attributes['retryAuthFailure'] = $attributes['retryAuthFailure'] ?? true; @@ -489,7 +489,7 @@ class CurlDownloader * @param Job $job * @return string */ - private function handleRedirect(array $job, Response $response) + private function handleRedirect(array $job, Response $response): string { if ($locationHeader = $response->getHeader('location')) { if (parse_url($locationHeader, PHP_URL_SCHEME)) { @@ -524,7 +524,7 @@ class CurlDownloader * @param Job $job * @return array{retry: bool, storeAuth: string|bool} */ - private function isAuthenticatedRetryNeeded(array $job, Response $response) + private function isAuthenticatedRetryNeeded(array $job, Response $response): array { if (in_array($response->getStatusCode(), array(401, 403)) && $job['attributes']['retryAuthFailure']) { $result = $this->authHelper->promptAuthIfNeeded($job['url'], $job['origin'], $response->getStatusCode(), $response->getStatusMessage(), $response->getHeaders()); @@ -596,7 +596,7 @@ class CurlDownloader * @param string $errorMessage * @return TransportException */ - private function failResponse(array $job, Response $response, $errorMessage) + private function failResponse(array $job, Response $response, $errorMessage): TransportException { if (null !== $job['filename']) { @unlink($job['filename'].'~'); diff --git a/src/Composer/Util/Http/ProxyHelper.php b/src/Composer/Util/Http/ProxyHelper.php index bfdfe2e4a..db19db62d 100644 --- a/src/Composer/Util/Http/ProxyHelper.php +++ b/src/Composer/Util/Http/ProxyHelper.php @@ -27,7 +27,7 @@ class ProxyHelper * * @throws \RuntimeException on malformed url */ - public static function getProxyData() + public static function getProxyData(): array { $httpProxy = null; $httpsProxy = null; @@ -64,7 +64,7 @@ class ProxyHelper * * @return array{http: array{proxy: string, header?: string}} */ - public static function getContextOptions($proxyUrl) + public static function getContextOptions($proxyUrl): array { $proxy = parse_url($proxyUrl); @@ -114,7 +114,7 @@ class ProxyHelper * * @return string|null The found value */ - private static function getProxyEnv(array $names, &$name) + private static function getProxyEnv(array $names, &$name): ?string { foreach ($names as $name) { if (!empty($_SERVER[$name])) { @@ -133,7 +133,7 @@ class ProxyHelper * @throws \RuntimeException on malformed url * @return string The formatted proxy url */ - private static function checkProxy($proxyUrl, $envName) + private static function checkProxy($proxyUrl, $envName): string { $error = sprintf('malformed %s url', $envName); $proxy = parse_url($proxyUrl); @@ -161,7 +161,7 @@ class ProxyHelper * * @return string The formatted value */ - private static function formatParsedUrl(array $proxy, $includeAuth) + private static function formatParsedUrl(array $proxy, $includeAuth): string { $proxyUrl = isset($proxy['scheme']) ? strtolower($proxy['scheme']) . '://' : ''; diff --git a/src/Composer/Util/Http/ProxyManager.php b/src/Composer/Util/Http/ProxyManager.php index 43bcea749..5f11c8242 100644 --- a/src/Composer/Util/Http/ProxyManager.php +++ b/src/Composer/Util/Http/ProxyManager.php @@ -58,7 +58,7 @@ class ProxyManager /** * @return ProxyManager */ - public static function getInstance() + public static function getInstance(): ProxyManager { if (!self::$instance) { self::$instance = new self(); @@ -83,7 +83,7 @@ class ProxyManager * @param string $requestUrl * @return RequestProxy */ - public function getProxyForRequest($requestUrl) + public function getProxyForRequest($requestUrl): RequestProxy { if ($this->error) { throw new TransportException('Unable to use a proxy: '.$this->error); @@ -113,7 +113,7 @@ class ProxyManager * * @return bool If false any error will be in $message */ - public function isProxying() + public function isProxying(): bool { return $this->hasProxy; } @@ -123,7 +123,7 @@ class ProxyManager * * @return string|null Safe proxy URL or an error message if setting up proxy failed or null if no proxy was configured */ - public function getFormattedProxy() + public function getFormattedProxy(): ?string { return $this->hasProxy ? $this->info : $this->error; } @@ -167,7 +167,7 @@ class ProxyManager * * @return non-empty-string */ - private function setData($url, $scheme) + private function setData($url, $scheme): string { $safeProxy = Url::sanitize($url); $this->fullProxy[$scheme] = $url; @@ -184,7 +184,7 @@ class ProxyManager * @param string $requestUrl * @return bool */ - private function noProxy($requestUrl) + private function noProxy($requestUrl): bool { return $this->noProxyHandler && $this->noProxyHandler->test($requestUrl); } diff --git a/src/Composer/Util/Http/RequestProxy.php b/src/Composer/Util/Http/RequestProxy.php index 5a832706f..e60c1a19c 100644 --- a/src/Composer/Util/Http/RequestProxy.php +++ b/src/Composer/Util/Http/RequestProxy.php @@ -47,7 +47,7 @@ class RequestProxy * * @return mixed[] */ - public function getContextOptions() + public function getContextOptions(): array { return $this->contextOptions; } @@ -58,7 +58,7 @@ class RequestProxy * @param string|null $format Output format specifier * @return string Safe proxy, no proxy or empty */ - public function getFormattedUrl($format = '') + public function getFormattedUrl($format = ''): string { $result = ''; if ($this->formattedUrl) { @@ -74,7 +74,7 @@ class RequestProxy * * @return string Proxy url or empty */ - public function getUrl() + public function getUrl(): string { return $this->url; } @@ -84,7 +84,7 @@ class RequestProxy * * @return bool False if not secure or there is no proxy */ - public function isSecure() + public function isSecure(): bool { return $this->isSecure; } diff --git a/src/Composer/Util/HttpDownloader.php b/src/Composer/Util/HttpDownloader.php index d1c8c1fbd..dcebffa4b 100644 --- a/src/Composer/Util/HttpDownloader.php +++ b/src/Composer/Util/HttpDownloader.php @@ -191,7 +191,7 @@ class HttpDownloader * * @return array{Job, PromiseInterface} */ - private function addJob($request, $sync = false) + private function addJob($request, $sync = false): array { $request['options'] = array_replace_recursive($this->options, $request['options']); @@ -291,7 +291,7 @@ class HttpDownloader * @param int $id * @return void */ - private function startJob($id) + private function startJob($id): void { $job = &$this->jobs[$id]; if ($job['status'] !== self::STATUS_QUEUED) { @@ -355,7 +355,7 @@ class HttpDownloader * * @return void */ - public function enableAsync() + public function enableAsync(): void { $this->allowAsync = true; } @@ -366,7 +366,7 @@ class HttpDownloader * @param int|null $index For internal use only, the job id * @return int number of active (queued or started) jobs */ - public function countActiveJobs($index = null) + public function countActiveJobs($index = null): int { if ($this->runningJobs < $this->maxJobs) { foreach ($this->jobs as $job) { @@ -400,7 +400,7 @@ class HttpDownloader * @param int $index Job id * @return Response */ - private function getResponse($index) + private function getResponse($index): Response { if (!isset($this->jobs[$index])) { throw new \LogicException('Invalid request id'); @@ -428,7 +428,7 @@ class HttpDownloader * @param array{warning?: string, info?: string, warning-versions?: string, info-versions?: string, warnings?: array, infos?: array} $data * @return void */ - public static function outputWarnings(IOInterface $io, $url, $data) + public static function outputWarnings(IOInterface $io, $url, $data): void { // legacy warning/info keys foreach (array('warning', 'info') as $type) { @@ -473,7 +473,7 @@ class HttpDownloader * * @return ?string[] */ - public static function getExceptionHints(\Exception $e) + public static function getExceptionHints(\Exception $e): ?array { if (!$e instanceof TransportException) { return null; @@ -507,7 +507,7 @@ class HttpDownloader * @param Job $job * @return bool */ - private function canUseCurl(array $job) + private function canUseCurl(array $job): bool { if (!$this->curl) { return false; @@ -528,7 +528,7 @@ class HttpDownloader * @internal * @return bool */ - public static function isCurlEnabled() + public static function isCurlEnabled(): bool { return \extension_loaded('curl') && \function_exists('curl_multi_exec') && \function_exists('curl_multi_init'); } diff --git a/src/Composer/Util/NoProxyPattern.php b/src/Composer/Util/NoProxyPattern.php index e8f14997b..20bddfe4a 100644 --- a/src/Composer/Util/NoProxyPattern.php +++ b/src/Composer/Util/NoProxyPattern.php @@ -186,7 +186,7 @@ class NoProxyPattern * * @return null|stdClass Null if the hostname is invalid */ - private function getRule($index, $hostName) + private function getRule($index, $hostName): ?stdClass { if (array_key_exists($index, $this->rules)) { return $this->rules[$index]; @@ -213,7 +213,7 @@ class NoProxyPattern * * @return bool False if the host contains invalid data */ - private function ipCheckData($host, &$ipdata, $allowPrefix = false) + private function ipCheckData($host, &$ipdata, $allowPrefix = false): bool { $ipdata = null; $netmask = null; @@ -262,7 +262,7 @@ class NoProxyPattern * * @return mixed[] in_addr, size */ - private function ipGetAddr($host) + private function ipGetAddr($host): array { $ip = inet_pton($host); $size = strlen($ip); @@ -279,7 +279,7 @@ class NoProxyPattern * * @return string */ - private function ipGetMask($prefix, $size) + private function ipGetMask($prefix, $size): string { $mask = ''; @@ -305,7 +305,7 @@ class NoProxyPattern * * @return string[] network in_addr, binary mask */ - private function ipGetNetwork($rangeIp, $size, $prefix) + private function ipGetNetwork($rangeIp, $size, $prefix): array { $netmask = $this->ipGetMask($prefix, $size); @@ -335,7 +335,7 @@ class NoProxyPattern * * @return string Mapped or existing in_addr */ - private function ipMapTo6($binary, $size) + private function ipMapTo6($binary, $size): string { if ($size === 4) { $prefix = str_repeat(chr(0), 10) . str_repeat(chr(255), 2); @@ -354,7 +354,7 @@ class NoProxyPattern * * @return stdClass */ - private function makeData($host, $port, $ipdata) + private function makeData($host, $port, $ipdata): stdClass { return (object) array( 'host' => $host, @@ -373,7 +373,7 @@ class NoProxyPattern * * @return stdClass */ - private function makeIpData($ip, $size, $netmask) + private function makeIpData($ip, $size, $netmask): stdClass { return (object) array( 'ip' => $ip, @@ -389,7 +389,7 @@ class NoProxyPattern * * @return mixed[] host, port, if there was error */ - private function splitHostPort($hostName) + private function splitHostPort($hostName): array { // host, port, err $error = array('', '', true); @@ -439,7 +439,7 @@ class NoProxyPattern * * @return bool */ - private function validateInt($int, $min, $max) + private function validateInt($int, $min, $max): bool { $options = array( 'options' => array( diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index b57b7dda8..39d5ac2cf 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -216,7 +216,7 @@ class Platform * * @return bool */ - private static function isVirtualBoxGuest() + private static function isVirtualBoxGuest(): bool { if (null === self::$isVirtualBoxGuest) { self::$isVirtualBoxGuest = false; diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index cb9cdd225..809de9810 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -100,7 +100,7 @@ class ProcessExecutor * @param mixed $output * @return int */ - private function doExecute($command, $cwd, $tty, &$output = null) + private function doExecute($command, $cwd, $tty, &$output = null): int { $this->outputCommandRun($command, $cwd, false); @@ -210,7 +210,7 @@ class ProcessExecutor * @param int $id * @return void */ - private function startJob($id) + private function startJob($id): void { $job = &$this->jobs[$id]; if ($job['status'] !== self::STATUS_QUEUED) { @@ -269,7 +269,7 @@ class ProcessExecutor * * @return void */ - public function enableAsync() + public function enableAsync(): void { $this->allowAsync = true; } @@ -280,7 +280,7 @@ class ProcessExecutor * @param ?int $index job id * @return int number of active (queued or started) jobs */ - public function countActiveJobs($index = null) + public function countActiveJobs($index = null): int { // tick foreach ($this->jobs as $job) { @@ -437,7 +437,7 @@ class ProcessExecutor * * @return string */ - private static function escapeArgument($argument) + private static function escapeArgument($argument): string { if ('' === ($argument = (string) $argument)) { return escapeshellarg($argument); diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 28982a8e9..464198f57 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -106,7 +106,7 @@ class RemoteFilesystem * * @return bool true */ - public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = array()) + public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = array()): bool { return $this->get($originUrl, $fileUrl, $options, $fileName, $progress); } @@ -131,7 +131,7 @@ class RemoteFilesystem * * @return mixed[] Options */ - public function getOptions() + public function getOptions(): array { return $this->options; } @@ -142,7 +142,7 @@ class RemoteFilesystem * @param mixed[] $options * @return void */ - public function setOptions(array $options) + public function setOptions(array $options): void { $this->options = array_replace_recursive($this->options, $options); } @@ -152,7 +152,7 @@ class RemoteFilesystem * * @return bool */ - public function isTlsDisabled() + public function isTlsDisabled(): bool { return $this->disableTls === true; } @@ -162,7 +162,7 @@ class RemoteFilesystem * * @return string[] */ - public function getLastHeaders() + public function getLastHeaders(): array { return $this->lastHeaders; } @@ -171,7 +171,7 @@ class RemoteFilesystem * @param string[] $headers array of returned headers like from getLastHeaders() * @return int|null */ - public static function findStatusCode(array $headers) + public static function findStatusCode(array $headers): ?int { $value = null; foreach ($headers as $header) { @@ -189,7 +189,7 @@ class RemoteFilesystem * @param string[] $headers array of returned headers like from getLastHeaders() * @return string|null */ - public function findStatusMessage(array $headers) + public function findStatusMessage(array $headers): ?string { $value = null; foreach ($headers as $header) { @@ -554,7 +554,7 @@ class RemoteFilesystem * * @throws TransportException */ - protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) + protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax): void { switch ($notificationCode) { case STREAM_NOTIFY_FAILURE: @@ -592,7 +592,7 @@ class RemoteFilesystem * * @return void */ - protected function promptAuthAndRetry($httpStatus, $reason = null, $headers = array()) + protected function promptAuthAndRetry($httpStatus, $reason = null, $headers = array()): void { $result = $this->authHelper->promptAuthIfNeeded($this->fileUrl, $this->originUrl, $httpStatus, $reason, $headers); @@ -610,7 +610,7 @@ class RemoteFilesystem * * @return mixed[] */ - protected function getOptionsForUrl($originUrl, $additionalOptions) + protected function getOptionsForUrl($originUrl, $additionalOptions): array { $tlsOptions = array(); $headers = array(); @@ -698,7 +698,7 @@ class RemoteFilesystem * * @return string|null */ - private function decodeResult($result, $http_response_header) + private function decodeResult($result, $http_response_header): ?string { // decode gzip if ($result && extension_loaded('zlib')) { @@ -722,7 +722,7 @@ class RemoteFilesystem * * @return string|null */ - private function normalizeResult($result) + private function normalizeResult($result): ?string { if ($result === false) { return null; diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 852d72946..f0d8bbe93 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -63,7 +63,7 @@ final class StreamContextFactory * @phpstan-return array{http: array{header: string[], proxy?: string, request_fulluri: bool}, ssl?: mixed[]} * @return array formatted as a stream context array */ - public static function initOptions($url, array $options, $forCurl = false) + public static function initOptions($url, array $options, $forCurl = false): array { // Make sure the headers are in an array form if (!isset($options['http']['header'])) { @@ -134,7 +134,7 @@ final class StreamContextFactory * * @return mixed[] */ - public static function getTlsDefaults(array $options, LoggerInterface $logger = null) + public static function getTlsDefaults(array $options, LoggerInterface $logger = null): array { $ciphers = implode(':', array( 'ECDHE-RSA-AES128-GCM-SHA256', @@ -240,7 +240,7 @@ final class StreamContextFactory * @param string|string[] $header * @return string[] */ - private static function fixHttpHeaderField($header) + private static function fixHttpHeaderField($header): array { if (!is_array($header)) { $header = explode("\r\n", $header); diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index c04f075df..8b1078a12 100644 --- a/src/Composer/Util/Svn.php +++ b/src/Composer/Util/Svn.php @@ -140,7 +140,7 @@ class Svn * * @return ?string */ - private function executeWithAuthRetry($svnCommand, $cwd, $url, $path, $verbose) + private function executeWithAuthRetry($svnCommand, $cwd, $url, $path, $verbose): ?string { // Regenerate the command at each try, to use the newly user-provided credentials $command = $this->getCommand($svnCommand, $url, $path); @@ -337,7 +337,7 @@ class Svn * * @return bool */ - private function createAuthFromConfig() + private function createAuthFromConfig(): bool { if (!$this->config->has('http-basic')) { return $this->hasAuth = false; @@ -363,7 +363,7 @@ class Svn * * @return bool */ - private function createAuthFromUrl() + private function createAuthFromUrl(): bool { $uri = parse_url($this->url); if (empty($uri['user'])) { diff --git a/src/Composer/Util/Tar.php b/src/Composer/Util/Tar.php index cae69c906..250a01c2c 100644 --- a/src/Composer/Util/Tar.php +++ b/src/Composer/Util/Tar.php @@ -40,7 +40,7 @@ class Tar * * @return string */ - private static function extractComposerJsonFromFolder(\PharData $phar) + private static function extractComposerJsonFromFolder(\PharData $phar): string { if (isset($phar['composer.json'])) { return $phar['composer.json']->getContent(); diff --git a/src/Composer/Util/TlsHelper.php b/src/Composer/Util/TlsHelper.php index 3fe329d4a..bf3aa1ea3 100644 --- a/src/Composer/Util/TlsHelper.php +++ b/src/Composer/Util/TlsHelper.php @@ -30,7 +30,7 @@ final class TlsHelper * * @return bool */ - public static function checkCertificateHost($certificate, $hostname, &$cn = null) + public static function checkCertificateHost($certificate, $hostname, &$cn = null): bool { $names = self::getCertificateNames($certificate); @@ -61,7 +61,7 @@ final class TlsHelper * * @return array{cn: string, san: string[]}|null */ - public static function getCertificateNames($certificate) + public static function getCertificateNames($certificate): ?array { if (is_array($certificate)) { $info = $certificate; @@ -136,7 +136,7 @@ final class TlsHelper * @param string $certificate * @return string */ - public static function getCertificateFingerprint($certificate) + public static function getCertificateFingerprint($certificate): string { $pubkey = openssl_get_publickey($certificate); if ($pubkey === false) { @@ -161,7 +161,7 @@ final class TlsHelper * * @return bool */ - public static function isOpensslParseSafe() + public static function isOpensslParseSafe(): bool { return CaBundle::isOpensslParseSafe(); } @@ -173,7 +173,7 @@ final class TlsHelper * * @return callable|null */ - private static function certNameMatcher($certName) + private static function certNameMatcher($certName): ?callable { $wildcards = substr_count($certName, '*'); diff --git a/src/Composer/Util/Zip.php b/src/Composer/Util/Zip.php index 7b1f6285c..f49ccdc25 100644 --- a/src/Composer/Util/Zip.php +++ b/src/Composer/Util/Zip.php @@ -65,7 +65,7 @@ class Zip * * @return int */ - private static function locateFile(\ZipArchive $zip, $filename) + private static function locateFile(\ZipArchive $zip, $filename): int { // return root composer.json if it is there and is a file if (false !== ($index = $zip->locateName($filename)) && $zip->getFromIndex($index) !== false) { diff --git a/tests/Composer/Test/AllFunctionalTest.php b/tests/Composer/Test/AllFunctionalTest.php index 896079f89..12bd95e3d 100644 --- a/tests/Composer/Test/AllFunctionalTest.php +++ b/tests/Composer/Test/AllFunctionalTest.php @@ -179,7 +179,7 @@ class AllFunctionalTest extends TestCase /** * @return array> */ - public function getTestFiles() + public function getTestFiles(): array { $tests = array(); foreach (Finder::create()->in(__DIR__.'/Fixtures/functional')->name('*.test')->files() as $file) { @@ -193,7 +193,7 @@ class AllFunctionalTest extends TestCase * @param string $file * @return array{RUN: string, EXPECT?: string, EXPECT-EXIT-CODE?: int, EXPECT-REGEX?: string, EXPECT-REGEXES?: string, TEST?: string} */ - private function parseTestFile($file) + private function parseTestFile($file): array { $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); $data = array(); @@ -255,7 +255,7 @@ class AllFunctionalTest extends TestCase * @param string $output * @return string */ - private function cleanOutput($output) + private function cleanOutput($output): string { $processed = ''; diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index ca5af8273..48ab276c1 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -1741,7 +1741,7 @@ EOF; /** * @return array */ - public function platformCheckProvider() + public function platformCheckProvider(): array { $versionParser = new VersionParser(); diff --git a/tests/Composer/Test/Autoload/ClassLoaderTest.php b/tests/Composer/Test/Autoload/ClassLoaderTest.php index 7b1f7ab7b..d11c522a9 100644 --- a/tests/Composer/Test/Autoload/ClassLoaderTest.php +++ b/tests/Composer/Test/Autoload/ClassLoaderTest.php @@ -42,7 +42,7 @@ class ClassLoaderTest extends TestCase * * @return array> Array of parameter sets to test with. */ - public function getLoadClassTests() + public function getLoadClassTests(): array { return array( array('Namespaced\\Foo'), diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 8f4fd1395..5315c4b33 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -38,7 +38,7 @@ class ClassMapGeneratorTest extends TestCase /** * @return array>> */ - public function getTestCreateMapTests() + public function getTestCreateMapTests(): array { $classmap = array( 'Foo\\Bar\\A' => realpath(__DIR__) . '/Fixtures/classmap/sameNsMultipleClasses.php', diff --git a/tests/Composer/Test/Command/RunScriptCommandTest.php b/tests/Composer/Test/Command/RunScriptCommandTest.php index fcae19051..97d5b2ad6 100644 --- a/tests/Composer/Test/Command/RunScriptCommandTest.php +++ b/tests/Composer/Test/Command/RunScriptCommandTest.php @@ -89,7 +89,7 @@ class RunScriptCommandTest extends TestCase } /** @return bool[][] **/ - public function getDevOptions() + public function getDevOptions(): array { return array( array(true, true), @@ -100,7 +100,7 @@ class RunScriptCommandTest extends TestCase } /** @return Composer **/ - private function createComposerInstance() + private function createComposerInstance(): Composer { $composer = new Composer; $config = new Config; diff --git a/tests/Composer/Test/Config/JsonConfigSourceTest.php b/tests/Composer/Test/Config/JsonConfigSourceTest.php index bcc193662..f23d5d958 100644 --- a/tests/Composer/Test/Config/JsonConfigSourceTest.php +++ b/tests/Composer/Test/Config/JsonConfigSourceTest.php @@ -29,7 +29,7 @@ class JsonConfigSourceTest extends TestCase * * @return string */ - protected function fixturePath($name) + protected function fixturePath($name): string { return __DIR__.'/Fixtures/'.$name; } @@ -160,7 +160,7 @@ class JsonConfigSourceTest extends TestCase * * @phpstan-return array{string, string, string, string, string} */ - protected function addLinkDataArguments($type, $name, $value, $fixtureBasename, $before) + protected function addLinkDataArguments($type, $name, $value, $fixtureBasename, $before): array { return array( $before, @@ -217,7 +217,7 @@ class JsonConfigSourceTest extends TestCase * * @phpstan-return array{string, string, string, string} */ - protected function removeLinkDataArguments($type, $name, $fixtureBasename, $after = null) + protected function removeLinkDataArguments($type, $name, $fixtureBasename, $after = null): array { return array( $this->fixturePath('removeLink/'.$fixtureBasename.'.json'), diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 0aad6141c..ded833967 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -269,7 +269,7 @@ class ConfigTest extends TestCase /** * @return string[][] List of test URLs that should pass strict security */ - public function allowedUrlProvider() + public function allowedUrlProvider(): array { $urls = array( 'https://packagist.org', @@ -290,7 +290,7 @@ class ConfigTest extends TestCase /** * @return string[][] List of test URLs that should not pass strict security */ - public function prohibitedUrlProvider() + public function prohibitedUrlProvider(): array { $urls = array( 'http://packagist.org', diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index 3939fcdd2..60ee193c3 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -149,7 +149,7 @@ class PoolBuilderTest extends TestCase * @param array $packageIds * @return string[] */ - private function getPackageResultSet(Pool $pool, $packageIds) + private function getPackageResultSet(Pool $pool, $packageIds): array { $result = array(); for ($i = 1, $count = count($pool); $i <= $count; $i++) { @@ -184,7 +184,7 @@ class PoolBuilderTest extends TestCase /** * @return array> */ - public function getIntegrationTests() + public function getIntegrationTests(): array { $fixturesDir = realpath(__DIR__.'/Fixtures/poolbuilder/'); $tests = array(); @@ -223,7 +223,7 @@ class PoolBuilderTest extends TestCase * @param string $fixturesDir * @return array */ - protected function readTestFile(\SplFileInfo $file, $fixturesDir) + protected function readTestFile(\SplFileInfo $file, $fixturesDir): array { $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); diff --git a/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php b/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php index 6b3e863bb..3455e325b 100644 --- a/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php @@ -100,7 +100,7 @@ class PoolOptimizerTest extends TestCase * @param string $fixturesDir * @return mixed[] */ - protected function readTestFile(\SplFileInfo $file, $fixturesDir) + protected function readTestFile(\SplFileInfo $file, $fixturesDir): array { $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); @@ -154,7 +154,7 @@ class PoolOptimizerTest extends TestCase * @param BasePackage[] $packages * @return string[] */ - private function reducePackagesInfoForComparison(array $packages) + private function reducePackagesInfoForComparison(array $packages): array { $packagesInfo = array(); @@ -171,7 +171,7 @@ class PoolOptimizerTest extends TestCase * @param mixed[][] $packagesData * @return BasePackage[] */ - private function loadPackages(array $packagesData) + private function loadPackages(array $packagesData): array { $packages = array(); @@ -189,7 +189,7 @@ class PoolOptimizerTest extends TestCase * @param mixed[] $packageData * @return BasePackage */ - private function loadPackage(array $packageData) + private function loadPackage(array $packageData): BasePackage { $loader = new ArrayLoader(); diff --git a/tests/Composer/Test/DependencyResolver/PoolTest.php b/tests/Composer/Test/DependencyResolver/PoolTest.php index 1e7fd5724..c4c5185ae 100644 --- a/tests/Composer/Test/DependencyResolver/PoolTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolTest.php @@ -61,7 +61,7 @@ class PoolTest extends TestCase * @param array<\Composer\Package\BasePackage>|null $packages * @return \Composer\DependencyResolver\Pool */ - protected function createPool($packages = array()) + protected function createPool($packages = array()): \Composer\DependencyResolver\Pool { return new Pool($packages); } diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index 691a38a72..73c92b183 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -43,7 +43,7 @@ class FileDownloaderTest extends TestCase * @param \Composer\Util\Filesystem $filesystem * @return \Composer\Downloader\FileDownloader */ - protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $httpDownloader = null, $filesystem = null) + protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $httpDownloader = null, $filesystem = null): \Composer\Downloader\FileDownloader { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $config = $config ?: $this->config; diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index a59ee038c..2ba0e33f0 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -42,7 +42,7 @@ class FossilDownloaderTest extends TestCase * @param \Composer\Util\Filesystem $filesystem * @return FossilDownloader */ - protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) + protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null): FossilDownloader { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $config = $config ?: $this->getMockBuilder('Composer\Config')->getMock(); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 57d55da1b..01a1397b8 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -62,7 +62,7 @@ class GitDownloaderTest extends TestCase * @param ?\Composer\Config $config * @return \Composer\Config */ - protected function setupConfig($config = null) + protected function setupConfig($config = null): \Composer\Config { if (!$config) { $config = new Config(); @@ -82,7 +82,7 @@ class GitDownloaderTest extends TestCase * @param \Composer\Util\Filesystem $filesystem * @return GitDownloader */ - protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) + protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null): GitDownloader { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $executor = $executor ?: $this->getProcessExecutorMock(); @@ -647,7 +647,7 @@ composer https://github.com/old/url (push) * @param string $cmd * @return string */ - private function winCompat($cmd) + private function winCompat($cmd): string { if (Platform::isWindows()) { $cmd = str_replace('cd ', 'cd /D ', $cmd); diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index f3a839303..81a039a24 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -42,7 +42,7 @@ class HgDownloaderTest extends TestCase * @param \Composer\Util\Filesystem $filesystem * @return HgDownloader */ - protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) + protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null): HgDownloader { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $config = $config ?: $this->getMockBuilder('Composer\Config')->getMock(); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index c6b99b5a6..16bd4d128 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -56,7 +56,7 @@ class PerforceDownloaderTest extends TestCase /** * @return \Composer\Config */ - protected function getConfig() + protected function getConfig(): \Composer\Config { $config = new Config(); $settings = array('config' => array('home' => $this->testPath)); @@ -87,7 +87,7 @@ class PerforceDownloaderTest extends TestCase /** * @return string[] */ - protected function getRepoConfig() + protected function getRepoConfig(): array { return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); } diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index 92b9ab5e2..49e9dcda4 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Downloader; +use React\Promise\PromiseInterface; use Composer\Downloader\ZipDownloader; use Composer\Package\PackageInterface; use Composer\Test\TestCase; @@ -334,17 +335,17 @@ class ZipDownloaderTest extends TestCase class MockedZipDownloader extends ZipDownloader { - public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true) + public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true): ?PromiseInterface { return \React\Promise\resolve(); } - public function install(PackageInterface $package, $path, $output = true) + public function install(PackageInterface $package, $path, $output = true): PromiseInterface { return \React\Promise\resolve(); } - public function extract(PackageInterface $package, $file, $path) + public function extract(PackageInterface $package, $file, $path): ?PromiseInterface { return parent::extract($package, $file, $path); } diff --git a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php index 7a37a92c2..e6b960acf 100644 --- a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php +++ b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php @@ -603,7 +603,7 @@ class EventDispatcherTest extends TestCase /** * @return true */ - public static function someMethod() + public static function someMethod(): bool { return true; } @@ -611,7 +611,7 @@ class EventDispatcherTest extends TestCase /** * @return true */ - public static function someMethod2() + public static function someMethod2(): bool { return true; } @@ -619,7 +619,7 @@ class EventDispatcherTest extends TestCase /** * @return Composer */ - private function createComposerInstance() + private function createComposerInstance(): Composer { $composer = new Composer; $config = new Config(); diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php index 767b50747..d7dcd9b33 100644 --- a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php @@ -33,7 +33,7 @@ final class IgnoreAllPlatformRequirementFilterTest extends TestCase /** * @return array */ - public function dataIsIgnored() + public function dataIsIgnored(): array { return array( 'php is ignored' => array('php', true), diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php index 685e97810..47af67fd2 100644 --- a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php @@ -34,7 +34,7 @@ final class IgnoreListPlatformRequirementFilterTest extends TestCase /** * @return array */ - public function dataIsIgnored() + public function dataIsIgnored(): array { return array( 'ext-json is ignored if listed' => array(array('ext-json', 'monolog/monolog'), 'ext-json', true), diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php index 02b7da85c..8b5b1f897 100644 --- a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php @@ -32,7 +32,7 @@ final class IgnoreNothingPlatformRequirementFilterTest extends TestCase /** * @return array */ - public function dataIsIgnored() + public function dataIsIgnored(): array { return array( 'php is not ignored' => array('php'), diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php index c7e462b92..d443532e3 100644 --- a/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php @@ -31,7 +31,7 @@ final class PlatformRequirementFilterFactoryTest extends TestCase /** * @return array */ - public function dataFromBoolOrList() + public function dataFromBoolOrList(): array { return array( 'true creates IgnoreAllFilter' => array(true, 'Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter'), diff --git a/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php b/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php index fc83c7261..5cd693d4f 100644 --- a/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php +++ b/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php @@ -271,7 +271,7 @@ class SuggestedPackagesReporterTest extends TestCase /** * @return array */ - private function getSuggestedPackageArray() + private function getSuggestedPackageArray(): array { return array( 'source' => 'a', diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 959ec7a33..3d1c78c20 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -160,7 +160,7 @@ class InstallerTest extends TestCase * @param PackageInterface[] $packages * @return mixed[] */ - protected function makePackagesComparable($packages) + protected function makePackagesComparable($packages): array { $dumper = new ArrayDumper(); @@ -516,7 +516,7 @@ class InstallerTest extends TestCase * @param string $path * @return mixed[] */ - public function loadIntegrationTests($path) + public function loadIntegrationTests($path): array { $fixturesDir = realpath(__DIR__.'/Fixtures/'.$path); $tests = array(); @@ -602,7 +602,7 @@ class InstallerTest extends TestCase * @param string $fixturesDir * @return mixed[] */ - protected function readTestFile(\SplFileInfo $file, $fixturesDir) + protected function readTestFile(\SplFileInfo $file, $fixturesDir): array { $tokens = Preg::split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); diff --git a/tests/Composer/Test/Mock/FactoryMock.php b/tests/Composer/Test/Mock/FactoryMock.php index ad2a14b9a..127720666 100644 --- a/tests/Composer/Test/Mock/FactoryMock.php +++ b/tests/Composer/Test/Mock/FactoryMock.php @@ -12,6 +12,8 @@ namespace Composer\Test\Mock; +use Composer\Installer\InstallationManager; +use Composer\Package\Loader\RootPackageLoader; use Composer\Composer; use Composer\Config; use Composer\Factory; @@ -30,7 +32,7 @@ use Composer\Util\ProcessExecutor; class FactoryMock extends Factory { - public static function createConfig(IOInterface $io = null, $cwd = null) + public static function createConfig(IOInterface $io = null, $cwd = null): Config { $config = new Config(true, $cwd); @@ -42,7 +44,7 @@ class FactoryMock extends Factory return $config; } - protected function loadRootPackage(RepositoryManager $rm, Config $config, VersionParser $parser, VersionGuesser $guesser, IOInterface $io) + protected function loadRootPackage(RepositoryManager $rm, Config $config, VersionParser $parser, VersionGuesser $guesser, IOInterface $io): RootPackageLoader { return new \Composer\Package\Loader\RootPackageLoader($rm, $config, $parser, new VersionGuesserMock(), $io); } @@ -52,16 +54,16 @@ class FactoryMock extends Factory $rm->setLocalRepository(new InstalledArrayRepository); } - public function createInstallationManager(Loop $loop, IOInterface $io, EventDispatcher $dispatcher = null) + public function createInstallationManager(Loop $loop, IOInterface $io, EventDispatcher $dispatcher = null): InstallationManager { return new InstallationManagerMock(); } - protected function createDefaultInstallers(Installer\InstallationManager $im, Composer $composer, IOInterface $io, ProcessExecutor $process = null): void + protected function createDefaultInstallers(InstallationManager $im, Composer $composer, IOInterface $io, ProcessExecutor $process = null): void { } - protected function purgePackages(InstalledRepositoryInterface $repo, Installer\InstallationManager $im): void + protected function purgePackages(InstalledRepositoryInterface $repo, InstallationManager $im): void { } } diff --git a/tests/Composer/Test/Mock/InstallationManagerMock.php b/tests/Composer/Test/Mock/InstallationManagerMock.php index 95fe5ecd5..ed4eaa873 100644 --- a/tests/Composer/Test/Mock/InstallationManagerMock.php +++ b/tests/Composer/Test/Mock/InstallationManagerMock.php @@ -12,6 +12,7 @@ namespace Composer\Test\Mock; +use React\Promise\PromiseInterface; use Composer\Installer\InstallationManager; use Composer\Repository\InstalledRepositoryInterface; use Composer\Package\PackageInterface; @@ -54,12 +55,12 @@ class InstallationManagerMock extends InstallationManager } } - public function getInstallPath(PackageInterface $package) + public function getInstallPath(PackageInterface $package): string { return ''; } - public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) + public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool { return $repo->hasPackage($package); } @@ -67,7 +68,7 @@ class InstallationManagerMock extends InstallationManager /** * @inheritDoc */ - public function install(InstalledRepositoryInterface $repo, InstallOperation $operation) + public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface { $this->installed[] = $operation->getPackage(); $this->trace[] = strip_tags((string) $operation); @@ -79,7 +80,7 @@ class InstallationManagerMock extends InstallationManager /** * @inheritDoc */ - public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation) + public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface { $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage()); $this->trace[] = strip_tags((string) $operation); @@ -94,7 +95,7 @@ class InstallationManagerMock extends InstallationManager /** * @inheritDoc */ - public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation) + public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface { $this->uninstalled[] = $operation->getPackage(); $this->trace[] = strip_tags((string) $operation); @@ -122,25 +123,25 @@ class InstallationManagerMock extends InstallationManager } /** @return string[] */ - public function getTrace() + public function getTrace(): array { return $this->trace; } /** @return PackageInterface[] */ - public function getInstalledPackages() + public function getInstalledPackages(): array { return $this->installed; } /** @return PackageInterface[][] */ - public function getUpdatedPackages() + public function getUpdatedPackages(): array { return $this->updated; } /** @return PackageInterface[] */ - public function getUninstalledPackages() + public function getUninstalledPackages(): array { return $this->uninstalled; } @@ -151,7 +152,7 @@ class InstallationManagerMock extends InstallationManager } /** @return PackageInterface[] */ - public function getInstalledPackagesByType() + public function getInstalledPackagesByType(): array { return $this->installed; } diff --git a/tests/Composer/Test/Mock/ProcessExecutorMock.php b/tests/Composer/Test/Mock/ProcessExecutorMock.php index cf9733ee1..dbd4f0bfc 100644 --- a/tests/Composer/Test/Mock/ProcessExecutorMock.php +++ b/tests/Composer/Test/Mock/ProcessExecutorMock.php @@ -12,6 +12,7 @@ namespace Composer\Test\Mock; +use React\Promise\PromiseInterface; use Composer\Util\ProcessExecutor; use Composer\Util\Platform; use PHPUnit\Framework\Assert; @@ -102,7 +103,7 @@ class ProcessExecutorMock extends ProcessExecutor Assert::assertTrue(true); // @phpstan-ignore-line } - public function execute($command, &$output = null, $cwd = null) + public function execute($command, &$output = null, $cwd = null): int { if (func_num_args() > 1) { return $this->doExecute($command, $cwd, false, $output); @@ -111,7 +112,7 @@ class ProcessExecutorMock extends ProcessExecutor return $this->doExecute($command, $cwd, false); } - public function executeTty($command, $cwd = null) + public function executeTty($command, $cwd = null): int { if (Platform::isTty()) { return $this->doExecute($command, $cwd, true); @@ -173,7 +174,7 @@ class ProcessExecutorMock extends ProcessExecutor return $return; } - public function executeAsync($command, $cwd = null) + public function executeAsync($command, $cwd = null): PromiseInterface { $resolver = function ($resolve, $reject): void { // TODO strictly speaking this should resolve with a mock Process instance here @@ -187,7 +188,7 @@ class ProcessExecutorMock extends ProcessExecutor return new Promise($resolver, $canceler); } - public function getErrorOutput() + public function getErrorOutput(): string { return $this->errorOutput; } diff --git a/tests/Composer/Test/Mock/VersionGuesserMock.php b/tests/Composer/Test/Mock/VersionGuesserMock.php index d2fe1236c..b634b0297 100644 --- a/tests/Composer/Test/Mock/VersionGuesserMock.php +++ b/tests/Composer/Test/Mock/VersionGuesserMock.php @@ -20,7 +20,7 @@ class VersionGuesserMock extends VersionGuesser { } - public function guessVersion(array $packageConfig, $path) + public function guessVersion(array $packageConfig, $path): ?array { return null; } diff --git a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php index 384623879..ad9bce604 100644 --- a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php @@ -260,7 +260,7 @@ class ArchivableFilesFinderTest extends TestCase /** * @return string[] */ - protected function getArchivableFiles() + protected function getArchivableFiles(): array { $files = array(); foreach ($this->finder as $file) { @@ -279,7 +279,7 @@ class ArchivableFilesFinderTest extends TestCase * * @return string[] */ - protected function getArchivedFiles($command) + protected function getArchivedFiles($command): array { $process = Process::fromShellCommandline($command, $this->sources); $process->run(); diff --git a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php index af8166576..8d620fbc9 100644 --- a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php @@ -104,7 +104,7 @@ class ArchiveManagerTest extends ArchiverTest * * @return string */ - protected function getTargetName(CompletePackage $package, $format, $fileName = null) + protected function getTargetName(CompletePackage $package, $format, $fileName = null): string { if (null === $fileName) { $packageName = $this->manager->getPackageFilename($package); diff --git a/tests/Composer/Test/Package/Archiver/ArchiverTest.php b/tests/Composer/Test/Package/Archiver/ArchiverTest.php index 9601fa1c6..5ac901d1b 100644 --- a/tests/Composer/Test/Package/Archiver/ArchiverTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchiverTest.php @@ -52,7 +52,7 @@ abstract class ArchiverTest extends TestCase * * @return CompletePackage */ - protected function setupPackage() + protected function setupPackage(): CompletePackage { $package = new CompletePackage('archivertest/archivertest', 'master', 'master'); $package->setSourceUrl(realpath($this->testDir)); diff --git a/tests/Composer/Test/Package/BasePackageTest.php b/tests/Composer/Test/Package/BasePackageTest.php index 0818ee358..b7ec37ce8 100644 --- a/tests/Composer/Test/Package/BasePackageTest.php +++ b/tests/Composer/Test/Package/BasePackageTest.php @@ -109,7 +109,7 @@ class BasePackageTest extends TestCase /** * @return mixed[][] */ - public function dataPackageNamesToRegexp() + public function dataPackageNamesToRegexp(): array { return array( array( diff --git a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php index 624347bd6..6a08d7b99 100644 --- a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php +++ b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php @@ -250,7 +250,7 @@ class ArrayDumperTest extends TestCase * * @return self */ - private function packageExpects($method, $value) + private function packageExpects($method, $value): \Composer\Test\Package\Dumper\ArrayDumperTest { $this->package ->expects($this->any()) diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index cfe12caa9..70f79bbbe 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -139,7 +139,7 @@ class ArrayLoaderTest extends TestCase * * @return array */ - protected function fixConfigWhenLoadConfigIsFalse($config) + protected function fixConfigWhenLoadConfigIsFalse($config): array { $expectedConfig = $config; unset($expectedConfig['transport-options']); diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index 05c2d6e0d..7a8fbf943 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -362,7 +362,7 @@ class VersionSelectorTest extends TestCase * * @return Package */ - private function createPackage($version) + private function createPackage($version): Package { $parser = new VersionParser(); diff --git a/tests/Composer/Test/Platform/HhvmDetectorTest.php b/tests/Composer/Test/Platform/HhvmDetectorTest.php index d3881a74d..eaf93c982 100644 --- a/tests/Composer/Test/Platform/HhvmDetectorTest.php +++ b/tests/Composer/Test/Platform/HhvmDetectorTest.php @@ -71,7 +71,7 @@ class HhvmDetectorTest extends TestCase /** * @return ?string */ - private static function versionIdToVersion() + private static function versionIdToVersion(): ?string { if (!defined('HHVM_VERSION_ID')) { return null; diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index 0bba37da8..fc0229527 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -407,7 +407,7 @@ class PluginInstallerTest extends TestCase } /** @return mixed[] */ - public function invalidImplementationClassNames() + public function invalidImplementationClassNames(): array { return array( array(null), @@ -422,7 +422,7 @@ class PluginInstallerTest extends TestCase } /** @return mixed[] */ - public function nonExistingOrInvalidImplementationClassTypes() + public function nonExistingOrInvalidImplementationClassTypes(): array { return array( array('\stdClass'), diff --git a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php index ed996717d..7d9c94a75 100644 --- a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php +++ b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php @@ -30,7 +30,7 @@ class StrictConfirmationQuestionTest extends TestCase * * @phpstan-return list */ - public function getAskConfirmationBadData() + public function getAskConfirmationBadData(): array { return array( array('not correct'), @@ -77,7 +77,7 @@ class StrictConfirmationQuestionTest extends TestCase * * @phpstan-return list|list */ - public function getAskConfirmationData() + public function getAskConfirmationData(): array { return array( array('', true), @@ -119,7 +119,7 @@ class StrictConfirmationQuestionTest extends TestCase /** * @return StreamOutput */ - protected function createOutputInterface() + protected function createOutputInterface(): StreamOutput { return new StreamOutput(fopen('php://memory', 'r+', false)); } @@ -131,7 +131,7 @@ class StrictConfirmationQuestionTest extends TestCase * * @phpstan-return array{ArrayInput, QuestionHelper} */ - protected function createInput($entry) + protected function createInput($entry): array { $input = new ArrayInput(array('--no-interaction')); $input->setStream($this->getInputStream($entry)); diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 96cdaa21a..f8c5946f8 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -1285,7 +1285,7 @@ class ResourceBundleStub * * @return ResourceBundleStub */ - public static function create($locale, $bundleName, $fallback) + public static function create($locale, $bundleName, $fallback): ResourceBundleStub { Assert::assertSame(3, func_num_args()); Assert::assertSame('root', $locale); @@ -1300,7 +1300,7 @@ class ResourceBundleStub * * @return string */ - public function get($field) + public function get($field): string { Assert::assertSame(1, func_num_args()); Assert::assertSame('Version', $field); @@ -1328,7 +1328,7 @@ class ImagickStub * @return array * @phpstan-return array{versionString: string} */ - public function getVersion() + public function getVersion(): array { Assert::assertSame(0, func_num_args()); diff --git a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php index 1643769ae..95fd969aa 100644 --- a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php @@ -64,7 +64,7 @@ class GitBitbucketDriverTest extends TestCase * * @phpstan-param array{url: string}&array $repoConfig */ - private function getDriver(array $repoConfig) + private function getDriver(array $repoConfig): GitBitbucketDriver { $driver = new GitBitbucketDriver( $repoConfig, diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 74576d98a..8482b28bd 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -337,7 +337,7 @@ class GitHubDriverTest extends TestCase /** * @return list */ - public function supportsProvider() + public function supportsProvider(): array { return array( array(false, 'https://github.com/acme'), diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 058bbc4c7..00acd67df 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -102,7 +102,7 @@ class PerforceDriverTest extends TestCase * * @return Config */ - protected function getTestConfig($testPath) + protected function getTestConfig($testPath): Config { $config = new Config(); $config->merge(array('config' => array('home' => $testPath))); diff --git a/tests/Composer/Test/Script/EventTest.php b/tests/Composer/Test/Script/EventTest.php index 561d0b300..724d0e886 100644 --- a/tests/Composer/Test/Script/EventTest.php +++ b/tests/Composer/Test/Script/EventTest.php @@ -71,7 +71,7 @@ class EventTest extends TestCase /** * @return Composer */ - private function createComposerInstance() + private function createComposerInstance(): Composer { $composer = new Composer; $config = new Config; diff --git a/tests/Composer/Test/TestCase.php b/tests/Composer/Test/TestCase.php index 380bd2550..a7a9d5c29 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -67,7 +67,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase /** * @return string */ - public static function getUniqueTmpDirectory() + public static function getUniqueTmpDirectory(): string { $attempts = 5; $root = sys_get_temp_dir(); @@ -86,7 +86,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase /** * @return VersionParser */ - protected static function getVersionParser() + protected static function getVersionParser(): VersionParser { if (!self::$parser) { self::$parser = new VersionParser(); @@ -100,7 +100,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase * @param string $version * @return Constraint */ - protected function getVersionConstraint($operator, $version) + protected function getVersionConstraint($operator, $version): Constraint { $constraint = new Constraint( $operator, @@ -214,7 +214,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase * * @return string The transformed command */ - protected function getCmd($cmd) + protected function getCmd($cmd): string { if (Platform::isWindows()) { $cmd = Preg::replaceCallback("/('[^']*')/", function ($m) { diff --git a/tests/Composer/Test/Util/NoProxyPatternTest.php b/tests/Composer/Test/Util/NoProxyPatternTest.php index 9a02d7e54..2a09261a7 100644 --- a/tests/Composer/Test/Util/NoProxyPatternTest.php +++ b/tests/Composer/Test/Util/NoProxyPatternTest.php @@ -140,7 +140,7 @@ class NoProxyPatternTest extends TestCase * * @return string */ - private function getUrl($url) + private function getUrl($url): string { if (parse_url($url, PHP_URL_SCHEME)) { return $url; diff --git a/tests/Composer/Test/Util/PackageSorterTest.php b/tests/Composer/Test/Util/PackageSorterTest.php index e11d1b89f..7c3eb7671 100644 --- a/tests/Composer/Test/Util/PackageSorterTest.php +++ b/tests/Composer/Test/Util/PackageSorterTest.php @@ -124,7 +124,7 @@ class PackageSorterTest extends TestCase * * @return Package */ - private function createPackage($name, $requires) + private function createPackage($name, $requires): Package { $package = new Package($name, '1.0.0.0', '1.0.0'); diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 764d1a68c..4e3f7d5b9 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -50,7 +50,7 @@ class PerforceTest extends TestCase /** * @return array */ - public function getTestRepoConfig() + public function getTestRepoConfig(): array { return array( 'depot' => self::TEST_DEPOT, @@ -598,7 +598,7 @@ class PerforceTest extends TestCase /** * @return string */ - public static function getComposerJson() + public static function getComposerJson(): string { return JsonFile::encode([ 'name' => 'test/perforce', @@ -615,7 +615,7 @@ class PerforceTest extends TestCase * * @return string[] */ - private function getExpectedClientSpec($withStream) + private function getExpectedClientSpec($withStream): array { $expectedArray = array( 'Client: composer_perforce_TEST_depot', diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 667e6d17f..26e76982e 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -265,7 +265,7 @@ class RemoteFilesystemTest extends TestCase * * @return string[][] */ - public function provideBitbucketPublicDownloadUrls() + public function provideBitbucketPublicDownloadUrls(): array { return array( array('https://bitbucket.org/seldaek/composer-live-test-repo/downloads/composer-unit-test-download-me.txt', '1234'), @@ -343,7 +343,7 @@ class RemoteFilesystemTest extends TestCase * * @return mixed[] */ - private function callGetOptionsForUrl(IOInterface $io, array $args = array(), array $options = array(), $fileUrl = '') + private function callGetOptionsForUrl(IOInterface $io, array $args = array(), array $options = array(), $fileUrl = ''): array { $fs = new RemoteFilesystem($io, $this->getConfigMock(), $options); $ref = new ReflectionMethod($fs, 'getOptionsForUrl');