1
0
Fork 0

Add parameter types to all the things

pull/10561/head
Jordi Boggiano 2022-02-22 16:47:09 +01:00
parent c9baeda95b
commit 6da38f83a0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
279 changed files with 1377 additions and 1504 deletions

View File

@ -16,8 +16,8 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/tests')
->name('*.php')
->notPath('Fixtures')
->notPath(__DIR__.'/src/Composer/Autoload/ClassLoader.php')
->notPath(__DIR__.'/src/Composer/InstalledVersions.php')
->notPath('Composer/Autoload/ClassLoader.php')
->notPath('Composer/InstalledVersions.php')
;
$config = new PhpCsFixer\Config();
@ -70,7 +70,11 @@ return $config->setRules([
'combine_nested_dirname' => true,
'random_api_migration' => true,
'ternary_to_null_coalescing' => true,
'phpdoc_to_param_type' => true,
//'declare_strict_types' => true,
// TODO php 7.4 migration (one day..)
// 'phpdoc_to_property_type' => true,
])
->setUsingCache(true)
->setRiskyAllowed(true)

View File

@ -2,6 +2,7 @@
<?php
$cwd = getcwd();
assert(is_string($cwd));
chdir(__DIR__.'/../');
$ts = rtrim(shell_exec('git log -n1 --pretty=%ct HEAD'));
if (!is_numeric($ts)) {

View File

@ -89,7 +89,7 @@ class AutoloadGenerator
* @param bool $devMode
* @return void
*/
public function setDevMode($devMode = true)
public function setDevMode(bool $devMode = true)
{
$this->devMode = (bool) $devMode;
}
@ -100,7 +100,7 @@ class AutoloadGenerator
* @param bool $classMapAuthoritative
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
public function setClassMapAuthoritative(bool $classMapAuthoritative)
{
$this->classMapAuthoritative = (bool) $classMapAuthoritative;
}
@ -112,7 +112,7 @@ class AutoloadGenerator
* @param string|null $apcuPrefix
* @return void
*/
public function setApcu($apcu, $apcuPrefix = null)
public function setApcu(bool $apcu, ?string $apcuPrefix = null)
{
$this->apcu = (bool) $apcu;
$this->apcuPrefix = $apcuPrefix !== null ? (string) $apcuPrefix : $apcuPrefix;
@ -124,7 +124,7 @@ class AutoloadGenerator
* @param bool $runScripts
* @return void
*/
public function setRunScripts($runScripts = true)
public function setRunScripts(bool $runScripts = true)
{
$this->runScripts = (bool) $runScripts;
}
@ -163,7 +163,7 @@ class AutoloadGenerator
* @return int
* @throws \Seld\JsonLint\ParsingException
*/
public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = '')
public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, string $targetDir, bool $scanPsrPackages = false, string $suffix = '')
{
if ($this->classMapAuthoritative) {
// Force scanPsrPackages when classmap is authoritative
@ -200,7 +200,7 @@ class AutoloadGenerator
// Do not remove double realpath() calls.
// Fixes failing Windows realpath() implementation.
// See https://bugs.php.net/bug.php?id=72738
$basePath = $filesystem->normalizePath(realpath(realpath(getcwd())));
$basePath = $filesystem->normalizePath(realpath(realpath(Platform::getCwd())));
$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
$useGlobalIncludePath = (bool) $config->get('use-include-path');
$prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';
@ -433,15 +433,15 @@ EOF;
* @param string $basePath
* @param string $vendorPath
* @param string $dir
* @param ?array<int, string> $excluded
* @param ?string $namespaceFilter
* @param ?string $autoloadType
* @param null|array<int, string> $excluded
* @param null|string $namespaceFilter
* @param null|string $autoloadType
* @param array<class-string, string> $classMap
* @param array<class-string, array<int, string>> $ambiguousClasses
* @param array<string, true> $scannedFiles
* @return array<class-string, string>
*/
private function addClassMapCode(Filesystem $filesystem, $basePath, $vendorPath, $dir, $excluded, $namespaceFilter, $autoloadType, array $classMap, array &$ambiguousClasses, array &$scannedFiles): array
private function addClassMapCode(Filesystem $filesystem, string $basePath, string $vendorPath, string $dir, ?array $excluded, ?string $namespaceFilter, ?string $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";
@ -457,14 +457,14 @@ EOF;
/**
* @param string $dir
* @param ?array<int, string> $excluded
* @param ?string $namespaceFilter
* @param ?string $autoloadType
* @param null|array<int, string> $excluded
* @param null|string $namespaceFilter
* @param null|string $autoloadType
* @param bool $showAmbiguousWarning
* @param array<string, true> $scannedFiles
* @return array<class-string, string>
*/
private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, $showAmbiguousWarning, array &$scannedFiles): array
private function generateClassMap(string $dir, ?array $excluded, ?string $namespaceFilter, ?string $autoloadType, bool $showAmbiguousWarning, array &$scannedFiles): array
{
if ($excluded) {
// filter excluded patterns here to only use those matching $dir
@ -586,10 +586,10 @@ EOF;
* Registers an autoloader based on an autoload-map returned by parseAutoloads
*
* @param array<string, mixed[]> $autoloads see parseAutoloads return value
* @param ?string $vendorDir
* @param null|string $vendorDir
* @return ClassLoader
*/
public function createLoader(array $autoloads, $vendorDir = null)
public function createLoader(array $autoloads, ?string $vendorDir = null)
{
$loader = new ClassLoader($vendorDir);
@ -632,7 +632,7 @@ EOF;
* @param string $appBaseDirCode
* @return ?string
*/
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, string $basePath, string $vendorPath, string $vendorPathCode, string $appBaseDirCode)
{
$includePaths = array();
@ -680,7 +680,7 @@ EOF;
* @param string $appBaseDirCode
* @return ?string
*/
protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
protected function getIncludeFilesFile(array $files, Filesystem $filesystem, string $basePath, string $vendorPath, string $vendorPathCode, string $appBaseDirCode)
{
$filesCode = '';
foreach ($files as $fileIdentifier => $functionFile) {
@ -712,7 +712,7 @@ EOF;
* @param string $path
* @return string
*/
protected function getPathCode(Filesystem $filesystem, $basePath, $vendorPath, $path)
protected function getPathCode(Filesystem $filesystem, string $basePath, string $vendorPath, string $path)
{
if (!$filesystem->isAbsolutePath($path)) {
$path = $basePath . '/' . $path;
@ -748,7 +748,7 @@ EOF;
* @param string[] $devPackageNames
* @return ?string
*/
protected function getPlatformCheck(array $packageMap, $checkPlatform, array $devPackageNames)
protected function getPlatformCheck(array $packageMap, bool $checkPlatform, array $devPackageNames)
{
$lowestPhpVersion = Bound::zero();
$requiredExtensions = array();
@ -906,7 +906,7 @@ PLATFORM_CHECK;
* @param string $suffix
* @return string
*/
protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix)
protected function getAutoloadFile(string $vendorPathToTargetDirCode, string $suffix)
{
$lastChar = $vendorPathToTargetDirCode[strlen($vendorPathToTargetDirCode) - 1];
if ("'" === $lastChar || '"' === $lastChar) {
@ -930,7 +930,7 @@ AUTOLOAD;
/**
* @param bool $useClassMap
* @param bool $useIncludePath
* @param ?string $targetDirLoader
* @param null|string $targetDirLoader
* @param bool $useIncludeFiles
* @param string $vendorPathCode unused in this method
* @param string $appBaseDirCode unused in this method
@ -940,7 +940,7 @@ AUTOLOAD;
* @param bool $checkPlatform
* @return string
*/
protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $checkPlatform)
protected function getAutoloadRealFile(bool $useClassMap, bool $useIncludePath, ?string $targetDirLoader, bool $useIncludeFiles, string $vendorPathCode, string $appBaseDirCode, string $suffix, bool $useGlobalIncludePath, string $prependAutoloader, bool $checkPlatform)
{
$file = <<<HEADER
<?php
@ -1092,7 +1092,7 @@ FOOTER;
* @param string $basePath input for findShortestPathCode
* @return string
*/
protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath)
protected function getStaticFile(string $suffix, string $targetDir, string $vendorPath, string $basePath)
{
$file = <<<HEADER
<?php
@ -1185,7 +1185,7 @@ INITIALIZER;
* @param string $type one of: 'psr-0'|'psr-4'|'classmap'|'files'
* @return array<int, string>|array<string, array<string>>|array<string, string>
*/
protected function parseAutoloadsType(array $packageMap, $type, RootPackageInterface $rootPackage)
protected function parseAutoloadsType(array $packageMap, string $type, RootPackageInterface $rootPackage)
{
$autoloads = array();
@ -1240,7 +1240,7 @@ INITIALIZER;
$path
);
if (empty($installPath)) {
$installPath = strtr(getcwd(), '\\', '/');
$installPath = strtr(Platform::getCwd(), '\\', '/');
}
$resolvedPath = realpath($installPath . '/' . $updir);
@ -1271,7 +1271,7 @@ INITIALIZER;
* @param string $path
* @return string
*/
protected function getFileIdentifier(PackageInterface $package, $path)
protected function getFileIdentifier(PackageInterface $package, string $path)
{
return md5($package->getName() . ':' . $path);
}
@ -1369,7 +1369,7 @@ INITIALIZER;
* @param string $file
* @return void
*/
function composerRequire($fileIdentifier, $file)
function composerRequire(string $fileIdentifier, string $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -19,6 +19,7 @@
namespace Composer\Autoload;
use Composer\Pcre\Preg;
use Composer\Util\Platform;
use Symfony\Component\Finder\Finder;
use Composer\IO\IOInterface;
use Composer\Util\Filesystem;
@ -35,10 +36,10 @@ class ClassMapGenerator
* Generate a class map file
*
* @param \Traversable<string>|array<string> $dirs Directories or a single path to search in
* @param string $file The name of the class map file
* @param string $file The name of the class map file
* @return void
*/
public static function dump($dirs, $file): void
public static function dump(iterable $dirs, string $file): void
{
$maps = array();
@ -55,13 +56,13 @@ class ClassMapGenerator
* @param \Traversable<\SplFileInfo>|string|array<string> $path The path to search in or an iterator
* @param string $excluded Regex that matches file paths to be excluded from the classmap
* @param ?IOInterface $io IO object
* @param ?string $namespace Optional namespace prefix to filter by
* @param ?string $autoloadType psr-0|psr-4 Optional autoload standard to use mapping rules
* @param null|string $namespace Optional namespace prefix to filter by
* @param null|string $autoloadType psr-0|psr-4 Optional autoload standard to use mapping rules
* @param array<string, true> $scannedFiles
* @return array<class-string, string> A class map array
* @throws \RuntimeException When the path is neither an existing file nor directory
*/
public static function createMap($path, $excluded = null, IOInterface $io = null, $namespace = null, $autoloadType = null, &$scannedFiles = array()): array
public static function createMap($path, string $excluded = null, IOInterface $io = null, ?string $namespace = null, ?string $autoloadType = null, array &$scannedFiles = array()): array
{
$basePath = $path;
if (is_string($path)) {
@ -81,7 +82,7 @@ class ClassMapGenerator
$map = array();
$filesystem = new Filesystem();
$cwd = realpath(getcwd());
$cwd = realpath(Platform::getCwd());
foreach ($path as $file) {
$filePath = $file->getPathname();
@ -157,7 +158,7 @@ class ClassMapGenerator
* @param ?IOInterface $io IO object
* @return array<int, class-string> valid classes
*/
private static function filterByNamespace($classes, $filePath, $baseNamespace, $namespaceType, $basePath, $io): array
private static function filterByNamespace(array $classes, string $filePath, string $baseNamespace, string $namespaceType, string $basePath, ?IOInterface $io): array
{
$validClasses = array();
$rejectedClasses = array();
@ -198,7 +199,7 @@ class ClassMapGenerator
if (empty($validClasses)) {
foreach ($rejectedClasses as $class) {
if ($io) {
$io->writeError("<warning>Class $class located in ".Preg::replace('{^'.preg_quote(getcwd()).'}', '.', $filePath, 1)." does not comply with $namespaceType autoloading standard. Skipping.</warning>");
$io->writeError("<warning>Class $class located in ".Preg::replace('{^'.preg_quote(Platform::getCwd()).'}', '.', $filePath, 1)." does not comply with $namespaceType autoloading standard. Skipping.</warning>");
}
}
@ -215,7 +216,7 @@ class ClassMapGenerator
* @throws \RuntimeException
* @return array<int, class-string> The found classes
*/
private static function findClasses($path): array
private static function findClasses(string $path): array
{
$extraTypes = self::getExtraTypes();

View File

@ -51,7 +51,7 @@ class PhpFileCleaner
* @param string[] $types
* @return void
*/
public static function setTypeConfig($types): void
public static function setTypeConfig(array $types): void
{
foreach ($types as $type) {
self::$typeConfig[$type[0]] = array(
@ -68,7 +68,7 @@ class PhpFileCleaner
* @param string $contents
* @param int $maxMatches
*/
public function __construct($contents, $maxMatches)
public function __construct(string $contents, int $maxMatches)
{
$this->contents = $contents;
$this->len = \strlen($this->contents);
@ -168,7 +168,7 @@ class PhpFileCleaner
* @param string $delimiter
* @return void
*/
private function skipString($delimiter): void
private function skipString(string $delimiter): void
{
$this->index += 1;
while ($this->index < $this->len) {
@ -217,7 +217,7 @@ class PhpFileCleaner
* @param string $delimiter
* @return void
*/
private function skipHeredoc($delimiter): void
private function skipHeredoc(string $delimiter): void
{
$firstDelimiterChar = $delimiter[0];
$delimiterLength = \strlen($delimiter);
@ -260,14 +260,14 @@ class PhpFileCleaner
* @param string $char
* @return bool
*/
private function peek($char): bool
private function peek(string $char): bool
{
return $this->index + 1 < $this->len && $this->contents[$this->index + 1] === $char;
}
/**
* @param non-empty-string $regex
* @param ?array<int, string> $match
* @param null|array<int, string> $match
* @return bool
*/
private function match($regex, array &$match = null): bool

View File

@ -48,7 +48,7 @@ class Cache
* @param Filesystem $filesystem optional filesystem instance
* @param bool $readOnly whether the cache is in readOnly mode
*/
public function __construct(IOInterface $io, $cacheDir, $allowlist = 'a-z0-9.', Filesystem $filesystem = null, $readOnly = false)
public function __construct(IOInterface $io, string $cacheDir, string $allowlist = 'a-z0-9.', Filesystem $filesystem = null, bool $readOnly = false)
{
$this->io = $io;
$this->root = rtrim($cacheDir, '/\\') . '/';
@ -66,7 +66,7 @@ class Cache
*
* @return void
*/
public function setReadOnly($readOnly)
public function setReadOnly(bool $readOnly)
{
$this->readOnly = (bool) $readOnly;
}
@ -84,7 +84,7 @@ class Cache
*
* @return bool
*/
public static function isUsable($path)
public static function isUsable(string $path)
{
return !Preg::isMatch('{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $path);
}
@ -122,7 +122,7 @@ class Cache
*
* @return string|false
*/
public function read($file)
public function read(string $file)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -142,7 +142,7 @@ class Cache
*
* @return bool
*/
public function write($file, $contents)
public function write(string $file, string $contents)
{
if ($this->isEnabled() && !$this->readOnly) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -186,7 +186,7 @@ class Cache
*
* @return bool
*/
public function copyFrom($file, $source)
public function copyFrom(string $file, string $source)
{
if ($this->isEnabled() && !$this->readOnly) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -212,7 +212,7 @@ class Cache
*
* @return bool
*/
public function copyTo($file, $target)
public function copyTo(string $file, string $target)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -256,7 +256,7 @@ class Cache
*
* @return bool
*/
public function remove($file)
public function remove(string $file)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -287,7 +287,7 @@ class Cache
* @return int|false
* @phpstan-return int<0, max>|false
*/
public function getAge($file)
public function getAge(string $file)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -305,7 +305,7 @@ class Cache
*
* @return bool
*/
public function gc($ttl, $maxSize)
public function gc(int $ttl, int $maxSize)
{
if ($this->isEnabled()) {
$expire = new \DateTime();
@ -340,7 +340,7 @@ class Cache
*
* @return string|false
*/
public function sha1($file)
public function sha1(string $file)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
@ -357,7 +357,7 @@ class Cache
*
* @return string|false
*/
public function sha256($file)
public function sha256(string $file)
{
if ($this->isEnabled()) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);

View File

@ -25,6 +25,7 @@ use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Util\Filesystem;
use Composer\Util\Loop;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -136,7 +137,7 @@ EOT
$io->writeError('<info>Creating the archive into "'.$dest.'".</info>');
$packagePath = $archiveManager->archive($package, $format, $dest, $fileName, $ignoreFilters);
$fs = new Filesystem;
$shortPath = $fs->findShortestPath(getcwd(), $packagePath, true);
$shortPath = $fs->findShortestPath(Platform::getCwd(), $packagePath, true);
$io->writeError('Created: ', false);
$io->write(strlen($shortPath) < strlen($packagePath) ? $shortPath : $packagePath);
@ -150,7 +151,7 @@ EOT
*
* @return (BasePackage&CompletePackageInterface)|false
*/
protected function selectPackage(IOInterface $io, $packageName, $version = null)
protected function selectPackage(IOInterface $io, string $packageName, ?string $version = null)
{
$io->writeError('<info>Searching for the specified package.</info>');

View File

@ -70,7 +70,7 @@ abstract class BaseCommand extends Command
* @return Composer|null
* @deprecated since Composer 2.3.0 use requireComposer or tryComposer depending on whether you have $required set to true or false
*/
public function getComposer($required = true, $disablePlugins = null, $disableScripts = null)
public function getComposer(bool $required = true, ?bool $disablePlugins = null, ?bool $disableScripts = null)
{
if ($required) {
return $this->requireComposer($disablePlugins, $disableScripts);
@ -226,7 +226,7 @@ abstract class BaseCommand extends Command
*
* @return bool[] An array composed of the preferSource and preferDist values
*/
protected function getPreferredInstallOptions(Config $config, InputInterface $input, $keepVcsRequiresPreferSource = false)
protected function getPreferredInstallOptions(Config $config, InputInterface $input, bool $keepVcsRequiresPreferSource = false)
{
$preferSource = false;
$preferDist = false;

View File

@ -50,7 +50,7 @@ class BaseDependencyCommand extends BaseCommand
* @param bool $inverted Whether to invert matching process (why-not vs why behaviour)
* @return int Exit code of the operation.
*/
protected function doExecute(InputInterface $input, OutputInterface $output, $inverted = false): int
protected function doExecute(InputInterface $input, OutputInterface $output, bool $inverted = false): int
{
// Emit command event on startup
$composer = $this->requireComposer();
@ -197,7 +197,7 @@ class BaseDependencyCommand extends BaseCommand
*
* @return void
*/
protected function printTree($results, $prefix = '', $level = 1): void
protected function printTree(array $results, string $prefix = '', int $level = 1): void
{
$count = count($results);
$idx = 0;
@ -223,7 +223,7 @@ class BaseDependencyCommand extends BaseCommand
*
* @return void
*/
private function writeTreeLine($line): void
private function writeTreeLine(string $line): void
{
$io = $this->getIO();
if (!$io->isDecorated()) {

View File

@ -174,7 +174,7 @@ EOT
*
* @return void
*/
protected function printTable(OutputInterface $output, $results): void
protected function printTable(OutputInterface $output, array $results): void
{
$rows = array();
foreach ($results as $result) {

View File

@ -175,7 +175,7 @@ EOT
if (
($configFile === 'composer.json' || $configFile === './composer.json')
&& !file_exists($configFile)
&& realpath(getcwd()) === realpath($this->config->get('home'))
&& realpath(Platform::getCwd()) === realpath($this->config->get('home'))
) {
file_put_contents($configFile, "{\n}\n");
}
@ -810,7 +810,7 @@ EOT
*
* @return void
*/
protected function handleSingleValue($key, array $callbacks, array $values, $method): void
protected function handleSingleValue(string $key, array $callbacks, array $values, string $method): void
{
list($validator, $normalizer) = $callbacks;
if (1 !== count($values)) {
@ -845,7 +845,7 @@ EOT
*
* @return void
*/
protected function handleMultiValue($key, array $callbacks, array $values, $method): void
protected function handleMultiValue(string $key, array $callbacks, array $values, string $method): void
{
list($validator, $normalizer) = $callbacks;
if (true !== $validation = $validator($values)) {
@ -868,7 +868,7 @@ EOT
*
* @return void
*/
protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null, $showSource = false): void
protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, ?string $k = null, bool $showSource = false): void
{
$origK = $k;
$io = $this->getIO();

View File

@ -187,9 +187,9 @@ EOT
* @return int
* @throws \Exception
*/
public function installProject(IOInterface $io, Config $config, InputInterface $input, $packageName = null, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositories = null, $disablePlugins = false, $disableScripts = false, $noProgress = false, $noInstall = false, PlatformRequirementFilterInterface $platformRequirementFilter = null, $secureHttp = true, $addRepository = false): int
public function installProject(IOInterface $io, Config $config, InputInterface $input, ?string $packageName = null, ?string $directory = null, ?string $packageVersion = null, ?string $stability = 'stable', bool $preferSource = false, bool $preferDist = false, bool $installDevPackages = false, $repositories = null, bool $disablePlugins = false, bool $disableScripts = false, bool $noProgress = false, bool $noInstall = false, PlatformRequirementFilterInterface $platformRequirementFilter = null, bool $secureHttp = true, bool $addRepository = false): int
{
$oldCwd = getcwd();
$oldCwd = Platform::getCwd();
if ($repositories !== null && !is_array($repositories)) {
$repositories = (array) $repositories;
@ -284,7 +284,7 @@ EOT
)
) {
$finder = new Finder();
$finder->depth(0)->directories()->in(getcwd())->ignoreVCS(false)->ignoreDotFiles(false);
$finder->depth(0)->directories()->in(Platform::getCwd())->ignoreVCS(false)->ignoreDotFiles(false);
foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg', '.fslckout', '_FOSSIL_') as $vcsName) {
$finder->name($vcsName);
}
@ -350,7 +350,7 @@ EOT
* @return bool
* @throws \Exception
*/
protected function installRootPackage(IOInterface $io, Config $config, $packageName, PlatformRequirementFilterInterface $platformRequirementFilter, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, array $repositories = null, $disablePlugins = false, $disableScripts = false, $noProgress = false, $secureHttp = true): bool
protected function installRootPackage(IOInterface $io, Config $config, string $packageName, PlatformRequirementFilterInterface $platformRequirementFilter, ?string $directory = null, ?string $packageVersion = null, ?string $stability = 'stable', bool $preferSource = false, bool $preferDist = false, bool $installDevPackages = false, array $repositories = null, bool $disablePlugins = false, bool $disableScripts = false, bool $noProgress = false, bool $secureHttp = true): bool
{
if (!$secureHttp) {
$config->merge(array('config' => array('secure-http' => false)), Config::SOURCE_COMMAND);
@ -366,16 +366,16 @@ EOT
// if no directory was specified, use the 2nd part of the package name
if (null === $directory) {
$parts = explode("/", $name, 2);
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
$directory = Platform::getCwd() . DIRECTORY_SEPARATOR . array_pop($parts);
}
$process = new ProcessExecutor($io);
$fs = new Filesystem($process);
if (!$fs->isAbsolutePath($directory)) {
$directory = getcwd() . DIRECTORY_SEPARATOR . $directory;
$directory = Platform::getCwd() . DIRECTORY_SEPARATOR . $directory;
}
$io->writeError('<info>Creating a "' . $packageName . '" project at "' . $fs->findShortestPath(getcwd(), $directory, true) . '"</info>');
$io->writeError('<info>Creating a "' . $packageName . '" project at "' . $fs->findShortestPath(Platform::getCwd(), $directory, true) . '"</info>');
if (file_exists($directory)) {
if (!is_dir($directory)) {

View File

@ -245,7 +245,7 @@ EOT
*
* @return string|string[]|true
*/
private function checkHttp($proto, Config $config)
private function checkHttp(string $proto, Config $config)
{
$result = $this->checkConnectivity();
if ($result !== true) {
@ -315,7 +315,7 @@ EOT
*
* @return string|true|\Exception
*/
private function checkGithubOauth($domain, $token)
private function checkGithubOauth(string $domain, string $token)
{
$result = $this->checkConnectivity();
if ($result !== true) {
@ -346,7 +346,7 @@ EOT
* @throws TransportException
* @return mixed|string
*/
private function getGithubRateLimit($domain, $token = null)
private function getGithubRateLimit(string $domain, string $token = null)
{
$result = $this->checkConnectivity();
if ($result !== true) {

View File

@ -95,7 +95,7 @@ EOT
// If the CWD was modified, we restore it to what it was initially, as it was
// most likely modified by the global command, and we want exec to run in the local working directory
// not the global one
if (getcwd() !== $this->getApplication()->getInitialWorkingDirectory()) {
if (getcwd() !== $this->getApplication()->getInitialWorkingDirectory() && $this->getApplication()->getInitialWorkingDirectory() !== false) {
try {
chdir($this->getApplication()->getInitialWorkingDirectory());
} catch (\Exception $e) {

View File

@ -101,7 +101,7 @@ EOT
* @param bool $showOnly
* @return bool
*/
private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly): bool
private function handlePackage(CompletePackageInterface $package, bool $showHomepage, bool $showOnly): bool
{
$support = $package->getSupport();
$url = $support['source'] ?? $package->getSourceUrl();
@ -128,7 +128,7 @@ EOT
* @param string $url
* @return void
*/
private function openBrowser($url): void
private function openBrowser(string $url): void
{
$url = ProcessExecutor::escape($url);

View File

@ -460,7 +460,7 @@ EOT
* @param string $author
* @return array{name: string, email: string|null}
*/
public function parseAuthorString($author)
public function parseAuthorString(string $author)
{
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'"()]+)(?:\s+<(?P<email>.+?)>)?$/u', $author, $match)) {
$hasEmail = isset($match['email']) && '' !== $match['email'];
@ -485,7 +485,7 @@ EOT
*
* @return array<int, array{name: string, email?: string}>
*/
protected function formatAuthors($author)
protected function formatAuthors(string $author)
{
$author = $this->parseAuthorString($author);
if (null === $author['email']) {
@ -504,7 +504,7 @@ EOT
*
* @return string|null
*/
public function namespaceFromPackageName($packageName)
public function namespaceFromPackageName(string $packageName)
{
if (!$packageName || strpos($packageName, '/') === false) {
return null;
@ -567,7 +567,7 @@ EOT
*
* @return bool
*/
protected function hasVendorIgnore($ignoreFile, $vendor = 'vendor')
protected function hasVendorIgnore(string $ignoreFile, string $vendor = 'vendor')
{
if (!file_exists($ignoreFile)) {
return false;
@ -591,7 +591,7 @@ EOT
*
* @return void
*/
protected function addVendorIgnore($ignoreFile, $vendor = '/vendor/')
protected function addVendorIgnore(string $ignoreFile, string $vendor = '/vendor/')
{
$contents = "";
if (file_exists($ignoreFile)) {
@ -610,7 +610,7 @@ EOT
*
* @return bool
*/
protected function isValidEmail($email)
protected function isValidEmail(string $email)
{
// assume it's valid if we can't validate it
if (!function_exists('filter_var')) {
@ -652,7 +652,7 @@ EOT
* @param array<string, string|array<string>> $options
* @return bool
*/
private function hasDependencies($options): bool
private function hasDependencies(array $options): bool
{
$requires = (array) $options['require'];
$devRequires = isset($options['require-dev']) ? (array) $options['require-dev'] : array();

View File

@ -163,7 +163,7 @@ EOT
* @param array<string, PackageInterface> $bucket
* @return array<string, PackageInterface>
*/
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()): array
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, array $bucket = array()): array
{
$requires = array_keys($package->getRequires());

View File

@ -296,7 +296,7 @@ EOT
* @param string $requireKey
* @return string[]
*/
private function getInconsistentRequireKeys(array $newRequirements, $requireKey): array
private function getInconsistentRequireKeys(array $newRequirements, string $requireKey): array
{
$requireKeys = $this->getPackagesByRequireKey();
$inconsistentRequirements = array();
@ -351,7 +351,7 @@ EOT
* @return int
* @throws \Exception
*/
private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey): int
private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, string $requireKey, string $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): bool
private function updateFileCleanly(JsonFile $json, array $new, string $requireKey, string $removeKey, bool $sortPackages): bool
{
$contents = file_get_contents($json->getPath());
@ -480,7 +480,7 @@ EOT
* @param bool $hardExit
* @return void
*/
public function revertComposerFile($hardExit = true)
public function revertComposerFile(bool $hardExit = true)
{
$io = $this->getIO();

View File

@ -27,14 +27,10 @@ class ScriptAliasCommand extends BaseCommand
/** @var string */
private $description;
/**
* @param string $script
* @param string $description
*/
public function __construct($script, $description)
public function __construct(string $script, ?string $description)
{
$this->script = $script;
$this->description = empty($description) ? 'Runs the '.$script.' script as defined in composer.json.' : $description;
$this->description = $description ?? 'Runs the '.$script.' script as defined in composer.json.';
parent::__construct();
}

View File

@ -397,7 +397,7 @@ TAGSPUBKEY
* @return int
* @throws FilesystemException
*/
protected function rollback(OutputInterface $output, $rollbackDir, $localFilename): int
protected function rollback(OutputInterface $output, string $rollbackDir, string $localFilename): int
{
$rollbackVersion = $this->getLastBackupVersion($rollbackDir);
if (!$rollbackVersion) {
@ -431,7 +431,7 @@ TAGSPUBKEY
* @throws FilesystemException If the file cannot be moved
* @return bool Whether the phar is valid and has been moved
*/
protected function setLocalPhar($localFilename, $newFilename, $backupTarget = null): bool
protected function setLocalPhar(string $localFilename, string $newFilename, string $backupTarget = null): bool
{
$io = $this->getIO();
@chmod($newFilename, fileperms($localFilename));
@ -483,7 +483,7 @@ TAGSPUBKEY
*
* @return void
*/
protected function cleanBackups($rollbackDir, $except = null): void
protected function cleanBackups(string $rollbackDir, ?string $except = null): void
{
$finder = $this->getOldInstallationFinder($rollbackDir);
$io = $this->getIO();
@ -503,7 +503,7 @@ TAGSPUBKEY
* @param string $rollbackDir
* @return string|false
*/
protected function getLastBackupVersion($rollbackDir)
protected function getLastBackupVersion(string $rollbackDir)
{
$finder = $this->getOldInstallationFinder($rollbackDir);
$finder->sortByName();
@ -520,7 +520,7 @@ TAGSPUBKEY
* @param string $rollbackDir
* @return Finder
*/
protected function getOldInstallationFinder($rollbackDir): Finder
protected function getOldInstallationFinder(string $rollbackDir): Finder
{
return Finder::create()
->depth(0)
@ -541,7 +541,7 @@ TAGSPUBKEY
* @throws \Exception
* @return bool If the operation succeeded
*/
protected function validatePhar($pharFile, &$error): bool
protected function validatePhar(string $pharFile, ?string &$error): bool
{
if (ini_get('phar.readonly')) {
return true;
@ -590,7 +590,7 @@ TAGSPUBKEY
* @param string $newFilename The downloaded or backup phar
* @return bool Whether composer.phar has been updated
*/
protected function tryAsWindowsAdmin($localFilename, $newFilename): bool
protected function tryAsWindowsAdmin(string $localFilename, string $newFilename): bool
{
$io = $this->getIO();

View File

@ -223,7 +223,7 @@ EOT
if ($input->getOption('no-dev')) {
$packages = $this->filterRequiredPackages($installedRepo, $rootPkg);
$repos = $installedRepo = new InstalledRepository(array(new InstalledArrayRepository(array_map(function ($pkg): \Composer\Package\PackageInterface {
$repos = $installedRepo = new InstalledRepository(array(new InstalledArrayRepository(array_map(function ($pkg): PackageInterface {
return clone $pkg;
}, $packages))));
}
@ -628,7 +628,7 @@ EOT
* @throws \InvalidArgumentException
* @return array{CompletePackageInterface|null, array<string, string>}
*/
protected function getPackage(InstalledRepository $installedRepo, RepositoryInterface $repos, $name, $version = null)
protected function getPackage(InstalledRepository $installedRepo, RepositoryInterface $repos, string $name, $version = null)
{
$name = strtolower($name);
$constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version;
@ -802,7 +802,7 @@ EOT
*
* @return void
*/
protected function printLinks(CompletePackageInterface $package, $linkType, $title = null)
protected function printLinks(CompletePackageInterface $package, string $linkType, string $title = null)
{
$title = $title ?: $linkType;
$io = $this->getIO();
@ -923,7 +923,7 @@ EOT
* @param array<string, string> $versions
* @return array<string, string|string[]|null>
*/
private function appendVersions($json, array $versions): array
private function appendVersions(array $json, array $versions): array
{
uasort($versions, 'version_compare');
$versions = array_keys(array_reverse($versions));
@ -936,7 +936,7 @@ EOT
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendLicenses($json, CompletePackageInterface $package): array
private function appendLicenses(array $json, CompletePackageInterface $package): array
{
if ($licenses = $package->getLicense()) {
$spdxLicenses = new SpdxLicenses();
@ -963,7 +963,7 @@ EOT
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendAutoload($json, CompletePackageInterface $package): array
private function appendAutoload(array $json, CompletePackageInterface $package): array
{
if ($package->getAutoload()) {
$autoload = array();
@ -996,7 +996,7 @@ EOT
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendLinks($json, CompletePackageInterface $package): array
private function appendLinks(array $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<string, string|string[]|null>
*/
private function appendLink($json, CompletePackageInterface $package, $linkType): array
private function appendLink(array $json, CompletePackageInterface $package, string $linkType): array
{
$links = $package->{'get' . ucfirst($linkType)}();
@ -1147,8 +1147,8 @@ EOT
protected function displayTree(
$package,
array $packagesInTree,
$previousTreeBar = '├',
$level = 1
string $previousTreeBar = '├',
int $level = 1
) {
$previousTreeBar = str_replace('├', '│', $previousTreeBar);
if (is_array($package) && isset($package['requires'])) {
@ -1197,7 +1197,7 @@ EOT
* @return array<int, array<string, array<int, array<string, string>>|string>>
*/
protected function addTree(
$name,
string $name,
Link $link,
InstalledRepository $installedRepo,
RepositoryInterface $remoteRepos,
@ -1240,7 +1240,7 @@ EOT
* @param string $updateStatus
* @return string
*/
private function updateStatusToVersionStyle($updateStatus): string
private function updateStatusToVersionStyle(string $updateStatus): string
{
// 'up-to-date' is printed green
// 'semver-safe-update' is printed red
@ -1275,7 +1275,7 @@ EOT
*
* @return void
*/
private function writeTreeLine($line): void
private function writeTreeLine(string $line): void
{
$io = $this->getIO();
if (!$io->isDecorated()) {
@ -1342,7 +1342,7 @@ EOT
* @param array<PackageInterface> $bucket
* @return array<PackageInterface>
*/
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()): array
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, array $bucket = array()): array
{
$requires = $package->getRequires();

View File

@ -312,7 +312,7 @@ EOT
* @param string $constraint
* @return Link
*/
private function appendConstraintToLink(Link $link, $constraint): Link
private function appendConstraintToLink(Link $link, string $constraint): Link
{
$parser = new VersionParser;
$oldPrettyString = $link->getConstraint()->getPrettyString();

View File

@ -169,7 +169,7 @@ EOT
*
* @return void
*/
private function outputResult(IOInterface $io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false): void
private function outputResult(IOInterface $io, string $name, array &$errors, array &$warnings, bool $checkPublish = false, array $publishErrors = array(), bool $checkLock = false, array $lockErrors = array(), bool $printSchemaUrl = false): void
{
$doPrintSchemaUrl = false;

View File

@ -44,7 +44,7 @@ class Compiler
*
* @throws \RuntimeException
*/
public function compile($pharFile = 'composer.phar'): void
public function compile(string $pharFile = 'composer.phar'): void
{
if (file_exists($pharFile)) {
unlink($pharFile);
@ -201,7 +201,7 @@ class Compiler
* @param \SplFileInfo $file
* @return string
*/
private function getRelativeFilePath($file): string
private function getRelativeFilePath(\SplFileInfo $file): string
{
$realPath = $file->getRealPath();
$pathPrefix = dirname(__DIR__, 2).DIRECTORY_SEPARATOR;
@ -217,7 +217,7 @@ class Compiler
*
* @return void
*/
private function addFile(\Phar $phar, \SplFileInfo $file, $strip = true): void
private function addFile(\Phar $phar, \SplFileInfo $file, bool $strip = true): void
{
$path = $this->getRelativeFilePath($file);
$content = file_get_contents($file);
@ -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): string
private function stripWhitespace(string $source): string
{
if (!function_exists('token_get_all')) {
return $source;

View File

@ -111,10 +111,10 @@ class Config
private $sourceOfConfigValue = array();
/**
* @param bool $useEnvironment Use COMPOSER_ environment variables to replace config settings
* @param string $baseDir Optional base directory of the config
* @param bool $useEnvironment Use COMPOSER_ environment variables to replace config settings
* @param ?string $baseDir Optional base directory of the config
*/
public function __construct($useEnvironment = true, $baseDir = null)
public function __construct(bool $useEnvironment = true, ?string $baseDir = null)
{
// load defaults
$this->config = static::$defaultConfig;
@ -126,7 +126,7 @@ class Config
$this->repositories = static::$defaultRepositories;
$this->useEnvironment = (bool) $useEnvironment;
$this->baseDir = $baseDir;
$this->baseDir = is_string($baseDir) && '' !== $baseDir ? $baseDir : null;
foreach ($this->config as $configKey => $configValue) {
$this->setSourceOfConfigValue($configValue, $configKey, self::SOURCE_DEFAULT);
@ -177,7 +177,7 @@ class Config
*
* @return void
*/
public function merge($config, $source = self::SOURCE_UNKNOWN): void
public function merge(array $config, string $source = self::SOURCE_UNKNOWN): void
{
// override defaults with given config
if (!empty($config['config']) && is_array($config['config'])) {
@ -277,7 +277,7 @@ class Config
*
* @return mixed
*/
public function get($key, $flags = 0)
public function get(string $key, int $flags = 0)
{
switch ($key) {
// strings/paths with env var and {$refs} support
@ -441,7 +441,7 @@ class Config
*
* @return array<string, mixed[]>
*/
public function all($flags = 0): array
public function all(int $flags = 0): array
{
$all = array(
'repositories' => $this->getRepositories(),
@ -457,7 +457,7 @@ class Config
* @param string $key
* @return string
*/
public function getSourceOfValue($key): string
public function getSourceOfValue(string $key): string
{
$this->get($key);
@ -471,7 +471,7 @@ class Config
*
* @return void
*/
private function setSourceOfConfigValue($configValue, $path, $source): void
private function setSourceOfConfigValue($configValue, string $path, string $source): void
{
$this->sourceOfConfigValue[$path] = $source;
@ -499,7 +499,7 @@ class Config
* @param string $key
* @return bool
*/
public function has($key): bool
public function has(string $key): bool
{
return array_key_exists($key, $this->config);
}
@ -512,7 +512,7 @@ class Config
*
* @return string|int|null
*/
private function process($value, $flags)
private function process($value, int $flags)
{
if (!is_string($value)) {
return $value;
@ -531,9 +531,9 @@ class Config
* @param string $path
* @return string
*/
private function realpath($path): string
private function realpath(string $path): string
{
if (Preg::isMatch('{^(?:/|[a-z]:|[a-z0-9.]+://)}i', $path)) {
if (Preg::isMatch('{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i', $path)) {
return $path;
}
@ -549,7 +549,7 @@ class Config
* @param string $var
* @return string|bool
*/
private function getComposerEnv($var)
private function getComposerEnv(string $var)
{
if ($this->useEnvironment) {
return Platform::getEnv($var);
@ -563,7 +563,7 @@ class Config
*
* @return void
*/
private function disableRepoByName($name): void
private function disableRepoByName(string $name): void
{
if (isset($this->repositories[$name])) {
unset($this->repositories[$name]);
@ -580,7 +580,7 @@ class Config
*
* @return void
*/
public function prohibitUrlByConfig($url, IOInterface $io = null): void
public function prohibitUrlByConfig(string $url, IOInterface $io = null): void
{
// Return right away if the URL is malformed or custom (see issue #5173)
if (false === filter_var($url, FILTER_VALIDATE_URL)) {

View File

@ -29,7 +29,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function addRepository($name, $config, $append = true);
public function addRepository(string $name, $config, bool $append = true);
/**
* Remove a repository
@ -38,7 +38,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function removeRepository($name);
public function removeRepository(string $name);
/**
* Add a config setting
@ -48,7 +48,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function addConfigSetting($name, $value);
public function addConfigSetting(string $name, $value);
/**
* Remove a config setting
@ -57,7 +57,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function removeConfigSetting($name);
public function removeConfigSetting(string $name);
/**
* Add a property
@ -67,7 +67,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function addProperty($name, $value);
public function addProperty(string $name, $value);
/**
* Remove a property
@ -76,7 +76,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function removeProperty($name);
public function removeProperty(string $name);
/**
* Add a package link
@ -87,7 +87,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function addLink($type, $name, $value);
public function addLink(string $type, string $name, string $value);
/**
* Remove a package link
@ -97,7 +97,7 @@ interface ConfigSourceInterface
*
* @return void
*/
public function removeLink($type, $name);
public function removeLink(string $type, string $name);
/**
* Gives a user-friendly name to this source (file path or so)

View File

@ -43,7 +43,7 @@ class JsonConfigSource implements ConfigSourceInterface
* @param JsonFile $file
* @param bool $authConfig
*/
public function __construct(JsonFile $file, $authConfig = false)
public function __construct(JsonFile $file, bool $authConfig = false)
{
$this->file = $file;
$this->authConfig = $authConfig;
@ -214,7 +214,7 @@ class JsonConfigSource implements ConfigSourceInterface
*
* @return void
*/
private function manipulateJson($method, $fallback, ...$args): void
private function manipulateJson(string $method, callable $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): int
private function arrayUnshiftRef(array &$array, &$value): int
{
$return = array_unshift($array, '');
$array[0] = &$value;

View File

@ -74,7 +74,7 @@ class Application extends BaseApplication
private $disableScriptsByDefault = false;
/**
* @var string Store the initial working directory at startup time
* @var string|false Store the initial working directory at startup time
*/
private $initialWorkingDirectory;
@ -151,10 +151,11 @@ class Application extends BaseApplication
// switch working dir
if ($newWorkDir = $this->getNewWorkingDir($input)) {
$oldWorkingDir = getcwd();
$oldWorkingDir = Platform::getCwd(true);
chdir($newWorkDir);
$this->initialWorkingDirectory = $newWorkDir;
$io->writeError('Changed CWD to ' . getcwd(), true, IOInterface::DEBUG);
$cwd = Platform::getCwd(true);
$io->writeError('Changed CWD to ' . ($cwd !== '' ? $cwd : $newWorkDir), true, IOInterface::DEBUG);
}
// determine command name to be executed without including plugin commands
@ -171,7 +172,7 @@ class Application extends BaseApplication
// prompt user for dir change if no composer.json is present in current dir
if ($io->isInteractive() && !$newWorkDir && !in_array($commandName, array('', 'list', 'init', 'about', 'help', 'diagnose', 'self-update', 'global', 'create-project', 'outdated'), true) && !file_exists(Factory::getComposerFile()) && ($useParentDirIfNoJsonAvailable = $this->getUseParentDirConfigValue()) !== false) {
$dir = dirname(getcwd());
$dir = dirname(Platform::getCwd(true));
$home = realpath(Platform::getEnv('HOME') ?: Platform::getEnv('USERPROFILE') ?: '/');
// abort when we reach the home dir or top of the filesystem
@ -183,7 +184,7 @@ class Application extends BaseApplication
} else {
$io->writeError('<info>Always want to use the parent dir? Use "composer config --global use-parent-dir true" to change the default.</info>');
}
$oldWorkingDir = getcwd();
$oldWorkingDir = Platform::getCwd(true);
chdir($dir);
}
break;
@ -330,7 +331,7 @@ class Application extends BaseApplication
$result = parent::doRun($input, $output);
// chdir back to $oldWorkingDir if set
if (isset($oldWorkingDir)) {
if (isset($oldWorkingDir) && '' !== $oldWorkingDir) {
Silencer::call('chdir', $oldWorkingDir);
}
@ -424,7 +425,7 @@ class Application extends BaseApplication
* @throws \InvalidArgumentException
* @return ?\Composer\Composer If $required is true then the return value is guaranteed
*/
public function getComposer($required = true, $disablePlugins = null, $disableScripts = null)
public function getComposer(bool $required = true, ?bool $disablePlugins = null, ?bool $disableScripts = null)
{
if (null === $disablePlugins) {
$disablePlugins = $this->disablePluginsByDefault;
@ -585,7 +586,7 @@ class Application extends BaseApplication
/**
* Get the working directory at startup time
*
* @return string
* @return string|false
*/
public function getInitialWorkingDirectory()
{

View File

@ -34,7 +34,7 @@ final class GithubActionError
*
* @return void
*/
public function emit($message, $file = null, $line = null): void
public function emit(string $message, ?string $file = null, ?int $line = null): void
{
if (Platform::getEnv('GITHUB_ACTIONS') && !Platform::getEnv('COMPOSER_TESTS_ARE_RUNNING')) {
$message = $this->escapeData($message);
@ -55,7 +55,7 @@ final class GithubActionError
* @param string $data
* @return string
*/
private function escapeData($data): string
private function escapeData(string $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): string
private function escapeProperty(string $property): string
{
// see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L87-L94
$property = str_replace("%", '%25', $property);

View File

@ -43,7 +43,7 @@ class Decisions implements \Iterator, \Countable
* @param int $level
* @return void
*/
public function decide($literal, $level, Rule $why): void
public function decide(int $literal, int $level, Rule $why): void
{
$this->addDecision($literal, $level);
$this->decisionQueue[] = array(
@ -56,7 +56,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literal
* @return bool
*/
public function satisfy($literal): bool
public function satisfy(int $literal): bool
{
$packageId = abs($literal);
@ -70,7 +70,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literal
* @return bool
*/
public function conflict($literal): bool
public function conflict(int $literal): bool
{
$packageId = abs($literal);
@ -84,7 +84,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literalOrPackageId
* @return bool
*/
public function decided($literalOrPackageId): bool
public function decided(int $literalOrPackageId): bool
{
return !empty($this->decisionMap[abs($literalOrPackageId)]);
}
@ -93,7 +93,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literalOrPackageId
* @return bool
*/
public function undecided($literalOrPackageId): bool
public function undecided(int $literalOrPackageId): bool
{
return empty($this->decisionMap[abs($literalOrPackageId)]);
}
@ -102,7 +102,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literalOrPackageId
* @return bool
*/
public function decidedInstall($literalOrPackageId): bool
public function decidedInstall(int $literalOrPackageId): bool
{
$packageId = abs($literalOrPackageId);
@ -113,7 +113,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literalOrPackageId
* @return int
*/
public function decisionLevel($literalOrPackageId): int
public function decisionLevel(int $literalOrPackageId): int
{
$packageId = abs($literalOrPackageId);
if (isset($this->decisionMap[$packageId])) {
@ -127,7 +127,7 @@ class Decisions implements \Iterator, \Countable
* @param int $literalOrPackageId
* @return Rule|null
*/
public function decisionRule($literalOrPackageId): ?Rule
public function decisionRule(int $literalOrPackageId): ?Rule
{
$packageId = abs($literalOrPackageId);
@ -144,7 +144,7 @@ class Decisions implements \Iterator, \Countable
* @param int $queueOffset
* @return array{0: int, 1: Rule} a literal and decision reason
*/
public function atOffset($queueOffset): array
public function atOffset(int $queueOffset): array
{
return $this->decisionQueue[$queueOffset];
}
@ -153,7 +153,7 @@ class Decisions implements \Iterator, \Countable
* @param int $queueOffset
* @return bool
*/
public function validOffset($queueOffset): bool
public function validOffset(int $queueOffset): bool
{
return $queueOffset >= 0 && $queueOffset < \count($this->decisionQueue);
}
@ -188,7 +188,7 @@ class Decisions implements \Iterator, \Countable
* @param int $offset
* @return void
*/
public function resetToOffset($offset): void
public function resetToOffset(int $offset): void
{
while (\count($this->decisionQueue) > $offset + 1) {
$decision = array_pop($this->decisionQueue);
@ -252,7 +252,7 @@ class Decisions implements \Iterator, \Countable
* @param int $level
* @return void
*/
protected function addDecision($literal, $level): void
protected function addDecision(int $literal, int $level): void
{
$packageId = abs($literal);

View File

@ -32,7 +32,7 @@ class DefaultPolicy implements PolicyInterface
* @param bool $preferStable
* @param bool $preferLowest
*/
public function __construct($preferStable = false, $preferLowest = false)
public function __construct(bool $preferStable = false, bool $preferLowest = false)
{
$this->preferStable = $preferStable;
$this->preferLowest = $preferLowest;
@ -44,7 +44,7 @@ class DefaultPolicy implements PolicyInterface
*
* @phpstan-param Constraint::STR_OP_* $operator
*/
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator): bool
public function versionCompare(PackageInterface $a, PackageInterface $b, string $operator): bool
{
if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
@ -61,7 +61,7 @@ class DefaultPolicy implements PolicyInterface
* @param string $requiredPackage
* @return int[]
*/
public function selectPreferredPackages(Pool $pool, array $literals, $requiredPackage = null): array
public function selectPreferredPackages(Pool $pool, array $literals, string $requiredPackage = null): array
{
$packages = $this->groupLiteralsByName($pool, $literals);
@ -90,7 +90,7 @@ class DefaultPolicy implements PolicyInterface
* @param int[] $literals
* @return array<string, int[]>
*/
protected function groupLiteralsByName(Pool $pool, $literals): array
protected function groupLiteralsByName(Pool $pool, array $literals): array
{
$packages = array();
foreach ($literals as $literal) {
@ -107,11 +107,11 @@ class DefaultPolicy implements PolicyInterface
/**
* @protected
* @param ?string $requiredPackage
* @param null|string $requiredPackage
* @param bool $ignoreReplace
* @return int
*/
public function compareByPriority(Pool $pool, BasePackage $a, BasePackage $b, $requiredPackage = null, $ignoreReplace = false): int
public function compareByPriority(Pool $pool, BasePackage $a, BasePackage $b, ?string $requiredPackage = null, bool $ignoreReplace = false): int
{
// prefer aliases to the original package
if ($a->getName() === $b->getName()) {
@ -182,7 +182,7 @@ class DefaultPolicy implements PolicyInterface
* @param int[] $literals
* @return int[]
*/
protected function pruneToBestVersion(Pool $pool, $literals): array
protected function pruneToBestVersion(Pool $pool, array $literals): array
{
$operator = $this->preferLowest ? '<' : '>';
$bestLiterals = array($literals[0]);

View File

@ -106,7 +106,7 @@ class LockTransaction extends Transaction
* @param bool $updateMirrors
* @return BasePackage[]
*/
public function getNewLockPackages($devMode, $updateMirrors = false): array
public function getNewLockPackages(bool $devMode, bool $updateMirrors = false): array
{
$packages = array();
foreach ($this->resultPackages[$devMode ? 'dev' : 'non-dev'] as $package) {
@ -119,7 +119,7 @@ class LockTransaction extends Transaction
if ($presentPackage->getSourceReference() && $presentPackage->getSourceType() === $package->getSourceType()) {
$package->setSourceDistReferences($presentPackage->getSourceReference());
}
if ($presentPackage->getReleaseDate() && $package instanceof Package) {
if ($presentPackage->getReleaseDate() !== null && $package instanceof Package) {
$package->setReleaseDate($presentPackage->getReleaseDate());
}
}
@ -137,7 +137,7 @@ class LockTransaction extends Transaction
* @param array<array{package: string, version: string, alias: string, alias_normalized: string}> $aliases
* @return array<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
public function getAliases($aliases): array
public function getAliases(array $aliases): array
{
$usedAliases = array();

View File

@ -55,7 +55,7 @@ class InstallOperation extends SolverOperation implements OperationInterface
* @param bool $lock
* @return string
*/
public static function format(PackageInterface $package, $lock = false)
public static function format(PackageInterface $package, bool $lock = false)
{
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
}

View File

@ -32,7 +32,7 @@ interface OperationInterface
* @param bool $lock Whether this is an operation on the lock file
* @return string
*/
public function show($lock);
public function show(bool $lock);
/**
* Serializes the operation in a human readable format

View File

@ -55,7 +55,7 @@ class UninstallOperation extends SolverOperation implements OperationInterface
* @param bool $lock
* @return string
*/
public static function format(PackageInterface $package, $lock = false): string
public static function format(PackageInterface $package, bool $lock = false): string
{
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
}

View File

@ -76,7 +76,7 @@ class UpdateOperation extends SolverOperation implements OperationInterface
* @param bool $lock
* @return string
*/
public static function format(PackageInterface $initialPackage, PackageInterface $targetPackage, $lock = false): string
public static function format(PackageInterface $initialPackage, PackageInterface $targetPackage, bool $lock = false): string
{
$fromVersion = $initialPackage->getFullPrettyVersion();
$toVersion = $targetPackage->getFullPrettyVersion();

View File

@ -26,12 +26,12 @@ interface PolicyInterface
*
* @phpstan-param Constraint::STR_OP_* $operator
*/
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator): bool;
public function versionCompare(PackageInterface $a, PackageInterface $b, string $operator): bool;
/**
* @param int[] $literals
* @param ?string $requiredPackage
* @param null|string $requiredPackage
* @return int[]
*/
public function selectPreferredPackages(Pool $pool, array $literals, $requiredPackage = null): array;
public function selectPreferredPackages(Pool $pool, array $literals, ?string $requiredPackage = null): array;
}

View File

@ -60,7 +60,7 @@ class Pool implements \Countable
* @param string $name
* @return array<string, string>
*/
public function getRemovedVersions($name, ConstraintInterface $constraint): array
public function getRemovedVersions(string $name, ConstraintInterface $constraint): array
{
if (!isset($this->removedVersions[$name])) {
return array();
@ -80,7 +80,7 @@ class Pool implements \Countable
* @param string $objectHash
* @return array<string, string>
*/
public function getRemovedVersionsByPackage($objectHash): array
public function getRemovedVersionsByPackage(string $objectHash): array
{
if (!isset($this->removedVersionsByPackage[$objectHash])) {
return array();
@ -122,7 +122,7 @@ class Pool implements \Countable
* @param int $id
* @return BasePackage
*/
public function packageById($id): BasePackage
public function packageById(int $id): BasePackage
{
return $this->packages[$id - 1];
}
@ -143,7 +143,7 @@ class Pool implements \Countable
* packages must match or null to return all
* @return BasePackage[] A set of packages
*/
public function whatProvides($name, ConstraintInterface $constraint = null): array
public function whatProvides(string $name, ConstraintInterface $constraint = null): array
{
$key = (string) $constraint;
if (isset($this->providerCache[$name][$key])) {
@ -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): array
private function computeWhatProvides(string $name, ConstraintInterface $constraint = null): array
{
if (!isset($this->packageByName[$name])) {
return array();
@ -180,7 +180,7 @@ class Pool implements \Countable
* @param int $literal
* @return BasePackage
*/
public function literalToPackage($literal): BasePackage
public function literalToPackage(int $literal): BasePackage
{
$packageId = abs($literal);
@ -192,7 +192,7 @@ class Pool implements \Countable
* @param array<int, BasePackage> $installedMap
* @return string
*/
public function literalToPrettyString($literal, $installedMap): string
public function literalToPrettyString(int $literal, array $installedMap): string
{
$package = $this->literalToPackage($literal);
@ -212,7 +212,7 @@ class Pool implements \Countable
* @param string $name Name of the package to be matched
* @return bool
*/
public function match(BasePackage $candidate, $name, ConstraintInterface $constraint = null): bool
public function match(BasePackage $candidate, string $name, ConstraintInterface $constraint = null): bool
{
$candidateName = $candidate->getName();
$candidateVersion = $candidate->getVersion();

View File

@ -300,7 +300,7 @@ class PoolBuilder
* @param string $name
* @return void
*/
private function markPackageNameForLoading(Request $request, $name, ConstraintInterface $constraint): void
private function markPackageNameForLoading(Request $request, string $name, ConstraintInterface $constraint): void
{
// Skip platform requires at this stage
if (PlatformRepository::isPlatformPackage($name)) {
@ -396,7 +396,7 @@ class PoolBuilder
* @param RepositoryInterface[] $repositories
* @return void
*/
private function loadPackage(Request $request, array $repositories, BasePackage $package, $propagateUpdate): void
private function loadPackage(Request $request, array $repositories, BasePackage $package, bool $propagateUpdate): void
{
$index = $this->indexCounter++;
$this->packages[$index] = $package;
@ -501,7 +501,7 @@ class PoolBuilder
* @param string $name packageName
* @return bool
*/
private function isRootRequire(Request $request, $name): bool
private function isRootRequire(Request $request, string $name): bool
{
$rootRequires = $request->getRequires();
@ -512,7 +512,7 @@ class PoolBuilder
* @param string $name
* @return string[]
*/
private function getSkippedRootRequires(Request $request, $name): array
private function getSkippedRootRequires(Request $request, string $name): array
{
if (!isset($this->skippedLoad[$name])) {
return array();
@ -602,7 +602,7 @@ class PoolBuilder
* @param string $name
* @return void
*/
private function unlockPackage(Request $request, array $repositories, $name): void
private function unlockPackage(Request $request, array $repositories, string $name): void
{
foreach ($this->skippedLoad[$name] as $packageOrReplacer) {
// if we unfixed a replaced package name, we also need to unfix the replacer itself
@ -668,7 +668,7 @@ class PoolBuilder
* @param int $index
* @return void
*/
private function removeLoadedPackage(Request $request, array $repositories, BasePackage $package, $index): void
private function removeLoadedPackage(Request $request, array $repositories, BasePackage $package, int $index): void
{
$repoIndex = array_search($package->getRepository(), $repositories, true);

View File

@ -322,7 +322,7 @@ class PoolOptimizer
* @param int $id
* @return void
*/
private function markPackageForRemoval($id): void
private function markPackageForRemoval(int $id): void
{
// We are not allowed to remove packages if they have been marked as irremovable
if (isset($this->irremovablePackages[$id])) {
@ -337,7 +337,7 @@ class PoolOptimizer
* @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup
* @return void
*/
private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup): void
private function keepPackage(BasePackage $package, array $identicalDefinitionsPerPackage, array $packageIdenticalDefinitionLookup): void
{
unset($this->packagesToRemove[$package->id]);

View File

@ -77,7 +77,7 @@ class Problem
* @param array<Rule[]> $learnedPool
* @return string
*/
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, array $installedMap = array(), array $learnedPool = array()): string
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, bool $isVerbose, array $installedMap = array(), array $learnedPool = array()): string
{
// TODO doesn't this entirely defeat the purpose of the problem sections? what's the point of sections?
$reasons = call_user_func_array('array_merge', array_reverse($this->reasons));
@ -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()): string
public static function formatDeduplicatedRules(array $rules, string $indent, RepositorySet $repositorySet, Request $request, Pool $pool, bool $isVerbose, array $installedMap = array(), array $learnedPool = array()): string
{
$messages = array();
$templates = array();
@ -185,7 +185,7 @@ class Problem
* @param Rule $reason The reason descriptor
* @return void
*/
protected function addReason($id, Rule $reason): void
protected function addReason(string $id, Rule $reason): void
{
// TODO: if a rule is part of a problem description in two sections, isn't this going to remove a message
// that is important to understand the issue?
@ -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): array
public static function getMissingPackageReason(RepositorySet $repositorySet, Request $request, Pool $pool, bool $isVerbose, string $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): string
public static function getPackageList(array $packages, bool $isVerbose, Pool $pool = null, ConstraintInterface $constraint = null, bool $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): ?string
private static function getPlatformPackageVersion(Pool $pool, string $packageName, string $version): ?string
{
$available = $pool->whatProvides($packageName);
@ -471,7 +471,7 @@ class Problem
* @param int $maxDev
* @return list<string> a list of pretty versions and '...' where versions were removed
*/
private static function condenseVersionList(array $versions, $max, $maxDev = 16): array
private static function condenseVersionList(array $versions, int $max, int $maxDev = 16): array
{
if (count($versions) <= $max) {
return $versions;
@ -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): array
private static function computeCheckForLowerPrioRepo(Pool $pool, bool $isVerbose, string $packageName, array $higherRepoPackages, array $allReposPackages, string $reason, ConstraintInterface $constraint = null): array
{
$nextRepoPackages = array();
$nextRepo = null;

View File

@ -64,7 +64,7 @@ class Request
* @param string $packageName
* @return void
*/
public function requireName($packageName, ConstraintInterface $constraint = null): void
public function requireName(string $packageName, ConstraintInterface $constraint = null): void
{
$packageName = strtolower($packageName);
@ -135,7 +135,7 @@ class Request
* @param false|self::UPDATE_* $updateAllowTransitiveDependencies
* @return void
*/
public function setUpdateAllowList($updateAllowList, $updateAllowTransitiveDependencies): void
public function setUpdateAllowList(array $updateAllowList, $updateAllowTransitiveDependencies): void
{
$this->updateAllowList = $updateAllowList;
$this->updateAllowTransitiveDependencies = $updateAllowTransitiveDependencies;
@ -222,7 +222,7 @@ class Request
* Some locked packages may not be in the pool,
* so they have a package->id of -1
*/
public function getPresentMap($packageIds = false): array
public function getPresentMap(bool $packageIds = false): array
{
$presentMap = array();

View File

@ -267,7 +267,7 @@ abstract class Rule
* @param array<Rule[]> $learnedPool
* @return string
*/
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, array $installedMap = array(), array $learnedPool = array()): string
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, bool $isVerbose, array $installedMap = array(), array $learnedPool = array()): string
{
$literals = $this->getLiterals();
@ -484,7 +484,7 @@ abstract class Rule
* @param bool $useRemovedVersionGroup
* @return string
*/
protected function formatPackagesUnique(Pool $pool, array $packages, $isVerbose, ConstraintInterface $constraint = null, $useRemovedVersionGroup = false): string
protected function formatPackagesUnique(Pool $pool, array $packages, bool $isVerbose, ConstraintInterface $constraint = null, bool $useRemovedVersionGroup = false): string
{
foreach ($packages as $index => $package) {
if (!\is_object($package)) {

View File

@ -31,7 +31,7 @@ class Rule2Literals extends Rule
*
* @phpstan-param ReasonData $reasonData
*/
public function __construct($literal1, $literal2, $reason, $reasonData)
public function __construct(int $literal1, int $literal2, $reason, $reasonData)
{
parent::__construct($reason, $reasonData);

View File

@ -112,7 +112,7 @@ class RuleSet implements \IteratorAggregate, \Countable
* @param int $id
* @return Rule
*/
public function ruleById($id): Rule
public function ruleById(int $id): Rule
{
return $this->ruleById[$id];
}
@ -181,7 +181,7 @@ class RuleSet implements \IteratorAggregate, \Countable
* @param bool $isVerbose
* @return string
*/
public function getPrettyString(RepositorySet $repositorySet = null, Request $request = null, Pool $pool = null, $isVerbose = false): string
public function getPrettyString(RepositorySet $repositorySet = null, Request $request = null, Pool $pool = null, bool $isVerbose = false): string
{
$string = "\n";
foreach ($this->rules as $type => $rules) {

View File

@ -80,7 +80,7 @@ class RuleSetGenerator
* @param BasePackage[] $packages The set of packages to choose from
* @param Rule::RULE_* $reason A RULE_* constant describing the reason for
* generating this rule
* @param array $reasonData Additional data like the root require or fix request info
* @param mixed $reasonData Additional data like the root require or fix request info
* @return Rule The generated rule
*
* @phpstan-param ReasonData $reasonData

View File

@ -29,7 +29,7 @@ class RuleWatchChain extends \SplDoublyLinkedList
* @param int $offset The offset to seek to.
* @return void
*/
public function seek($offset): void
public function seek(int $offset): void
{
$this->rewind();
for ($i = 0; $i < $offset; $i++, $this->next());

View File

@ -88,7 +88,7 @@ class RuleWatchGraph
* register decisions resulting from propagation
* @return Rule|null If a conflict is found the conflicting rule is returned
*/
public function propagateLiteral($decidedLiteral, $level, Decisions $decisions): ?Rule
public function propagateLiteral(int $decidedLiteral, int $level, Decisions $decisions): ?Rule
{
// we invert the decided literal here, example:
// A was decided => (-A|B) now requires B to be true, so we look for
@ -156,7 +156,7 @@ class RuleWatchGraph
* @param RuleWatchNode $node The rule node to be moved
* @return void
*/
protected function moveWatch($fromLiteral, $toLiteral, RuleWatchNode $node): void
protected function moveWatch(int $fromLiteral, int $toLiteral, RuleWatchNode $node): void
{
if (!isset($this->watchChains[$toLiteral])) {
$this->watchChains[$toLiteral] = new RuleWatchChain;

View File

@ -91,7 +91,7 @@ class RuleWatchNode
* @param int $literal The watched literal that should not be returned
* @return int A literal
*/
public function getOtherWatch($literal): int
public function getOtherWatch(int $literal): int
{
if ($this->watch1 == $literal) {
return $this->watch2;
@ -107,7 +107,7 @@ class RuleWatchNode
* @param int $to The literal to be watched now
* @return void
*/
public function moveWatch($from, $to): void
public function moveWatch(int $from, int $to): void
{
if ($this->watch1 == $from) {
$this->watch1 = $to;

View File

@ -233,7 +233,7 @@ class Solver
* @param int $level
* @return Rule|null A rule on conflict, otherwise null.
*/
protected function propagate($level): ?Rule
protected function propagate(int $level): ?Rule
{
while ($this->decisions->validOffset($this->propagateIndex)) {
$decision = $this->decisions->atOffset($this->propagateIndex);
@ -261,7 +261,7 @@ class Solver
*
* @return void
*/
private function revert($level): void
private function revert(int $level): void
{
while (!$this->decisions->isEmpty()) {
$literal = $this->decisions->lastLiteral();
@ -302,7 +302,7 @@ class Solver
* @param string|int $literal
* @return int
*/
private function setPropagateLearn($level, $literal, Rule $rule): int
private function setPropagateLearn(int $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): int
private function selectAndInstall(int $level, array $decisionQueue, Rule $rule): int
{
// choose best package to install from decisionQueue
$literals = $this->policy->selectPreferredPackages($this->pool, $decisionQueue, $rule->getRequiredPackage());
@ -370,7 +370,7 @@ class Solver
* @param int $level
* @return array{int, int, GenericRule, int}
*/
protected function analyze($level, Rule $rule): array
protected function analyze(int $level, Rule $rule): array
{
$analyzedRule = $rule;
$ruleLevel = 1;

View File

@ -20,7 +20,7 @@ class SolverBugException extends \RuntimeException
/**
* @param string $message
*/
public function __construct($message)
public function __construct(string $message)
{
parent::__construct(
$message."\nThis exception was most likely caused by a bug in Composer.\n".

View File

@ -46,7 +46,7 @@ class SolverProblemsException extends \RuntimeException
* @param bool $isDevExtraction
* @return string
*/
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $isDevExtraction = false): string
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, bool $isVerbose, bool $isDevExtraction = false): string
{
$installedMap = $request->getPresentMap(true);
$missingExtensions = array();

View File

@ -50,7 +50,7 @@ class Transaction
* @param PackageInterface[] $presentPackages
* @param PackageInterface[] $resultPackages
*/
public function __construct($presentPackages, $resultPackages)
public function __construct(array $presentPackages, array $resultPackages)
{
$this->presentPackages = $presentPackages;
$this->setResultPackageMaps($resultPackages);
@ -69,7 +69,7 @@ class Transaction
* @param PackageInterface[] $resultPackages
* @return void
*/
private function setResultPackageMaps($resultPackages): void
private function setResultPackageMaps(array $resultPackages): void
{
$packageSort = function (PackageInterface $a, PackageInterface $b): int {
// sort alias packages by the same name behind their non alias version

View File

@ -13,6 +13,7 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Composer\Util\Platform;
use Symfony\Component\Finder\Finder;
use React\Promise\PromiseInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
@ -34,7 +35,7 @@ abstract class ArchiveDownloader extends FileDownloader
/**
* @return PromiseInterface|null
*/
public function prepare($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
unset($this->cleanupExecuted[$package->getName()]);
@ -44,7 +45,7 @@ abstract class ArchiveDownloader extends FileDownloader
/**
* @return PromiseInterface|null
*/
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
$this->cleanupExecuted[$package->getName()] = true;
@ -61,7 +62,7 @@ abstract class ArchiveDownloader extends FileDownloader
* @throws \RuntimeException
* @throws \UnexpectedValueException
*/
public function install(PackageInterface $package, $path, $output = true)
public function install(PackageInterface $package, string $path, bool $output = true)
{
if ($output) {
$this->io->writeError(" - " . InstallOperation::format($package) . $this->getInstallOperationAppendix($package, $path));
@ -83,7 +84,7 @@ abstract class ArchiveDownloader extends FileDownloader
$this->addCleanupPath($package, $temporaryDir);
// avoid cleaning up $path if installing in "." for eg create-project as we can not
// delete the directory we are currently in on windows
if (!is_dir($path) || realpath($path) !== getcwd()) {
if (!is_dir($path) || realpath($path) !== Platform::getCwd()) {
$this->addCleanupPath($package, $path);
}
@ -98,7 +99,7 @@ abstract class ArchiveDownloader extends FileDownloader
// clean up
$filesystem->removeDirectory($temporaryDir);
if (is_dir($path) && realpath($path) !== getcwd()) {
if (is_dir($path) && realpath($path) !== Platform::getCwd()) {
$filesystem->removeDirectory($path);
}
$this->removeCleanupPath($package, $temporaryDir);
@ -214,7 +215,7 @@ abstract class ArchiveDownloader extends FileDownloader
/**
* @inheritDoc
*/
protected function getInstallOperationAppendix(PackageInterface $package, $path)
protected function getInstallOperationAppendix(PackageInterface $package, string $path)
{
return ': Extracting archive';
}
@ -228,5 +229,5 @@ abstract class ArchiveDownloader extends FileDownloader
* @throws \UnexpectedValueException If can not extract downloaded file to path
* @return PromiseInterface|null
*/
abstract protected function extract(PackageInterface $package, $file, $path);
abstract protected function extract(PackageInterface $package, string $file, string $path);
}

View File

@ -28,5 +28,5 @@ interface ChangeReportInterface
* @param string $path package directory
* @return string|null changes or null
*/
public function getLocalChanges(PackageInterface $package, $path);
public function getLocalChanges(PackageInterface $package, string $path);
}

View File

@ -46,7 +46,7 @@ class DownloadManager
* @param bool $preferSource prefer downloading from source
* @param Filesystem|null $filesystem custom Filesystem object
*/
public function __construct(IOInterface $io, $preferSource = false, Filesystem $filesystem = null)
public function __construct(IOInterface $io, bool $preferSource = false, Filesystem $filesystem = null)
{
$this->io = $io;
$this->preferSource = $preferSource;
@ -59,7 +59,7 @@ class DownloadManager
* @param bool $preferSource prefer downloading from source
* @return DownloadManager
*/
public function setPreferSource($preferSource): DownloadManager
public function setPreferSource(bool $preferSource): DownloadManager
{
$this->preferSource = $preferSource;
@ -72,7 +72,7 @@ class DownloadManager
* @param bool $preferDist prefer downloading from dist
* @return DownloadManager
*/
public function setPreferDist($preferDist): DownloadManager
public function setPreferDist(bool $preferDist): DownloadManager
{
$this->preferDist = $preferDist;
@ -100,7 +100,7 @@ class DownloadManager
* @param DownloaderInterface $downloader downloader instance
* @return DownloadManager
*/
public function setDownloader($type, DownloaderInterface $downloader): DownloadManager
public function setDownloader(string $type, DownloaderInterface $downloader): DownloadManager
{
$type = strtolower($type);
$this->downloaders[$type] = $downloader;
@ -115,7 +115,7 @@ class DownloadManager
* @throws \InvalidArgumentException if downloader for provided type is not registered
* @return DownloaderInterface
*/
public function getDownloader($type): DownloaderInterface
public function getDownloader(string $type): DownloaderInterface
{
$type = strtolower($type);
if (!isset($this->downloaders[$type])) {
@ -184,7 +184,7 @@ class DownloadManager
* @throws \RuntimeException
* @return PromiseInterface
*/
public function download(PackageInterface $package, $targetDir, PackageInterface $prevPackage = null): PromiseInterface
public function download(PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$this->filesystem->ensureDirectoryExists(dirname($targetDir));
@ -253,7 +253,7 @@ class DownloadManager
*
* @return PromiseInterface|null
*/
public function prepare($type, PackageInterface $package, $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface
public function prepare(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package);
@ -274,7 +274,7 @@ class DownloadManager
* @throws \RuntimeException
* @return PromiseInterface|null
*/
public function install(PackageInterface $package, $targetDir): ?PromiseInterface
public function install(PackageInterface $package, string $targetDir): ?PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package);
@ -295,7 +295,7 @@ class DownloadManager
* @throws \InvalidArgumentException if initial package is not installed
* @return PromiseInterface|null
*/
public function update(PackageInterface $initial, PackageInterface $target, $targetDir): ?PromiseInterface
public function update(PackageInterface $initial, PackageInterface $target, string $targetDir): ?PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($target);
@ -336,7 +336,7 @@ class DownloadManager
if ($promise instanceof PromiseInterface) {
return $promise;
}
return \React\Promise\resolve();
});
}
@ -352,7 +352,7 @@ class DownloadManager
*
* @return PromiseInterface|null
*/
public function remove(PackageInterface $package, $targetDir): ?PromiseInterface
public function remove(PackageInterface $package, string $targetDir): ?PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package);
@ -373,7 +373,7 @@ class DownloadManager
*
* @return PromiseInterface|null
*/
public function cleanup($type, PackageInterface $package, $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface
public function cleanup(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface
{
$targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package);
@ -461,7 +461,7 @@ class DownloadManager
*
* @return string
*/
private function normalizeTargetDir($dir): string
private function normalizeTargetDir(string $dir): string
{
if ($dir === '\\' || $dir === '/') {
return $dir;

View File

@ -36,7 +36,7 @@ interface DownloaderInterface
* @param string $path download path
* @return PromiseInterface|null
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null);
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null);
/**
* Do anything that needs to be done between all downloads have been completed and the actual operation is executed
@ -52,7 +52,7 @@ interface DownloaderInterface
* @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null
*/
public function prepare($type, PackageInterface $package, $path, PackageInterface $prevPackage = null);
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null);
/**
* Installs specific package into specific folder.
@ -61,7 +61,7 @@ interface DownloaderInterface
* @param string $path download path
* @return PromiseInterface|null
*/
public function install(PackageInterface $package, $path);
public function install(PackageInterface $package, string $path);
/**
* Updates specific package in specific folder from initial to target version.
@ -71,7 +71,7 @@ interface DownloaderInterface
* @param string $path download path
* @return PromiseInterface|null
*/
public function update(PackageInterface $initial, PackageInterface $target, $path);
public function update(PackageInterface $initial, PackageInterface $target, string $path);
/**
* Removes specific package from specific folder.
@ -80,7 +80,7 @@ interface DownloaderInterface
* @param string $path download path
* @return PromiseInterface|null
*/
public function remove(PackageInterface $package, $path);
public function remove(PackageInterface $package, string $path);
/**
* Do anything to cleanup changes applied in the prepare or install/update/uninstall steps
@ -95,5 +95,5 @@ interface DownloaderInterface
* @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null
*/
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null);
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null);
}

View File

@ -28,5 +28,5 @@ interface DvcsDownloaderInterface
* @param string $path package directory
* @return string|null changes or null
*/
public function getUnpushedChanges(PackageInterface $package, $path);
public function getUnpushedChanges(PackageInterface $package, string $path);
}

View File

@ -27,6 +27,7 @@ use Composer\Plugin\PostFileDownloadEvent;
use Composer\Plugin\PreFileDownloadEvent;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\Silencer;
use Composer\Util\HttpDownloader;
use Composer\Util\Url as UrlUtil;
@ -112,7 +113,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
*
* @param bool $output
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true)
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true)
{
if (!$package->getDistUrl()) {
throw new \InvalidArgumentException('The given package is missing url information');
@ -295,7 +296,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/**
* @inheritDoc
*/
public function prepare($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
return \React\Promise\resolve();
}
@ -303,7 +304,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/**
* @inheritDoc
*/
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
$fileName = $this->getFileName($package, $path);
if (file_exists($fileName)) {
@ -323,7 +324,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
}
foreach ($dirsToCleanUp as $dir) {
if (is_dir($dir) && $this->filesystem->isDirEmpty($dir) && realpath($dir) !== getcwd()) {
if (is_dir($dir) && $this->filesystem->isDirEmpty($dir) && realpath($dir) !== Platform::getCwd()) {
$this->filesystem->removeDirectoryPhp($dir);
}
}
@ -336,7 +337,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
*
* @param bool $output
*/
public function install(PackageInterface $package, $path, $output = true)
public function install(PackageInterface $package, string $path, bool $output = true)
{
if ($output) {
$this->io->writeError(" - " . InstallOperation::format($package));
@ -375,7 +376,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
*
* @return void
*/
protected function addCleanupPath(PackageInterface $package, $path)
protected function addCleanupPath(PackageInterface $package, string $path)
{
$this->additionalCleanupPaths[$package->getName()][] = $path;
}
@ -385,7 +386,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
*
* @return void
*/
protected function removeCleanupPath(PackageInterface $package, $path)
protected function removeCleanupPath(PackageInterface $package, string $path)
{
if (isset($this->additionalCleanupPaths[$package->getName()])) {
$idx = array_search($path, $this->additionalCleanupPaths[$package->getName()]);
@ -398,7 +399,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/**
* @inheritDoc
*/
public function update(PackageInterface $initial, PackageInterface $target, $path)
public function update(PackageInterface $initial, PackageInterface $target, string $path)
{
$this->io->writeError(" - " . UpdateOperation::format($initial, $target) . $this->getInstallOperationAppendix($target, $path));
@ -422,7 +423,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
*
* @param bool $output
*/
public function remove(PackageInterface $package, $path, $output = true)
public function remove(PackageInterface $package, string $path, bool $output = true)
{
if ($output) {
$this->io->writeError(" - " . UninstallOperation::format($package));
@ -443,7 +444,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @param string $path download path
* @return string file name
*/
protected function getFileName(PackageInterface $package, $path)
protected function getFileName(PackageInterface $package, string $path)
{
return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_EXTENSION), '.');
}
@ -455,7 +456,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @param string $path download path
* @return string
*/
protected function getInstallOperationAppendix(PackageInterface $package, $path)
protected function getInstallOperationAppendix(PackageInterface $package, string $path)
{
return '';
}
@ -468,7 +469,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @throws \RuntimeException If any problem with the url
* @return string url
*/
protected function processUrl(PackageInterface $package, $url)
protected function processUrl(PackageInterface $package, string $url)
{
if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) {
throw new \RuntimeException('You must enable the openssl extension to download files via https');
@ -485,7 +486,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @inheritDoc
* @throws \RuntimeException
*/
public function getLocalChanges(PackageInterface $package, $targetDir)
public function getLocalChanges(PackageInterface $package, string $targetDir)
{
$prevIO = $this->io;

View File

@ -24,7 +24,7 @@ class FilesystemException extends \Exception
* @param int $code
* @param \Exception|null $previous
*/
public function __construct($message = '', $code = 0, \Exception $previous = null)
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{
parent::__construct("Filesystem exception: \n".$message, $code, $previous);
}

View File

@ -25,7 +25,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null): ?PromiseInterface
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface
{
return \React\Promise\resolve();
}
@ -33,7 +33,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doInstall(PackageInterface $package, $path, $url): ?PromiseInterface
protected function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface
{
// Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io);
@ -61,7 +61,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url): ?PromiseInterface
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface
{
// Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io);
@ -84,7 +84,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
public function getLocalChanges(PackageInterface $package, $path): ?string
public function getLocalChanges(PackageInterface $package, string $path): ?string
{
if (!$this->hasMetadataRepository($path)) {
return null;
@ -98,7 +98,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function getCommitLogs($fromReference, $toReference, $path): string
protected function getCommitLogs(string $fromReference, string $toReference, string $path): string
{
$command = sprintf('fossil timeline -t ci -W 0 -n 0 before %s', ProcessExecutor::escape($toReference));
@ -122,7 +122,7 @@ class FossilDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function hasMetadataRepository($path): bool
protected function hasMetadataRepository(string $path): bool
{
return is_file($path . '/.fslckout') || is_file($path . '/_FOSSIL_');
}

View File

@ -58,7 +58,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null)
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null)
{
GitUtil::cleanEnv();
@ -83,7 +83,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function doInstall(PackageInterface $package, $path, $url)
protected function doInstall(PackageInterface $package, string $path, string $url)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
@ -114,7 +114,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
$this->io->writeError($msg);
$commandCallable = function ($url) use ($path, $command, $cachePath): string {
$commandCallable = function (string $url) use ($path, $command, $cachePath): string {
return str_replace(
array('%url%', '%path%', '%cachePath%', '%sanitizedUrl%'),
array(
@ -148,7 +148,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
@ -213,7 +213,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
public function getLocalChanges(PackageInterface $package, $path)
public function getLocalChanges(PackageInterface $package, string $path)
{
GitUtil::cleanEnv();
if (!$this->hasMetadataRepository($path)) {
@ -231,7 +231,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @return null|string
*/
public function getUnpushedChanges(PackageInterface $package, $path)
public function getUnpushedChanges(PackageInterface $package, string $path)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
@ -328,7 +328,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function cleanChanges(PackageInterface $package, $path, $update)
protected function cleanChanges(PackageInterface $package, string $path, bool $update)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
@ -415,7 +415,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function reapplyChanges($path)
protected function reapplyChanges(string $path)
{
$path = $this->normalizePath($path);
if (!empty($this->hasStashedChanges[$path])) {
@ -438,7 +438,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* @throws \RuntimeException
* @return null|string if a string is returned, it is the commit reference that was checked out if the original could not be found
*/
protected function updateToCommit(PackageInterface $package, $path, $reference, $prettyVersion)
protected function updateToCommit(PackageInterface $package, string $path, string $reference, string $prettyVersion)
{
$force = !empty($this->hasDiscardedChanges[$path]) || !empty($this->hasStashedChanges[$path]) ? '-f ' : '';
@ -505,7 +505,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @return void
*/
protected function updateOriginUrl($path, $url)
protected function updateOriginUrl(string $path, string $url)
{
$this->process->execute(sprintf('git remote set-url origin -- %s', ProcessExecutor::escape($url)), $output, $path);
$this->setPushUrl($path, $url);
@ -517,7 +517,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @return void
*/
protected function setPushUrl($path, $url)
protected function setPushUrl(string $path, string $url)
{
// set push url for github projects
if (Preg::isMatch('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) {
@ -534,7 +534,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function getCommitLogs($fromReference, $toReference, $path)
protected function getCommitLogs(string $fromReference, string $toReference, string $path)
{
$path = $this->normalizePath($path);
$command = sprintf('git log %s..%s --pretty=format:"%%h - %%an: %%s"'.GitUtil::getNoShowSignatureFlag($this->process), ProcessExecutor::escape($fromReference), ProcessExecutor::escape($toReference));
@ -553,7 +553,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @throws \RuntimeException
*/
protected function discardChanges($path)
protected function discardChanges(string $path)
{
$path = $this->normalizePath($path);
if (0 !== $this->process->execute('git clean -df && git reset --hard', $output, $path)) {
@ -572,7 +572,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @throws \RuntimeException
*/
protected function stashChanges($path)
protected function stashChanges(string $path)
{
$path = $this->normalizePath($path);
if (0 !== $this->process->execute('git stash --include-untracked', $output, $path)) {
@ -591,7 +591,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @throws \RuntimeException
*/
protected function viewDiff($path)
protected function viewDiff(string $path)
{
$path = $this->normalizePath($path);
if (0 !== $this->process->execute('git diff HEAD', $output, $path)) {
@ -606,7 +606,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
*
* @return string
*/
protected function normalizePath($path)
protected function normalizePath(string $path)
{
if (Platform::isWindows() && strlen($path) > 0) {
$basePath = $path;
@ -630,7 +630,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/**
* @inheritDoc
*/
protected function hasMetadataRepository($path)
protected function hasMetadataRepository(string $path)
{
$path = $this->normalizePath($path);
@ -641,7 +641,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* @param string $reference
* @return string
*/
protected function getShortHash($reference)
protected function getShortHash(string $reference)
{
if (!$this->io->isVerbose() && Preg::isMatch('{^[0-9a-f]{40}$}', $reference)) {
return substr($reference, 0, 10);

View File

@ -24,7 +24,7 @@ use Composer\Util\ProcessExecutor;
*/
class GzipDownloader extends ArchiveDownloader
{
protected function extract(PackageInterface $package, $file, $path): ?PromiseInterface
protected function extract(PackageInterface $package, string $file, string $path): ?PromiseInterface
{
$filename = pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_FILENAME);
$targetFilepath = $path . DIRECTORY_SEPARATOR . $filename;
@ -60,7 +60,7 @@ class GzipDownloader extends ArchiveDownloader
*
* @return void
*/
private function extractUsingExt($file, $targetFilepath): void
private function extractUsingExt(string $file, string $targetFilepath): void
{
$archiveFile = gzopen($file, 'rb');
$targetFile = fopen($targetFilepath, 'wb');

View File

@ -25,7 +25,7 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null): ?PromiseInterface
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface
{
if (null === HgUtils::getVersion($this->process)) {
throw new \RuntimeException('hg was not found in your PATH, skipping source download');
@ -37,11 +37,11 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doInstall(PackageInterface $package, $path, $url): ?PromiseInterface
protected function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface
{
$hgUtils = new HgUtils($this->io, $this->config, $this->process);
$cloneCommand = function ($url) use ($path): string {
$cloneCommand = function (string $url) use ($path): string {
return sprintf('hg clone -- %s %s', ProcessExecutor::escape($url), ProcessExecutor::escape($path));
};
@ -59,7 +59,7 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url): ?PromiseInterface
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface
{
$hgUtils = new HgUtils($this->io, $this->config, $this->process);
@ -82,7 +82,7 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
public function getLocalChanges(PackageInterface $package, $path): ?string
public function getLocalChanges(PackageInterface $package, string $path): ?string
{
if (!is_dir($path.'/.hg')) {
return null;
@ -96,7 +96,7 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function getCommitLogs($fromReference, $toReference, $path): string
protected function getCommitLogs(string $fromReference, string $toReference, string $path): string
{
$command = sprintf('hg log -r %s:%s --style compact', ProcessExecutor::escape($fromReference), ProcessExecutor::escape($toReference));
@ -110,7 +110,7 @@ class HgDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function hasMetadataRepository($path): bool
protected function hasMetadataRepository(string $path): bool
{
return is_dir($path . '/.hg');
}

View File

@ -39,7 +39,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/**
* @inheritDoc
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true): ?PromiseInterface
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true): ?PromiseInterface
{
$path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl();
@ -75,7 +75,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/**
* @inheritDoc
*/
public function install(PackageInterface $package, $path, $output = true): ?PromiseInterface
public function install(PackageInterface $package, string $path, bool $output = true): ?PromiseInterface
{
$path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl();
@ -113,7 +113,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
} else {
$absolutePath = $path;
if (!$this->filesystem->isAbsolutePath($absolutePath)) {
$absolutePath = getcwd() . DIRECTORY_SEPARATOR . $path;
$absolutePath = Platform::getCwd() . DIRECTORY_SEPARATOR . $path;
}
$shortestPath = $this->filesystem->findShortestPath($absolutePath, $realUrl);
$path = rtrim($path, "/");
@ -161,7 +161,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/**
* @inheritDoc
*/
public function remove(PackageInterface $package, $path, $output = true): ?PromiseInterface
public function remove(PackageInterface $package, string $path, bool $output = true): ?PromiseInterface
{
$path = Filesystem::trimTrailingSlash($path);
/**
@ -190,8 +190,8 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
// not using realpath here as we do not want to resolve the symlink to the original dist url
// it points to
$fs = new Filesystem;
$absPath = $fs->isAbsolutePath($path) ? $path : getcwd() . '/' . $path;
$absDistUrl = $fs->isAbsolutePath($package->getDistUrl()) ? $package->getDistUrl() : getcwd() . '/' . $package->getDistUrl();
$absPath = $fs->isAbsolutePath($path) ? $path : Platform::getCwd() . '/' . $path;
$absDistUrl = $fs->isAbsolutePath($package->getDistUrl()) ? $package->getDistUrl() : Platform::getCwd() . '/' . $package->getDistUrl();
if ($fs->normalizePath($absPath) === $fs->normalizePath($absDistUrl)) {
if ($output) {
$this->io->writeError(" - " . UninstallOperation::format($package).", source is still present in $path");
@ -206,7 +206,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/**
* @inheritDoc
*/
public function getVcsReference(PackageInterface $package, $path): ?string
public function getVcsReference(PackageInterface $package, string $path): ?string
{
$path = Filesystem::trimTrailingSlash($path);
$parser = new VersionParser;
@ -224,7 +224,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/**
* @inheritDoc
*/
protected function getInstallOperationAppendix(PackageInterface $package, $path): string
protected function getInstallOperationAppendix(PackageInterface $package, string $path): string
{
$realUrl = realpath($package->getDistUrl());

View File

@ -28,7 +28,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null): ?PromiseInterface
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface
{
return \React\Promise\resolve();
}
@ -36,7 +36,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
public function doInstall(PackageInterface $package, $path, $url): ?PromiseInterface
public function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface
{
$ref = $package->getSourceReference();
$label = $this->getLabelFromSourceReference((string) $ref);
@ -58,7 +58,7 @@ class PerforceDownloader extends VcsDownloader
*
* @return string|null
*/
private function getLabelFromSourceReference($ref): ?string
private function getLabelFromSourceReference(string $ref): ?string
{
$pos = strpos($ref, '@');
if (false !== $pos) {
@ -74,7 +74,7 @@ class PerforceDownloader extends VcsDownloader
*
* @return void
*/
public function initPerforce(PackageInterface $package, $path, $url): void
public function initPerforce(PackageInterface $package, string $path, string $url): void
{
if (!empty($this->perforce)) {
$this->perforce->initializePath($path);
@ -101,7 +101,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url): ?PromiseInterface
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface
{
return $this->doInstall($target, $path, $url);
}
@ -109,7 +109,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
public function getLocalChanges(PackageInterface $package, $path): ?string
public function getLocalChanges(PackageInterface $package, string $path): ?string
{
$this->io->writeError('Perforce driver does not check for local changes before overriding');
@ -119,7 +119,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function getCommitLogs($fromReference, $toReference, $path): string
protected function getCommitLogs(string $fromReference, string $toReference, string $path): string
{
return $this->perforce->getCommitLogs($fromReference, $toReference);
}
@ -135,7 +135,7 @@ class PerforceDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function hasMetadataRepository($path): bool
protected function hasMetadataRepository(string $path): bool
{
return true;
}

View File

@ -25,7 +25,7 @@ class PharDownloader extends ArchiveDownloader
/**
* @inheritDoc
*/
protected function extract(PackageInterface $package, $file, $path): ?PromiseInterface
protected function extract(PackageInterface $package, string $file, string $path): ?PromiseInterface
{
// Can throw an UnexpectedValueException
$archive = new \Phar($file);

View File

@ -28,7 +28,7 @@ use RarArchive;
*/
class RarDownloader extends ArchiveDownloader
{
protected function extract(PackageInterface $package, $file, $path): ?PromiseInterface
protected function extract(PackageInterface $package, string $file, string $path): ?PromiseInterface
{
$processError = null;

View File

@ -31,7 +31,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null)
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null)
{
SvnUtil::cleanEnv();
$util = new SvnUtil($url, $this->io, $this->config, $this->process);
@ -45,7 +45,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doInstall(PackageInterface $package, $path, $url)
protected function doInstall(PackageInterface $package, string $path, string $url)
{
SvnUtil::cleanEnv();
$ref = $package->getSourceReference();
@ -67,7 +67,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url)
{
SvnUtil::cleanEnv();
$ref = $target->getSourceReference();
@ -91,7 +91,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
public function getLocalChanges(PackageInterface $package, $path)
public function getLocalChanges(PackageInterface $package, string $path)
{
if (!$this->hasMetadataRepository($path)) {
return null;
@ -114,7 +114,7 @@ class SvnDownloader extends VcsDownloader
* @throws \RuntimeException
* @return string
*/
protected function execute(PackageInterface $package, $baseUrl, $command, $url, $cwd = null, $path = null)
protected function execute(PackageInterface $package, string $baseUrl, string $command, string $url, string $cwd = null, string $path = null)
{
$util = new SvnUtil($baseUrl, $this->io, $this->config, $this->process);
$util->setCacheCredentials($this->cacheCredentials);
@ -130,7 +130,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function cleanChanges(PackageInterface $package, $path, $update)
protected function cleanChanges(PackageInterface $package, string $path, bool $update)
{
if (!$changes = $this->getLocalChanges($package, $path)) {
return \React\Promise\resolve();
@ -191,7 +191,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function getCommitLogs($fromReference, $toReference, $path)
protected function getCommitLogs(string $fromReference, string $toReference, string $path)
{
if (Preg::isMatch('{@(\d+)$}', $fromReference) && Preg::isMatch('{@(\d+)$}', $toReference)) {
// retrieve the svn base url from the checkout folder
@ -236,7 +236,7 @@ class SvnDownloader extends VcsDownloader
*
* @return PromiseInterface
*/
protected function discardChanges($path)
protected function discardChanges(string $path)
{
if (0 !== $this->process->execute('svn revert -R .', $output, $path)) {
throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
@ -248,7 +248,7 @@ class SvnDownloader extends VcsDownloader
/**
* @inheritDoc
*/
protected function hasMetadataRepository($path)
protected function hasMetadataRepository(string $path)
{
return is_dir($path.'/.svn');
}

View File

@ -24,7 +24,7 @@ class TarDownloader extends ArchiveDownloader
/**
* @inheritDoc
*/
protected function extract(PackageInterface $package, $file, $path)
protected function extract(PackageInterface $package, string $file, string $path)
{
// Can throw an UnexpectedValueException
$archive = new \PharData($file);

View File

@ -31,7 +31,7 @@ class TransportException extends \RuntimeException
*
* @return void
*/
public function setHeaders($headers): void
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}
@ -45,11 +45,11 @@ class TransportException extends \RuntimeException
}
/**
* @param ?string $response
* @param null|string $response
*
* @return void
*/
public function setResponse($response): void
public function setResponse(?string $response): void
{
$this->response = $response;
}

View File

@ -28,5 +28,5 @@ interface VcsCapableDownloaderInterface
* @param string $path package directory
* @return string|null reference or null
*/
public function getVcsReference(PackageInterface $package, $path);
public function getVcsReference(PackageInterface $package, string $path);
}

View File

@ -60,7 +60,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
if (!$package->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
@ -93,7 +93,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function prepare($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
if ($type === 'update') {
$this->cleanChanges($prevPackage, $path, true);
@ -110,7 +110,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null)
{
if ($type === 'update' && isset($this->hasCleanedChanges[$prevPackage->getUniqueName()])) {
$this->reapplyChanges($path);
@ -123,7 +123,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function install(PackageInterface $package, $path)
public function install(PackageInterface $package, string $path)
{
if (!$package->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
@ -158,7 +158,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function update(PackageInterface $initial, PackageInterface $target, $path)
public function update(PackageInterface $initial, PackageInterface $target, string $path)
{
if (!$target->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
@ -194,12 +194,12 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$message = 'Pulling in changes:';
$logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
if (!trim($logs)) {
if ('' === trim($logs)) {
$message = 'Rolling back changes:';
$logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path);
}
if (trim($logs)) {
if ('' !== trim($logs)) {
$logs = implode("\n", array_map(function ($line): string {
return ' ' . $line;
}, explode("\n", $logs)));
@ -222,13 +222,13 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function remove(PackageInterface $package, $path)
public function remove(PackageInterface $package, string $path)
{
$this->io->writeError(" - " . UninstallOperation::format($package));
$promise = $this->filesystem->removeDirectoryAsync($path);
return $promise->then(function ($result) use ($path) {
return $promise->then(function (bool $result) use ($path) {
if (!$result) {
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
}
@ -238,7 +238,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/**
* @inheritDoc
*/
public function getVcsReference(PackageInterface $package, $path)
public function getVcsReference(PackageInterface $package, string $path)
{
$parser = new VersionParser;
$guesser = new VersionGuesser($this->config, $this->process, $parser);
@ -264,7 +264,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
*
* @throws \RuntimeException in case the operation must be aborted
*/
protected function cleanChanges(PackageInterface $package, $path, $update)
protected function cleanChanges(PackageInterface $package, string $path, bool $update)
{
// the default implementation just fails if there are any changes, override in child classes to provide stash-ability
if (null !== $this->getLocalChanges($package, $path)) {
@ -283,7 +283,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
*
* @throws \RuntimeException in case the operation must be aborted or the patch does not apply cleanly
*/
protected function reapplyChanges($path)
protected function reapplyChanges(string $path)
{
}
@ -297,7 +297,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
*
* @return PromiseInterface|null
*/
abstract protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null);
abstract protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null);
/**
* Downloads specific package into specific folder.
@ -308,7 +308,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
*
* @return PromiseInterface|null
*/
abstract protected function doInstall(PackageInterface $package, $path, $url);
abstract protected function doInstall(PackageInterface $package, string $path, string $url);
/**
* Updates specific package in specific folder from initial to target version.
@ -320,7 +320,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
*
* @return PromiseInterface|null
*/
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url);
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url);
/**
* Fetches the commit logs between two commits
@ -330,7 +330,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path the package path
* @return string
*/
abstract protected function getCommitLogs($fromReference, $toReference, $path);
abstract protected function getCommitLogs(string $fromReference, string $toReference, string $path);
/**
* Checks if VCS metadata repository has been initialized
@ -339,7 +339,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path
* @return bool
*/
abstract protected function hasMetadataRepository($path);
abstract protected function hasMetadataRepository(string $path);
/**
* @param string[] $urls

View File

@ -24,7 +24,7 @@ use Composer\Util\ProcessExecutor;
*/
class XzDownloader extends ArchiveDownloader
{
protected function extract(PackageInterface $package, $file, $path): ?PromiseInterface
protected function extract(PackageInterface $package, string $file, string $path): ?PromiseInterface
{
$command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);

View File

@ -17,6 +17,7 @@ use Composer\Util\IniHelper;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
use React\Promise\PromiseInterface;
use ZipArchive;
@ -38,7 +39,7 @@ class ZipDownloader extends ArchiveDownloader
/**
* @inheritDoc
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true)
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true)
{
if (null === self::$unzipCommands) {
self::$unzipCommands = array();
@ -105,7 +106,7 @@ class ZipDownloader extends ArchiveDownloader
* @param string $path Path where to extract file
* @return PromiseInterface
*/
private function extractWithSystemUnzip(PackageInterface $package, $file, $path): PromiseInterface
private function extractWithSystemUnzip(PackageInterface $package, string $file, string $path): PromiseInterface
{
// Force Exception throwing if the other alternative extraction method is not available
$isLastChance = !self::$hasZipArchive;
@ -127,7 +128,7 @@ class ZipDownloader extends ArchiveDownloader
$executable = $commandSpec[0];
$io = $this->io;
$tryFallback = function ($processError) use ($isLastChance, $io, $file, $path, $package, $executable): \React\Promise\PromiseInterface {
$tryFallback = function (\Throwable $processError) use ($isLastChance, $io, $file, $path, $package, $executable): \React\Promise\PromiseInterface {
if ($isLastChance) {
throw $processError;
}
@ -148,7 +149,7 @@ class ZipDownloader extends ArchiveDownloader
try {
$promise = $this->process->executeAsync($command);
return $promise->then(function ($process) use ($tryFallback, $command, $package, $file) {
return $promise->then(function (Process $process) use ($tryFallback, $command, $package, $file) {
if (!$process->isSuccessful()) {
if (isset($this->cleanupExecuted[$package->getName()])) {
throw new \RuntimeException('Failed to extract '.$package->getName().' as the installation was aborted by another package operation.');
@ -172,7 +173,7 @@ class ZipDownloader extends ArchiveDownloader
* @param string $path Path where to extract file
* @return PromiseInterface
*/
private function extractWithZipArchive(PackageInterface $package, $file, $path): PromiseInterface
private function extractWithZipArchive(PackageInterface $package, string $file, string $path): PromiseInterface
{
$processError = null;
$zipArchive = $this->zipArchiveObject ?: new ZipArchive();
@ -207,7 +208,7 @@ class ZipDownloader extends ArchiveDownloader
* @param string $path Path where to extract file
* @return PromiseInterface|null
*/
protected function extract(PackageInterface $package, $file, $path)
protected function extract(PackageInterface $package, string $file, string $path)
{
return $this->extractWithSystemUnzip($package, $file, $path);
}
@ -219,7 +220,7 @@ class ZipDownloader extends ArchiveDownloader
* @param string $file
* @return string
*/
protected function getErrorMessage($retval, $file)
protected function getErrorMessage(int $retval, string $file): string
{
switch ($retval) {
case ZipArchive::ER_EXISTS:

View File

@ -46,7 +46,7 @@ class Event
* @param string[] $args Arguments passed by the user
* @param mixed[] $flags Optional flags to pass data not as argument
*/
public function __construct($name, array $args = array(), array $flags = array())
public function __construct(string $name, array $args = array(), array $flags = array())
{
$this->name = $name;
$this->args = $args;

View File

@ -12,7 +12,6 @@
namespace Composer\EventDispatcher;
use Composer\Autoload\AutoloadGenerator;
use Composer\DependencyResolver\Transaction;
use Composer\Installer\InstallerEvent;
use Composer\IO\IOInterface;
@ -82,7 +81,7 @@ class EventDispatcher
* @param bool $runScripts
* @return $this
*/
public function setRunScripts($runScripts = true)
public function setRunScripts(bool $runScripts = true)
{
$this->runScripts = (bool) $runScripts;
@ -97,7 +96,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatch($eventName, Event $event = null)
public function dispatch(string $eventName, Event $event = null)
{
if (null === $event) {
$event = new Event($eventName);
@ -116,7 +115,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatchScript($eventName, $devMode = false, $additionalArgs = array(), $flags = array())
public function dispatchScript(string $eventName, bool $devMode = false, array $additionalArgs = array(), array $flags = array())
{
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -135,7 +134,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatchPackageEvent($eventName, $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation)
public function dispatchPackageEvent(string $eventName, bool $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation)
{
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -153,7 +152,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatchInstallerEvent($eventName, $devMode, $executeOperations, Transaction $transaction)
public function dispatchInstallerEvent(string $eventName, bool $devMode, bool $executeOperations, Transaction $transaction)
{
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -343,7 +342,7 @@ class EventDispatcher
*
* @return int
*/
protected function executeTty($exec)
protected function executeTty(string $exec)
{
if ($this->io->isInteractive()) {
return $this->process->executeTty($exec);
@ -378,7 +377,7 @@ class EventDispatcher
*
* @return mixed
*/
protected function executeEventPhpScript($className, $methodName, Event $event)
protected function executeEventPhpScript(string $className, string $methodName, Event $event)
{
if ($this->io->isVerbose()) {
$this->io->writeError(sprintf('> %s: %s::%s', $event->getName(), $className, $methodName));
@ -398,7 +397,7 @@ class EventDispatcher
*
* @return void
*/
public function addListener($eventName, $listener, $priority = 0)
public function addListener(string $eventName, callable $listener, int $priority = 0)
{
$this->listeners[$eventName][$priority][] = $listener;
}
@ -520,7 +519,7 @@ class EventDispatcher
* @param string $callable
* @return bool
*/
protected function isPhpScript($callable)
protected function isPhpScript(string $callable)
{
return false === strpos($callable, ' ') && false !== strpos($callable, '::');
}
@ -531,7 +530,7 @@ class EventDispatcher
* @param string $callable
* @return bool
*/
protected function isComposerScript($callable)
protected function isComposerScript(string $callable)
{
return strpos($callable, '@') === 0 && strpos($callable, '@php ') !== 0 && strpos($callable, '@putenv ') !== 0;
}

View File

@ -164,7 +164,7 @@ class Factory
public static function createConfig(IOInterface $io = null, ?string $cwd = null): Config
{
$cwd = $cwd ?: (string) getcwd();
$cwd = $cwd ?? Platform::getCwd(true);
$config = new Config(true, $cwd);
@ -278,7 +278,7 @@ class Factory
*/
public function createComposer(IOInterface $io, $localConfig = null, bool $disablePlugins = false, ?string $cwd = null, bool $fullLoad = true, bool $disableScripts = false)
{
$cwd = $cwd ?: (string) getcwd();
$cwd = $cwd ?? Platform::getCwd(true);
// load Composer configuration
if (null === $localConfig) {
@ -454,7 +454,7 @@ class Factory
*
* @return void
*/
protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $vendorDir, RootPackageInterface $rootPackage, ProcessExecutor $process = null): void
protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, string $vendorDir, RootPackageInterface $rootPackage, ProcessExecutor $process = null): void
{
$fs = null;
if ($process) {
@ -621,7 +621,7 @@ class Factory
* @param mixed[] $options Array of options passed directly to HttpDownloader constructor
* @return HttpDownloader
*/
public static function createHttpDownloader(IOInterface $io, Config $config, $options = array()): HttpDownloader
public static function createHttpDownloader(IOInterface $io, Config $config, array $options = array()): HttpDownloader
{
static $warned = false;
$disableTls = false;

View File

@ -20,7 +20,7 @@ final class IgnoreAllPlatformRequirementFilter implements PlatformRequirementFil
* @param string $req
* @return bool
*/
public function isIgnored($req): bool
public function isIgnored(string $req): bool
{
return PlatformRepository::isPlatformPackage($req);
}

View File

@ -55,7 +55,7 @@ final class IgnoreListPlatformRequirementFilter implements PlatformRequirementFi
* @param string $req
* @return bool
*/
public function isIgnored($req): bool
public function isIgnored(string $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): ConstraintInterface
public function filterConstraint(string $req, ConstraintInterface $constraint): ConstraintInterface
{
if (!PlatformRepository::isPlatformPackage($req)) {
return $constraint;

View File

@ -18,7 +18,7 @@ final class IgnoreNothingPlatformRequirementFilter implements PlatformRequiremen
* @param string $req
* @return false
*/
public function isIgnored($req): bool
public function isIgnored(string $req): bool
{
return false;
}

View File

@ -18,5 +18,5 @@ interface PlatformRequirementFilterInterface
* @param string $req
* @return bool
*/
public function isIgnored($req): bool;
public function isIgnored(string $req): bool;
}

View File

@ -69,7 +69,7 @@ abstract class BaseIO implements IOInterface
/**
* @inheritDoc
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL)
public function writeRaw($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->write($messages, $newline, $verbosity);
}
@ -77,7 +77,7 @@ abstract class BaseIO implements IOInterface
/**
* @inheritDoc
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL)
public function writeErrorRaw($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->writeError($messages, $newline, $verbosity);
}
@ -91,7 +91,7 @@ abstract class BaseIO implements IOInterface
*
* @return void
*/
protected function checkAndSetAuthentication($repositoryName, $username, $password = null)
protected function checkAndSetAuthentication(string $repositoryName, string $username, string $password = null)
{
if ($this->hasAuthentication($repositoryName)) {
$auth = $this->getAuthentication($repositoryName);

View File

@ -35,7 +35,7 @@ class BufferIO extends ConsoleIO
* @param int $verbosity
* @param OutputFormatterInterface|null $formatter
*/
public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null)
public function __construct(string $input = '', int $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null)
{
$input = new StringInput($input);
$input->setInteractive(false);

View File

@ -71,7 +71,7 @@ class ConsoleIO extends BaseIO
*
* @return void
*/
public function enableDebugging($startTime)
public function enableDebugging(float $startTime)
{
$this->startTime = $startTime;
}
@ -119,7 +119,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function write($messages, $newline = true, $verbosity = self::NORMAL)
public function write($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, false, $verbosity);
}
@ -127,7 +127,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function writeError($messages, $newline = true, $verbosity = self::NORMAL)
public function writeError($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, true, $verbosity);
}
@ -135,7 +135,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL)
public function writeRaw($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, false, $verbosity, true);
}
@ -143,7 +143,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL)
public function writeErrorRaw($messages, bool $newline = true, int $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, true, $verbosity, true);
}
@ -157,7 +157,7 @@ class ConsoleIO extends BaseIO
*
* @return void
*/
private function doWrite($messages, $newline, $stderr, $verbosity, $raw = false): void
private function doWrite($messages, bool $newline, bool $stderr, int $verbosity, bool $raw = false): void
{
$sfVerbosity = $this->verbosityMap[$verbosity];
if ($sfVerbosity > $this->output->getVerbosity()) {
@ -194,7 +194,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function overwrite($messages, $newline = true, $size = null, $verbosity = self::NORMAL)
public function overwrite($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL)
{
$this->doOverwrite($messages, $newline, $size, false, $verbosity);
}
@ -202,7 +202,7 @@ class ConsoleIO extends BaseIO
/**
* @inheritDoc
*/
public function overwriteError($messages, $newline = true, $size = null, $verbosity = self::NORMAL)
public function overwriteError($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL)
{
$this->doOverwrite($messages, $newline, $size, true, $verbosity);
}
@ -216,7 +216,7 @@ class ConsoleIO extends BaseIO
*
* @return void
*/
private function doOverwrite($messages, $newline, $size, $stderr, $verbosity): void
private function doOverwrite($messages, bool $newline, ?int $size, bool $stderr, int $verbosity): void
{
// messages can be an array, let's convert it to string anyway
$messages = implode($newline ? "\n" : '', (array) $messages);
@ -258,7 +258,7 @@ class ConsoleIO extends BaseIO
* @param int $max
* @return ProgressBar
*/
public function getProgressBar($max = 0)
public function getProgressBar(int $max = 0)
{
return new ProgressBar($this->getErrorOutput(), $max);
}

View File

@ -72,7 +72,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function write($messages, $newline = true, $verbosity = self::NORMAL);
public function write($messages, bool $newline = true, int $verbosity = self::NORMAL);
/**
* Writes a message to the error output.
@ -83,7 +83,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function writeError($messages, $newline = true, $verbosity = self::NORMAL);
public function writeError($messages, bool $newline = true, int $verbosity = self::NORMAL);
/**
* Writes a message to the output, without formatting it.
@ -94,7 +94,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL);
public function writeRaw($messages, bool $newline = true, int $verbosity = self::NORMAL);
/**
* Writes a message to the error output, without formatting it.
@ -105,7 +105,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL);
public function writeErrorRaw($messages, bool $newline = true, int $verbosity = self::NORMAL);
/**
* Overwrites a previous message to the output.
@ -117,7 +117,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function overwrite($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
public function overwrite($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL);
/**
* Overwrites a previous message to the error output.
@ -129,7 +129,7 @@ interface IOInterface extends LoggerInterface
*
* @return void
*/
public function overwriteError($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
public function overwriteError($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL);
/**
* Asks a question to the user.
@ -140,7 +140,7 @@ interface IOInterface extends LoggerInterface
* @throws \RuntimeException If there is no data to read in the input stream
* @return mixed The user answer
*/
public function ask($question, $default = null);
public function ask(string $question, $default = null);
/**
* Asks a confirmation to the user.
@ -152,7 +152,7 @@ interface IOInterface extends LoggerInterface
*
* @return bool true if the user has confirmed, false otherwise
*/
public function askConfirmation($question, $default = true);
public function askConfirmation(string $question, bool $default = true);
/**
* Asks for a value and validates the response.
@ -169,7 +169,7 @@ interface IOInterface extends LoggerInterface
* @throws \Exception When any of the validators return an error
* @return mixed
*/
public function askAndValidate($question, $validator, $attempts = null, $default = null);
public function askAndValidate(string $question, callable $validator, ?int $attempts = null, $default = null);
/**
* Asks a question to the user and hide the answer.
@ -178,7 +178,7 @@ interface IOInterface extends LoggerInterface
*
* @return string|null The answer
*/
public function askAndHideAnswer($question);
public function askAndHideAnswer(string $question);
/**
* Asks the user to select a value.
@ -193,7 +193,7 @@ interface IOInterface extends LoggerInterface
* @throws \InvalidArgumentException
* @return int|string|string[]|bool The selected value or values (the key of the choices array)
*/
public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);
public function select(string $question, array $choices, $default, $attempts = false, string $errorMessage = 'Value "%s" is invalid', bool $multiselect = false);
/**
* Get all authentication information entered.
@ -209,7 +209,7 @@ interface IOInterface extends LoggerInterface
*
* @return bool
*/
public function hasAuthentication($repositoryName);
public function hasAuthentication(string $repositoryName);
/**
* Get the username and password of repository.
@ -218,18 +218,18 @@ interface IOInterface extends LoggerInterface
*
* @return array{username: string|null, password: string|null}
*/
public function getAuthentication($repositoryName);
public function getAuthentication(string $repositoryName);
/**
* Set the authentication information for the repository.
*
* @param string $repositoryName The unique name of repository
* @param string $username The username
* @param ?string $password The password
* @param string $repositoryName The unique name of repository
* @param string $username The username
* @param null|string $password The password
*
* @return void
*/
public function setAuthentication($repositoryName, $username, $password = null);
public function setAuthentication(string $repositoryName, string $username, ?string $password = null);
/**
* Loads authentications from a config instance

View File

@ -62,28 +62,28 @@ class NullIO extends BaseIO
/**
* @inheritDoc
*/
public function write($messages, $newline = true, $verbosity = self::NORMAL): void
public function write($messages, bool $newline = true, int $verbosity = self::NORMAL): void
{
}
/**
* @inheritDoc
*/
public function writeError($messages, $newline = true, $verbosity = self::NORMAL): void
public function writeError($messages, bool $newline = true, int $verbosity = self::NORMAL): void
{
}
/**
* @inheritDoc
*/
public function overwrite($messages, $newline = true, $size = 80, $verbosity = self::NORMAL): void
public function overwrite($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL): void
{
}
/**
* @inheritDoc
*/
public function overwriteError($messages, $newline = true, $size = 80, $verbosity = self::NORMAL): void
public function overwriteError($messages, bool $newline = true, ?int $size = null, int $verbosity = self::NORMAL): void
{
}

View File

@ -386,7 +386,7 @@ class Installer
* @return int
* @phpstan-return self::ERROR_*
*/
protected function doUpdate(InstalledRepositoryInterface $localRepo, $doInstall): int
protected function doUpdate(InstalledRepositoryInterface $localRepo, bool $doInstall): int
{
$platformRepo = $this->createPlatformRepo(true);
$aliases = $this->getRootAliases(true);
@ -648,7 +648,7 @@ class Installer
* @return int exit code
* @phpstan-return self::ERROR_*
*/
protected function doInstall(InstalledRepositoryInterface $localRepo, $alreadySolved = false): int
protected function doInstall(InstalledRepositoryInterface $localRepo, bool $alreadySolved = false): int
{
$this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
@ -769,7 +769,7 @@ class Installer
*
* @return PlatformRepository
*/
protected function createPlatformRepo($forUpdate): PlatformRepository
protected function createPlatformRepo(bool $forUpdate): PlatformRepository
{
if ($forUpdate) {
$platformOverrides = $this->config->get('platform') ?: array();
@ -789,7 +789,7 @@ class Installer
*
* @phpstan-param list<array{package: string, version: string, alias: string, alias_normalized: string}> $rootAliases
*/
private function createRepositorySet($forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null): RepositorySet
private function createRepositorySet(bool $forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), ?RepositoryInterface $lockedRepository = null): RepositorySet
{
if ($forUpdate) {
$minimumStability = $this->package->getMinimumStability();
@ -858,7 +858,7 @@ class Installer
*
* @return DefaultPolicy
*/
private function createPolicy($forUpdate): DefaultPolicy
private function createPolicy(bool $forUpdate): DefaultPolicy
{
$preferStable = null;
$preferLowest = null;
@ -919,7 +919,7 @@ class Installer
*
* @return void
*/
private function requirePackagesForUpdate(Request $request, LockArrayRepository $lockedRepository = null, $includeDevRequires = true): void
private function requirePackagesForUpdate(Request $request, LockArrayRepository $lockedRepository = null, bool $includeDevRequires = true): void
{
// if we're updating mirrors we want to keep exactly the same versions installed which are in the lock file, but we want current remote metadata
if ($this->updateMirrors) {
@ -953,7 +953,7 @@ class Installer
*
* @phpstan-return list<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
private function getRootAliases($forUpdate): array
private function getRootAliases(bool $forUpdate): array
{
if ($forUpdate) {
$aliases = $this->package->getAliases();
@ -1062,7 +1062,7 @@ class Installer
* @param bool $dryRun
* @return Installer
*/
public function setDryRun($dryRun = true): Installer
public function setDryRun(bool $dryRun = true): Installer
{
$this->dryRun = (bool) $dryRun;
@ -1085,7 +1085,7 @@ class Installer
* @param bool $preferSource
* @return Installer
*/
public function setPreferSource($preferSource = true): Installer
public function setPreferSource(bool $preferSource = true): Installer
{
$this->preferSource = (bool) $preferSource;
@ -1098,7 +1098,7 @@ class Installer
* @param bool $preferDist
* @return Installer
*/
public function setPreferDist($preferDist = true): Installer
public function setPreferDist(bool $preferDist = true): Installer
{
$this->preferDist = (bool) $preferDist;
@ -1111,7 +1111,7 @@ class Installer
* @param bool $optimizeAutoloader
* @return Installer
*/
public function setOptimizeAutoloader($optimizeAutoloader): Installer
public function setOptimizeAutoloader(bool $optimizeAutoloader): Installer
{
$this->optimizeAutoloader = (bool) $optimizeAutoloader;
if (!$this->optimizeAutoloader) {
@ -1130,7 +1130,7 @@ class Installer
* @param bool $classMapAuthoritative
* @return Installer
*/
public function setClassMapAuthoritative($classMapAuthoritative): Installer
public function setClassMapAuthoritative(bool $classMapAuthoritative): Installer
{
$this->classMapAuthoritative = (bool) $classMapAuthoritative;
if ($this->classMapAuthoritative) {
@ -1148,7 +1148,7 @@ class Installer
* @param string|null $apcuAutoloaderPrefix
* @return Installer
*/
public function setApcuAutoloader($apcuAutoloader, $apcuAutoloaderPrefix = null): Installer
public function setApcuAutoloader(bool $apcuAutoloader, ?string $apcuAutoloaderPrefix = null): Installer
{
$this->apcuAutoloader = $apcuAutoloader;
$this->apcuAutoloaderPrefix = $apcuAutoloaderPrefix;
@ -1162,7 +1162,7 @@ class Installer
* @param bool $update
* @return Installer
*/
public function setUpdate($update): Installer
public function setUpdate(bool $update): Installer
{
$this->update = (bool) $update;
@ -1175,7 +1175,7 @@ class Installer
* @param bool $install
* @return Installer
*/
public function setInstall($install): Installer
public function setInstall(bool $install): Installer
{
$this->install = (bool) $install;
@ -1188,7 +1188,7 @@ class Installer
* @param bool $devMode
* @return Installer
*/
public function setDevMode($devMode = true): Installer
public function setDevMode(bool $devMode = true): Installer
{
$this->devMode = (bool) $devMode;
@ -1203,7 +1203,7 @@ class Installer
* @param bool $dumpAutoloader
* @return Installer
*/
public function setDumpAutoloader($dumpAutoloader = true): Installer
public function setDumpAutoloader(bool $dumpAutoloader = true): Installer
{
$this->dumpAutoloader = (bool) $dumpAutoloader;
@ -1219,7 +1219,7 @@ class Installer
* @return Installer
* @deprecated Use setRunScripts(false) on the EventDispatcher instance being injected instead
*/
public function setRunScripts($runScripts = true): Installer
public function setRunScripts(bool $runScripts = true): Installer
{
$this->runScripts = (bool) $runScripts;
@ -1245,7 +1245,7 @@ class Installer
* @param bool $verbose
* @return Installer
*/
public function setVerbose($verbose = true): Installer
public function setVerbose(bool $verbose = true): Installer
{
$this->verbose = (bool) $verbose;
@ -1299,7 +1299,7 @@ class Installer
* @param bool $updateMirrors
* @return Installer
*/
public function setUpdateMirrors($updateMirrors): Installer
public function setUpdateMirrors(bool $updateMirrors): Installer
{
$this->updateMirrors = $updateMirrors;
@ -1330,7 +1330,7 @@ class Installer
* @param int $updateAllowTransitiveDependencies One of the UPDATE_ constants on the Request class
* @return Installer
*/
public function setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies): Installer
public function setUpdateAllowTransitiveDependencies(int $updateAllowTransitiveDependencies): Installer
{
if (!in_array($updateAllowTransitiveDependencies, array(Request::UPDATE_ONLY_LISTED, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS), true)) {
throw new \RuntimeException("Invalid value for updateAllowTransitiveDependencies supplied");
@ -1347,7 +1347,7 @@ class Installer
* @param bool $preferStable
* @return Installer
*/
public function setPreferStable($preferStable = true): Installer
public function setPreferStable(bool $preferStable = true): Installer
{
$this->preferStable = (bool) $preferStable;
@ -1360,7 +1360,7 @@ class Installer
* @param bool $preferLowest
* @return Installer
*/
public function setPreferLowest($preferLowest = true): Installer
public function setPreferLowest(bool $preferLowest = true): Installer
{
$this->preferLowest = (bool) $preferLowest;
@ -1375,7 +1375,7 @@ class Installer
* @param bool $writeLock
* @return Installer
*/
public function setWriteLock($writeLock = true): Installer
public function setWriteLock(bool $writeLock = true): Installer
{
$this->writeLock = (bool) $writeLock;
@ -1390,7 +1390,7 @@ class Installer
* @param bool $executeOperations
* @return Installer
*/
public function setExecuteOperations($executeOperations = true): Installer
public function setExecuteOperations(bool $executeOperations = true): Installer
{
$this->executeOperations = (bool) $executeOperations;

View File

@ -47,7 +47,7 @@ class BinaryInstaller
* @param Filesystem $filesystem
* @param string|null $vendorDir
*/
public function __construct(IOInterface $io, $binDir, $binCompat, Filesystem $filesystem = null, $vendorDir = null)
public function __construct(IOInterface $io, string $binDir, string $binCompat, Filesystem $filesystem = null, ?string $vendorDir = null)
{
$this->binDir = $binDir;
$this->binCompat = $binCompat;
@ -62,7 +62,7 @@ class BinaryInstaller
*
* @return void
*/
public function installBinaries(PackageInterface $package, $installPath, $warnOnOverwrite = true): void
public function installBinaries(PackageInterface $package, string $installPath, bool $warnOnOverwrite = true): void
{
$binaries = $this->getBinaries($package);
if (!$binaries) {
@ -149,7 +149,7 @@ class BinaryInstaller
*
* @return string
*/
public static function determineBinaryCaller($bin): string
public static function determineBinaryCaller(string $bin): string
{
if ('.bat' === substr($bin, -4) || '.exe' === substr($bin, -4)) {
return 'call';
@ -180,7 +180,7 @@ class BinaryInstaller
*
* @return void
*/
protected function installFullBinaries($binPath, $link, $bin, PackageInterface $package): void
protected function installFullBinaries(string $binPath, string $link, string $bin, PackageInterface $package): void
{
// add unixy support for cygwin and similar environments
if ('.bat' !== substr($binPath, -4)) {
@ -202,7 +202,7 @@ class BinaryInstaller
*
* @return void
*/
protected function installUnixyProxyBinaries($binPath, $link): void
protected function installUnixyProxyBinaries(string $binPath, string $link): void
{
file_put_contents($link, $this->generateUnixyProxyCode($binPath, $link));
Silencer::call('chmod', $link, 0777 & ~umask());
@ -223,7 +223,7 @@ class BinaryInstaller
*
* @return string
*/
protected function generateWindowsProxyCode($bin, $link): string
protected function generateWindowsProxyCode(string $bin, string $link): string
{
$binPath = $this->filesystem->findShortestPath($link, $bin);
$caller = self::determineBinaryCaller($bin);
@ -252,7 +252,7 @@ class BinaryInstaller
*
* @return string
*/
protected function generateUnixyProxyCode($bin, $link): string
protected function generateUnixyProxyCode(string $bin, string $link): string
{
$binPath = $this->filesystem->findShortestPath($link, $bin);

View File

@ -125,7 +125,7 @@ class InstallationManager
* @throws \InvalidArgumentException if installer for provided type is not registered
* @return InstallerInterface
*/
public function getInstaller($type)
public function getInstaller(string $type)
{
$type = strtolower($type);
@ -192,7 +192,7 @@ class InstallationManager
*
* @return void
*/
public function execute(InstalledRepositoryInterface $repo, array $operations, $devMode = true, $runScripts = true)
public function execute(InstalledRepositoryInterface $repo, array $operations, bool $devMode = true, bool $runScripts = true)
{
/** @var PromiseInterface[] */
$cleanupPromises = array();
@ -316,7 +316,7 @@ class InstallationManager
*
* @return void
*/
private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, $devMode, $runScripts, array $allOperations): void
private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, bool $devMode, bool $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): void
private function executeBatch(InstalledRepositoryInterface $repo, array $operations, array $cleanupPromises, bool $devMode, bool $runScripts, array $allOperations): void
{
$promises = array();
$postExecCallbacks = array();
@ -553,7 +553,7 @@ class InstallationManager
if ($promise instanceof PromiseInterface) {
return $promise;
}
return \React\Promise\resolve();
});
}
@ -627,7 +627,7 @@ class InstallationManager
*
* @return void
*/
public function setOutputProgress($outputProgress)
public function setOutputProgress(bool $outputProgress)
{
$this->outputProgress = $outputProgress;
}

View File

@ -54,7 +54,7 @@ class InstallerEvent extends Event
* @param bool $executeOperations
* @param Transaction $transaction
*/
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, $executeOperations, Transaction $transaction)
public function __construct(string $eventName, Composer $composer, IOInterface $io, bool $devMode, bool $executeOperations, Transaction $transaction)
{
parent::__construct($eventName);

View File

@ -31,7 +31,7 @@ interface InstallerInterface
* @param string $packageType
* @return bool
*/
public function supports($packageType);
public function supports(string $packageType);
/**
* Checks that provided package is installed.
@ -65,7 +65,7 @@ interface InstallerInterface
* @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null
*/
public function prepare($type, PackageInterface $package, PackageInterface $prevPackage = null);
public function prepare(string $type, PackageInterface $package, PackageInterface $prevPackage = null);
/**
* Installs specific package.
@ -108,7 +108,7 @@ interface InstallerInterface
* @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null
*/
public function cleanup($type, PackageInterface $package, PackageInterface $prevPackage = null);
public function cleanup(string $type, PackageInterface $package, PackageInterface $prevPackage = null);
/**
* Returns the absolute installation path of a package.

View File

@ -56,7 +56,7 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
* @param Filesystem $filesystem
* @param BinaryInstaller $binaryInstaller
*/
public function __construct(IOInterface $io, PartialComposer $composer, $type = 'library', Filesystem $filesystem = null, BinaryInstaller $binaryInstaller = null)
public function __construct(IOInterface $io, PartialComposer $composer, ?string $type = 'library', Filesystem $filesystem = null, BinaryInstaller $binaryInstaller = null)
{
$this->composer = $composer;
$this->downloadManager = $composer instanceof Composer ? $composer->getDownloadManager() : null;

View File

@ -66,7 +66,7 @@ class PackageEvent extends Event
* @param OperationInterface[] $operations
* @param OperationInterface $operation
*/
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation)
public function __construct(string $eventName, Composer $composer, IOInterface $io, bool $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation)
{
parent::__construct($eventName);

View File

@ -36,7 +36,7 @@ class ProjectInstaller implements InstallerInterface
/**
* @param string $installPath
*/
public function __construct($installPath, DownloadManager $dm, Filesystem $fs)
public function __construct(string $installPath, DownloadManager $dm, Filesystem $fs)
{
$this->installPath = rtrim(strtr($installPath, '\\', '/'), '/').'/';
$this->downloadManager = $dm;
@ -49,7 +49,7 @@ class ProjectInstaller implements InstallerInterface
* @param string $packageType
* @return bool
*/
public function supports($packageType): bool
public function supports(string $packageType): bool
{
return true;
}

View File

@ -63,7 +63,7 @@ class SuggestedPackagesReporter
* @param string $reason Reason the target package to be suggested
* @return SuggestedPackagesReporter
*/
public function addPackage($source, $target, $reason): SuggestedPackagesReporter
public function addPackage(string $source, string $target, string $reason): SuggestedPackagesReporter
{
$this->suggestedPackages[] = array(
'source' => $source,
@ -104,7 +104,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 void
*/
public function output($mode, InstalledRepository $installedRepo = null, PackageInterface $onlyDependentsOf = null): void
public function output(int $mode, InstalledRepository $installedRepo = null, PackageInterface $onlyDependentsOf = null): void
{
$suggestedPackages = $this->getFilteredSuggestions($installedRepo, $onlyDependentsOf);
@ -220,7 +220,7 @@ class SuggestedPackagesReporter
* @param string $string
* @return string
*/
private function escapeOutput($string): string
private function escapeOutput(string $string): string
{
return OutputFormatter::escape(
$this->removeControlCharacters($string)
@ -231,7 +231,7 @@ class SuggestedPackagesReporter
* @param string $string
* @return string
*/
private function removeControlCharacters($string): string
private function removeControlCharacters(string $string): string
{
return Preg::replace(
'/[[:cntrl:]]/',

View File

@ -55,7 +55,7 @@ class JsonFile
* @param ?IOInterface $io
* @throws \InvalidArgumentException
*/
public function __construct($path, HttpDownloader $httpDownloader = null, IOInterface $io = null)
public function __construct(string $path, HttpDownloader $httpDownloader = null, IOInterface $io = null)
{
$this->path = $path;
@ -124,7 +124,7 @@ class JsonFile
* @throws \UnexpectedValueException|\Exception
* @return void
*/
public function write(array $hash, $options = JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
public function write(array $hash, int $options = JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
{
if ($this->path === 'php://memory') {
file_put_contents($this->path, static::encode($hash, $options));
@ -169,7 +169,7 @@ class JsonFile
* @param string $content
* @return int|false
*/
private function filePutContentsIfModified($path, $content)
private function filePutContentsIfModified(string $path, string $content)
{
$currentContent = @file_get_contents($path);
if (!$currentContent || ($currentContent != $content)) {
@ -188,7 +188,7 @@ class JsonFile
* @throws ParsingException
* @return bool true on success
*/
public function validateSchema($schema = self::STRICT_SCHEMA, $schemaFile = null)
public function validateSchema(int $schema = self::STRICT_SCHEMA, ?string $schemaFile = null)
{
$content = file_get_contents($this->path);
$data = json_decode($content);
@ -239,7 +239,7 @@ class JsonFile
* @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
* @return string Encoded json
*/
public static function encode($data, $options = 448)
public static function encode($data, int $options = 448)
{
$json = json_encode($data, $options);
if (false === $json) {
@ -256,7 +256,7 @@ class JsonFile
* @throws \RuntimeException
* @return void
*/
private static function throwEncodeError($code): void
private static function throwEncodeError(int $code): void
{
switch ($code) {
case JSON_ERROR_DEPTH:
@ -281,13 +281,13 @@ class JsonFile
/**
* Parses json string and returns hash.
*
* @param ?string $json json string
* @param null|string $json json string
* @param string $file the json file
*
* @throws ParsingException
* @return mixed
*/
public static function parseJson($json, $file = null)
public static function parseJson(?string $json, string $file = null)
{
if (null === $json) {
return null;
@ -309,7 +309,7 @@ class JsonFile
* @throws ParsingException
* @return bool true on success
*/
protected static function validateSyntax($json, $file = null)
protected static function validateSyntax(string $json, string $file = null)
{
$parser = new JsonParser();
$result = $parser->lint($json);

View File

@ -38,7 +38,7 @@ class JsonFormatter
* @param bool $unescapeSlashes Un escape slashes
* @return string
*/
public static function format($json, $unescapeUnicode, $unescapeSlashes): string
public static function format(string $json, bool $unescapeUnicode, bool $unescapeSlashes): string
{
$result = '';
$pos = 0;

View File

@ -41,7 +41,7 @@ class JsonManipulator
/**
* @param string $contents
*/
public function __construct($contents)
public function __construct(string $contents)
{
$contents = trim($contents);
if ($contents === '') {
@ -70,7 +70,7 @@ class JsonManipulator
* @param bool $sortPackages
* @return bool
*/
public function addLink($type, $package, $constraint, $sortPackages = false)
public function addLink(string $type, string $package, string $constraint, bool $sortPackages = false)
{
$decoded = JsonFile::parseJson($this->contents);
@ -165,12 +165,12 @@ class JsonManipulator
}
/**
* @param string $name
* @param array<string, mixed> $config
* @param bool $append
* @param string $name
* @param array<string, mixed>|false $config
* @param bool $append
* @return bool
*/
public function addRepository($name, $config, $append = true)
public function addRepository(string $name, $config, bool $append = true)
{
return $this->addSubNode('repositories', $name, $config, $append);
}
@ -179,7 +179,7 @@ class JsonManipulator
* @param string $name
* @return bool
*/
public function removeRepository($name)
public function removeRepository(string $name)
{
return $this->removeSubNode('repositories', $name);
}
@ -189,7 +189,7 @@ class JsonManipulator
* @param mixed $value
* @return bool
*/
public function addConfigSetting($name, $value)
public function addConfigSetting(string $name, $value)
{
return $this->addSubNode('config', $name, $value);
}
@ -198,7 +198,7 @@ class JsonManipulator
* @param string $name
* @return bool
*/
public function removeConfigSetting($name)
public function removeConfigSetting(string $name)
{
return $this->removeSubNode('config', $name);
}
@ -208,7 +208,7 @@ class JsonManipulator
* @param mixed $value
* @return bool
*/
public function addProperty($name, $value)
public function addProperty(string $name, $value)
{
if (strpos($name, 'suggest.') === 0) {
return $this->addSubNode('suggest', substr($name, 8), $value);
@ -229,7 +229,7 @@ class JsonManipulator
* @param string $name
* @return bool
*/
public function removeProperty($name)
public function removeProperty(string $name)
{
if (strpos($name, 'suggest.') === 0) {
return $this->removeSubNode('suggest', substr($name, 8));
@ -253,7 +253,7 @@ class JsonManipulator
* @param bool $append
* @return bool
*/
public function addSubNode($mainNode, $name, $value, $append = true)
public function addSubNode(string $mainNode, string $name, $value, bool $append = true)
{
$decoded = JsonFile::parseJson($this->contents);
@ -363,7 +363,7 @@ class JsonManipulator
* @param string $name
* @return bool
*/
public function removeSubNode($mainNode, $name)
public function removeSubNode(string $mainNode, string $name)
{
$decoded = JsonFile::parseJson($this->contents);
@ -468,7 +468,7 @@ class JsonManipulator
* @param mixed $content
* @return bool
*/
public function addMainKey($key, $content)
public function addMainKey(string $key, $content)
{
$decoded = JsonFile::parseJson($this->contents);
$content = $this->format($content);
@ -512,7 +512,7 @@ class JsonManipulator
* @param string $key
* @return bool
*/
public function removeMainKey($key)
public function removeMainKey(string $key)
{
$decoded = JsonFile::parseJson($this->contents);
@ -549,7 +549,7 @@ class JsonManipulator
* @param string $key
* @return bool
*/
public function removeMainKeyIfEmpty($key)
public function removeMainKeyIfEmpty(string $key)
{
$decoded = JsonFile::parseJson($this->contents);
@ -569,7 +569,7 @@ class JsonManipulator
* @param int $depth
* @return string
*/
public function format($data, $depth = 0)
public function format($data, int $depth = 0)
{
if (is_array($data)) {
reset($data);

View File

@ -28,7 +28,7 @@ class JsonValidationException extends Exception
* @param string $message
* @param string[] $errors
*/
public function __construct($message, array $errors = array(), Exception $previous = null)
public function __construct(string $message, array $errors = array(), Exception $previous = null)
{
$this->errors = $errors;
parent::__construct((string) $message, 0, $previous);

Some files were not shown because too many files have changed in this diff Show More