1
0
Fork 0

Add more types

pull/10561/head
Jordi Boggiano 2022-02-22 22:10:52 +01:00
parent e52071a92c
commit 7abc8da7d3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
71 changed files with 807 additions and 850 deletions

View File

@ -52,7 +52,7 @@ class DiagnoseCommand extends BaseCommand
/** /**
* @return void * @return void
*/ */
protected function configure() protected function configure(): void
{ {
$this $this
->setName('diagnose') ->setName('diagnose')

View File

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

View File

@ -335,15 +335,6 @@ EOT
); );
} }
/**
* @private
* @return void
*/
public function markSolverComplete()
{
$this->dependencyResolutionCompleted = true;
}
/** /**
* @param array<string, string> $requirements * @param array<string, string> $requirements
* @param string $requireKey * @param string $requireKey
@ -358,7 +349,9 @@ EOT
$composer = $this->requireComposer(); $composer = $this->requireComposer();
$this->dependencyResolutionCompleted = false; $this->dependencyResolutionCompleted = false;
$composer->getEventDispatcher()->addListener(InstallerEvents::PRE_OPERATIONS_EXEC, array($this, 'markSolverComplete'), 10000); $composer->getEventDispatcher()->addListener(InstallerEvents::PRE_OPERATIONS_EXEC, function (): void {
$this->dependencyResolutionCompleted = true;
}, 10000);
if ($input->getOption('dry-run')) { if ($input->getOption('dry-run')) {
$rootPackage = $composer->getPackage(); $rootPackage = $composer->getPackage();
@ -480,7 +473,7 @@ EOT
* @param bool $hardExit * @param bool $hardExit
* @return void * @return void
*/ */
public function revertComposerFile(bool $hardExit = true) public function revertComposerFile(bool $hardExit = true): void
{ {
$io = $this->getIO(); $io = $this->getIO();

View File

@ -602,7 +602,7 @@ EOT
/** /**
* @return string[] * @return string[]
*/ */
protected function getRootRequires() protected function getRootRequires(): array
{ {
$rootPackage = $this->requireComposer()->getPackage(); $rootPackage = $this->requireComposer()->getPackage();
@ -677,7 +677,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printPackageInfo(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) protected function printPackageInfo(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null): void
{ {
$io = $this->getIO(); $io = $this->getIO();
@ -705,7 +705,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printMeta(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) protected function printMeta(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null): void
{ {
$io = $this->getIO(); $io = $this->getIO();
$io->write('<info>name</info> : ' . $package->getPrettyName()); $io->write('<info>name</info> : ' . $package->getPrettyName());
@ -773,7 +773,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printVersions(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo) protected function printVersions(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo): void
{ {
$versions = array_keys($versions); $versions = array_keys($versions);
$versions = Semver::rsort($versions); $versions = Semver::rsort($versions);
@ -802,7 +802,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printLinks(CompletePackageInterface $package, string $linkType, string $title = null) protected function printLinks(CompletePackageInterface $package, string $linkType, string $title = null): void
{ {
$title = $title ?: $linkType; $title = $title ?: $linkType;
$io = $this->getIO(); $io = $this->getIO();
@ -820,7 +820,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printLicenses(CompletePackageInterface $package) protected function printLicenses(CompletePackageInterface $package): void
{ {
$spdxLicenses = new SpdxLicenses(); $spdxLicenses = new SpdxLicenses();
@ -852,7 +852,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function printPackageInfoAsJson(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) protected function printPackageInfoAsJson(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null): void
{ {
$json = array( $json = array(
'name' => $package->getPrettyName(), 'name' => $package->getPrettyName(),
@ -1030,7 +1030,7 @@ EOT
* *
* @return void * @return void
*/ */
protected function initStyles(OutputInterface $output) protected function initStyles(OutputInterface $output): void
{ {
$this->colors = array( $this->colors = array(
'green', 'green',
@ -1052,7 +1052,7 @@ EOT
* @param array<int, array<string, string|mixed[]>> $arrayTree * @param array<int, array<string, string|mixed[]>> $arrayTree
* @return void * @return void
*/ */
protected function displayPackageTree(array $arrayTree) protected function displayPackageTree(array $arrayTree): void
{ {
$io = $this->getIO(); $io = $this->getIO();
foreach ($arrayTree as $package) { foreach ($arrayTree as $package) {
@ -1101,7 +1101,7 @@ EOT
PackageInterface $package, PackageInterface $package,
InstalledRepository $installedRepo, InstalledRepository $installedRepo,
RepositoryInterface $remoteRepos RepositoryInterface $remoteRepos
) { ): array {
$requires = $package->getRequires(); $requires = $package->getRequires();
ksort($requires); ksort($requires);
$children = array(); $children = array();
@ -1149,7 +1149,7 @@ EOT
array $packagesInTree, array $packagesInTree,
string $previousTreeBar = '├', string $previousTreeBar = '├',
int $level = 1 int $level = 1
) { ): void {
$previousTreeBar = str_replace('├', '│', $previousTreeBar); $previousTreeBar = str_replace('├', '│', $previousTreeBar);
if (is_array($package) && isset($package['requires'])) { if (is_array($package) && isset($package['requires'])) {
$requires = $package['requires']; $requires = $package['requires'];
@ -1202,7 +1202,7 @@ EOT
InstalledRepository $installedRepo, InstalledRepository $installedRepo,
RepositoryInterface $remoteRepos, RepositoryInterface $remoteRepos,
array $packagesInTree array $packagesInTree
) { ): array {
$children = array(); $children = array();
list($package) = $this->getPackage( list($package) = $this->getPackage(
$installedRepo, $installedRepo,

View File

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

View File

@ -52,7 +52,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getName() public function getName(): string
{ {
return $this->file->getPath(); return $this->file->getPath();
} }
@ -60,7 +60,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function addRepository($name, $config, $append = true) public function addRepository(string $name, $config, bool $append = true): void
{ {
$this->manipulateJson('addRepository', function (&$config, $repo, $repoConfig) use ($append): void { $this->manipulateJson('addRepository', function (&$config, $repo, $repoConfig) use ($append): void {
// if converting from an array format to hashmap format, and there is a {"packagist.org":false} repo, we have // if converting from an array format to hashmap format, and there is a {"packagist.org":false} repo, we have
@ -89,7 +89,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function removeRepository($name) public function removeRepository(string $name): void
{ {
$this->manipulateJson('removeRepository', function (&$config, $repo): void { $this->manipulateJson('removeRepository', function (&$config, $repo): void {
unset($config['repositories'][$repo]); unset($config['repositories'][$repo]);
@ -99,7 +99,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function addConfigSetting($name, $value) public function addConfigSetting(string $name, $value): void
{ {
$authConfig = $this->authConfig; $authConfig = $this->authConfig;
$this->manipulateJson('addConfigSetting', function (&$config, $key, $val) use ($authConfig): void { $this->manipulateJson('addConfigSetting', function (&$config, $key, $val) use ($authConfig): void {
@ -119,7 +119,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function removeConfigSetting($name) public function removeConfigSetting(string $name): void
{ {
$authConfig = $this->authConfig; $authConfig = $this->authConfig;
$this->manipulateJson('removeConfigSetting', function (&$config, $key) use ($authConfig): void { $this->manipulateJson('removeConfigSetting', function (&$config, $key) use ($authConfig): void {
@ -139,7 +139,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function addProperty($name, $value) public function addProperty(string $name, $value): void
{ {
$this->manipulateJson('addProperty', function (&$config, $key, $val): void { $this->manipulateJson('addProperty', function (&$config, $key, $val): void {
if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) { if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) {
@ -162,7 +162,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function removeProperty($name) public function removeProperty(string $name): void
{ {
$this->manipulateJson('removeProperty', function (&$config, $key): void { $this->manipulateJson('removeProperty', function (&$config, $key): void {
if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) { if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) {
@ -185,7 +185,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function addLink($type, $name, $value) public function addLink(string $type, string $name, string $value): void
{ {
$this->manipulateJson('addLink', function (&$config, $type, $name, $value): void { $this->manipulateJson('addLink', function (&$config, $type, $name, $value): void {
$config[$type][$name] = $value; $config[$type][$name] = $value;
@ -195,7 +195,7 @@ class JsonConfigSource implements ConfigSourceInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function removeLink($type, $name) public function removeLink(string $type, string $name): void
{ {
$this->manipulateJson('removeSubNode', function (&$config, $type, $name): void { $this->manipulateJson('removeSubNode', function (&$config, $type, $name): void {
unset($config[$type][$name]); unset($config[$type][$name]);

View File

@ -423,9 +423,9 @@ class Application extends BaseApplication
* @param bool|null $disableScripts * @param bool|null $disableScripts
* @throws JsonValidationException * @throws JsonValidationException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return ?\Composer\Composer If $required is true then the return value is guaranteed * @return ?Composer If $required is true then the return value is guaranteed
*/ */
public function getComposer(bool $required = true, ?bool $disablePlugins = null, ?bool $disableScripts = null) public function getComposer(bool $required = true, ?bool $disablePlugins = null, ?bool $disableScripts = null): ?Composer
{ {
if (null === $disablePlugins) { if (null === $disablePlugins) {
$disablePlugins = $this->disablePluginsByDefault; $disablePlugins = $this->disablePluginsByDefault;
@ -460,7 +460,7 @@ class Application extends BaseApplication
* *
* @return void * @return void
*/ */
public function resetComposer() public function resetComposer(): void
{ {
$this->composer = null; $this->composer = null;
if (method_exists($this->getIO(), 'resetAuthentications')) { if (method_exists($this->getIO(), 'resetAuthentications')) {
@ -471,7 +471,7 @@ class Application extends BaseApplication
/** /**
* @return IOInterface * @return IOInterface
*/ */
public function getIO() public function getIO(): IOInterface
{ {
return $this->io; return $this->io;
} }

View File

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

View File

@ -26,7 +26,7 @@ abstract class SolverOperation implements OperationInterface
* *
* @return string * @return string
*/ */
public function getOperationType() public function getOperationType(): string
{ {
return static::TYPE; return static::TYPE;
} }

View File

@ -33,9 +33,9 @@ abstract class ArchiveDownloader extends FileDownloader
protected $cleanupExecuted = array(); protected $cleanupExecuted = array();
/** /**
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
unset($this->cleanupExecuted[$package->getName()]); unset($this->cleanupExecuted[$package->getName()]);
@ -43,9 +43,9 @@ abstract class ArchiveDownloader extends FileDownloader
} }
/** /**
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
$this->cleanupExecuted[$package->getName()] = true; $this->cleanupExecuted[$package->getName()] = true;
@ -62,7 +62,7 @@ abstract class ArchiveDownloader extends FileDownloader
* @throws \RuntimeException * @throws \RuntimeException
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function install(PackageInterface $package, string $path, bool $output = true) public function install(PackageInterface $package, string $path, bool $output = true): PromiseInterface
{ {
if ($output) { if ($output) {
$this->io->writeError(" - " . InstallOperation::format($package) . $this->getInstallOperationAppendix($package, $path)); $this->io->writeError(" - " . InstallOperation::format($package) . $this->getInstallOperationAppendix($package, $path));
@ -113,10 +113,6 @@ abstract class ArchiveDownloader extends FileDownloader
throw $e; throw $e;
} }
if (!$promise instanceof PromiseInterface) {
$promise = \React\Promise\resolve();
}
return $promise->then(function () use ($package, $filesystem, $fileName, $temporaryDir, $path): \React\Promise\PromiseInterface { return $promise->then(function () use ($package, $filesystem, $fileName, $temporaryDir, $path): \React\Promise\PromiseInterface {
$filesystem->unlink($fileName); $filesystem->unlink($fileName);
@ -215,7 +211,7 @@ abstract class ArchiveDownloader extends FileDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function getInstallOperationAppendix(PackageInterface $package, string $path) protected function getInstallOperationAppendix(PackageInterface $package, string $path): string
{ {
return ': Extracting archive'; return ': Extracting archive';
} }
@ -227,7 +223,6 @@ abstract class ArchiveDownloader extends FileDownloader
* @param string $path Directory * @param string $path Directory
* *
* @throws \UnexpectedValueException If can not extract downloaded file to path * @throws \UnexpectedValueException If can not extract downloaded file to path
* @return PromiseInterface|null
*/ */
abstract protected function extract(PackageInterface $package, string $file, string $path); abstract protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface;
} }

View File

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

View File

@ -59,7 +59,7 @@ class DownloadManager
* @param bool $preferSource prefer downloading from source * @param bool $preferSource prefer downloading from source
* @return DownloadManager * @return DownloadManager
*/ */
public function setPreferSource(bool $preferSource): DownloadManager public function setPreferSource(bool $preferSource): self
{ {
$this->preferSource = $preferSource; $this->preferSource = $preferSource;
@ -72,7 +72,7 @@ class DownloadManager
* @param bool $preferDist prefer downloading from dist * @param bool $preferDist prefer downloading from dist
* @return DownloadManager * @return DownloadManager
*/ */
public function setPreferDist(bool $preferDist): DownloadManager public function setPreferDist(bool $preferDist): self
{ {
$this->preferDist = $preferDist; $this->preferDist = $preferDist;
@ -86,7 +86,7 @@ class DownloadManager
* *
* @return DownloadManager * @return DownloadManager
*/ */
public function setPreferences(array $preferences): DownloadManager public function setPreferences(array $preferences): self
{ {
$this->packagePreferences = $preferences; $this->packagePreferences = $preferences;
@ -100,7 +100,7 @@ class DownloadManager
* @param DownloaderInterface $downloader downloader instance * @param DownloaderInterface $downloader downloader instance
* @return DownloadManager * @return DownloadManager
*/ */
public function setDownloader(string $type, DownloaderInterface $downloader): DownloadManager public function setDownloader(string $type, DownloaderInterface $downloader): self
{ {
$type = strtolower($type); $type = strtolower($type);
$this->downloaders[$type] = $downloader; $this->downloaders[$type] = $downloader;
@ -229,9 +229,6 @@ class DownloadManager
} catch (\Exception $e) { } catch (\Exception $e) {
return $handleError($e); return $handleError($e);
} }
if (!$result instanceof PromiseInterface) {
return \React\Promise\resolve($result);
}
$res = $result->then(function ($res) { $res = $result->then(function ($res) {
return $res; return $res;
@ -251,9 +248,9 @@ class DownloadManager
* @param string $targetDir target dir * @param string $targetDir target dir
* @param PackageInterface|null $prevPackage previous package instance in case of updates * @param PackageInterface|null $prevPackage previous package instance in case of updates
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function prepare(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface public function prepare(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): PromiseInterface
{ {
$targetDir = $this->normalizeTargetDir($targetDir); $targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package); $downloader = $this->getDownloaderForPackage($package);
@ -272,9 +269,9 @@ class DownloadManager
* *
* @throws \InvalidArgumentException if package have no urls to download from * @throws \InvalidArgumentException if package have no urls to download from
* @throws \RuntimeException * @throws \RuntimeException
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function install(PackageInterface $package, string $targetDir): ?PromiseInterface public function install(PackageInterface $package, string $targetDir): PromiseInterface
{ {
$targetDir = $this->normalizeTargetDir($targetDir); $targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package); $downloader = $this->getDownloaderForPackage($package);
@ -293,9 +290,9 @@ class DownloadManager
* @param string $targetDir target dir * @param string $targetDir target dir
* *
* @throws \InvalidArgumentException if initial package is not installed * @throws \InvalidArgumentException if initial package is not installed
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function update(PackageInterface $initial, PackageInterface $target, string $targetDir): ?PromiseInterface public function update(PackageInterface $initial, PackageInterface $target, string $targetDir): PromiseInterface
{ {
$targetDir = $this->normalizeTargetDir($targetDir); $targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($target); $downloader = $this->getDownloaderForPackage($target);
@ -330,18 +327,10 @@ class DownloadManager
// if downloader type changed, or update failed and user asks for reinstall, // if downloader type changed, or update failed and user asks for reinstall,
// we wipe the dir and do a new install instead of updating it // we wipe the dir and do a new install instead of updating it
$promise = $initialDownloader->remove($initial, $targetDir); $promise = $initialDownloader->remove($initial, $targetDir);
if ($promise instanceof PromiseInterface) {
return $promise->then(function ($res) use ($target, $targetDir): PromiseInterface {
$promise = $this->install($target, $targetDir);
if ($promise instanceof PromiseInterface) {
return $promise;
}
return \React\Promise\resolve(); return $promise->then(function ($res) use ($target, $targetDir): PromiseInterface {
}); return $this->install($target, $targetDir);
} });
return $this->install($target, $targetDir);
} }
/** /**
@ -350,9 +339,9 @@ class DownloadManager
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function remove(PackageInterface $package, string $targetDir): ?PromiseInterface public function remove(PackageInterface $package, string $targetDir): PromiseInterface
{ {
$targetDir = $this->normalizeTargetDir($targetDir); $targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package); $downloader = $this->getDownloaderForPackage($package);
@ -371,9 +360,9 @@ class DownloadManager
* @param string $targetDir target dir * @param string $targetDir target dir
* @param PackageInterface|null $prevPackage previous package instance in case of updates * @param PackageInterface|null $prevPackage previous package instance in case of updates
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function cleanup(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): ?PromiseInterface public function cleanup(string $type, PackageInterface $package, string $targetDir, PackageInterface $prevPackage = null): PromiseInterface
{ {
$targetDir = $this->normalizeTargetDir($targetDir); $targetDir = $this->normalizeTargetDir($targetDir);
$downloader = $this->getDownloaderForPackage($package); $downloader = $this->getDownloaderForPackage($package);

View File

@ -28,15 +28,15 @@ interface DownloaderInterface
* *
* @return string "source" or "dist" * @return string "source" or "dist"
*/ */
public function getInstallationSource(); public function getInstallationSource(): string;
/** /**
* This should do any network-related tasks to prepare for an upcoming install/update * This should do any network-related tasks to prepare for an upcoming install/update
* *
* @param string $path download path * @param string $path download path
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null); public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface;
/** /**
* Do anything that needs to be done between all downloads have been completed and the actual operation is executed * Do anything that needs to be done between all downloads have been completed and the actual operation is executed
@ -50,18 +50,18 @@ interface DownloaderInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null); public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface;
/** /**
* Installs specific package into specific folder. * Installs specific package into specific folder.
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function install(PackageInterface $package, string $path); public function install(PackageInterface $package, string $path): PromiseInterface;
/** /**
* Updates specific package in specific folder from initial to target version. * Updates specific package in specific folder from initial to target version.
@ -69,18 +69,18 @@ interface DownloaderInterface
* @param PackageInterface $initial initial package * @param PackageInterface $initial initial package
* @param PackageInterface $target updated package * @param PackageInterface $target updated package
* @param string $path download path * @param string $path download path
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function update(PackageInterface $initial, PackageInterface $target, string $path); public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface;
/** /**
* Removes specific package from specific folder. * Removes specific package from specific folder.
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function remove(PackageInterface $package, string $path); public function remove(PackageInterface $package, string $path): PromiseInterface;
/** /**
* Do anything to cleanup changes applied in the prepare or install/update/uninstall steps * Do anything to cleanup changes applied in the prepare or install/update/uninstall steps
@ -93,7 +93,7 @@ interface DownloaderInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null * @return PromiseInterface
*/ */
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null); public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface;
} }

View File

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

View File

@ -66,11 +66,9 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
public static $downloadMetadata = array(); public static $downloadMetadata = array();
/** /**
* @private this is only public for php 5.3 support in closures
*
* @var array<string, string> Map of package name to cache key * @var array<string, string> Map of package name to cache key
*/ */
public $lastCacheWrites = array(); private $lastCacheWrites = array();
/** @var array<string, string[]> Map of package name to list of paths */ /** @var array<string, string[]> Map of package name to list of paths */
private $additionalCleanupPaths = array(); private $additionalCleanupPaths = array();
@ -103,7 +101,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getInstallationSource() public function getInstallationSource(): string
{ {
return 'dist'; return 'dist';
} }
@ -113,7 +111,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* *
* @param bool $output * @param bool $output
*/ */
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true) public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true): PromiseInterface
{ {
if (!$package->getDistUrl()) { if (!$package->getDistUrl()) {
throw new \InvalidArgumentException('The given package is missing url information'); throw new \InvalidArgumentException('The given package is missing url information');
@ -296,7 +294,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
return \React\Promise\resolve(); return \React\Promise\resolve();
} }
@ -304,7 +302,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
$fileName = $this->getFileName($package, $path); $fileName = $this->getFileName($package, $path);
if (file_exists($fileName)) { if (file_exists($fileName)) {
@ -337,7 +335,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* *
* @param bool $output * @param bool $output
*/ */
public function install(PackageInterface $package, string $path, bool $output = true) public function install(PackageInterface $package, string $path, bool $output = true): PromiseInterface
{ {
if ($output) { if ($output) {
$this->io->writeError(" - " . InstallOperation::format($package)); $this->io->writeError(" - " . InstallOperation::format($package));
@ -363,7 +361,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/** /**
* @return void * @return void
*/ */
protected function clearLastCacheWrite(PackageInterface $package) protected function clearLastCacheWrite(PackageInterface $package): void
{ {
if ($this->cache && isset($this->lastCacheWrites[$package->getName()])) { if ($this->cache && isset($this->lastCacheWrites[$package->getName()])) {
$this->cache->remove($this->lastCacheWrites[$package->getName()]); $this->cache->remove($this->lastCacheWrites[$package->getName()]);
@ -376,7 +374,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* *
* @return void * @return void
*/ */
protected function addCleanupPath(PackageInterface $package, string $path) protected function addCleanupPath(PackageInterface $package, string $path): void
{ {
$this->additionalCleanupPaths[$package->getName()][] = $path; $this->additionalCleanupPaths[$package->getName()][] = $path;
} }
@ -386,7 +384,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* *
* @return void * @return void
*/ */
protected function removeCleanupPath(PackageInterface $package, string $path) protected function removeCleanupPath(PackageInterface $package, string $path): void
{ {
if (isset($this->additionalCleanupPaths[$package->getName()])) { if (isset($this->additionalCleanupPaths[$package->getName()])) {
$idx = array_search($path, $this->additionalCleanupPaths[$package->getName()]); $idx = array_search($path, $this->additionalCleanupPaths[$package->getName()]);
@ -399,22 +397,14 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function update(PackageInterface $initial, PackageInterface $target, string $path) public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface
{ {
$this->io->writeError(" - " . UpdateOperation::format($initial, $target) . $this->getInstallOperationAppendix($target, $path)); $this->io->writeError(" - " . UpdateOperation::format($initial, $target) . $this->getInstallOperationAppendix($target, $path));
$promise = $this->remove($initial, $path, false); $promise = $this->remove($initial, $path, false);
if (!$promise instanceof PromiseInterface) {
$promise = \React\Promise\resolve();
}
return $promise->then(function () use ($target, $path): PromiseInterface { return $promise->then(function () use ($target, $path): PromiseInterface {
$promise = $this->install($target, $path, false); return $this->install($target, $path, false);
if ($promise instanceof PromiseInterface) {
return $promise;
}
return \React\Promise\resolve();
}); });
} }
@ -423,7 +413,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* *
* @param bool $output * @param bool $output
*/ */
public function remove(PackageInterface $package, string $path, bool $output = true) public function remove(PackageInterface $package, string $path, bool $output = true): PromiseInterface
{ {
if ($output) { if ($output) {
$this->io->writeError(" - " . UninstallOperation::format($package)); $this->io->writeError(" - " . UninstallOperation::format($package));
@ -444,7 +434,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @param string $path download path * @param string $path download path
* @return string file name * @return string file name
*/ */
protected function getFileName(PackageInterface $package, string $path) protected function getFileName(PackageInterface $package, string $path): string
{ {
return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_EXTENSION), '.'); return rtrim($this->config->get('vendor-dir').'/composer/tmp-'.md5($package.spl_object_hash($package)).'.'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_EXTENSION), '.');
} }
@ -456,7 +446,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @param string $path download path * @param string $path download path
* @return string * @return string
*/ */
protected function getInstallOperationAppendix(PackageInterface $package, string $path) protected function getInstallOperationAppendix(PackageInterface $package, string $path): string
{ {
return ''; return '';
} }
@ -469,7 +459,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @throws \RuntimeException If any problem with the url * @throws \RuntimeException If any problem with the url
* @return string url * @return string url
*/ */
protected function processUrl(PackageInterface $package, string $url) protected function processUrl(PackageInterface $package, string $url): string
{ {
if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) { if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) {
throw new \RuntimeException('You must enable the openssl extension to download files via https'); throw new \RuntimeException('You must enable the openssl extension to download files via https');
@ -486,7 +476,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @inheritDoc * @inheritDoc
* @throws \RuntimeException * @throws \RuntimeException
*/ */
public function getLocalChanges(PackageInterface $package, string $targetDir) public function getLocalChanges(PackageInterface $package, string $targetDir): ?string
{ {
$prevIO = $this->io; $prevIO = $this->io;

View File

@ -25,7 +25,7 @@ class FossilDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): PromiseInterface
{ {
return \React\Promise\resolve(); return \React\Promise\resolve();
} }
@ -33,7 +33,7 @@ class FossilDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface
{ {
// Ensure we are allowed to use this URL by config // Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io); $this->config->prohibitUrlByConfig($url, $this->io);
@ -61,7 +61,7 @@ class FossilDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface
{ {
// Ensure we are allowed to use this URL by config // Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io); $this->config->prohibitUrlByConfig($url, $this->io);

View File

@ -58,7 +58,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null) protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): PromiseInterface
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
@ -83,7 +83,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doInstall(PackageInterface $package, string $path, string $url) protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -148,7 +148,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url) protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -213,7 +213,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLocalChanges(PackageInterface $package, string $path) public function getLocalChanges(PackageInterface $package, string $path): ?string
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
if (!$this->hasMetadataRepository($path)) { if (!$this->hasMetadataRepository($path)) {
@ -231,7 +231,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @return null|string * @return null|string
*/ */
public function getUnpushedChanges(PackageInterface $package, string $path) public function getUnpushedChanges(PackageInterface $package, string $path): ?string
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -328,7 +328,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function cleanChanges(PackageInterface $package, string $path, bool $update) protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -415,7 +415,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function reapplyChanges(string $path) protected function reapplyChanges(string $path): void
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!empty($this->hasStashedChanges[$path])) { if (!empty($this->hasStashedChanges[$path])) {
@ -438,7 +438,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* @throws \RuntimeException * @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 * @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, string $path, string $reference, string $prettyVersion) protected function updateToCommit(PackageInterface $package, string $path, string $reference, string $prettyVersion): ?string
{ {
$force = !empty($this->hasDiscardedChanges[$path]) || !empty($this->hasStashedChanges[$path]) ? '-f ' : ''; $force = !empty($this->hasDiscardedChanges[$path]) || !empty($this->hasStashedChanges[$path]) ? '-f ' : '';
@ -505,7 +505,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* *
* @return void * @return void
*/ */
protected function updateOriginUrl(string $path, string $url) protected function updateOriginUrl(string $path, string $url): void
{ {
$this->process->execute(sprintf('git remote set-url origin -- %s', ProcessExecutor::escape($url)), $output, $path); $this->process->execute(sprintf('git remote set-url origin -- %s', ProcessExecutor::escape($url)), $output, $path);
$this->setPushUrl($path, $url); $this->setPushUrl($path, $url);
@ -517,7 +517,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* *
* @return void * @return void
*/ */
protected function setPushUrl(string $path, string $url) protected function setPushUrl(string $path, string $url): void
{ {
// set push url for github projects // set push url for github projects
if (Preg::isMatch('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) { if (Preg::isMatch('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) {
@ -534,7 +534,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function getCommitLogs(string $fromReference, string $toReference, string $path) protected function getCommitLogs(string $fromReference, string $toReference, string $path): string
{ {
$path = $this->normalizePath($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)); $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 * @throws \RuntimeException
*/ */
protected function discardChanges(string $path) protected function discardChanges(string $path): PromiseInterface
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (0 !== $this->process->execute('git clean -df && git reset --hard', $output, $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 * @throws \RuntimeException
*/ */
protected function stashChanges(string $path) protected function stashChanges(string $path): PromiseInterface
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (0 !== $this->process->execute('git stash --include-untracked', $output, $path)) { if (0 !== $this->process->execute('git stash --include-untracked', $output, $path)) {
@ -591,7 +591,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* *
* @throws \RuntimeException * @throws \RuntimeException
*/ */
protected function viewDiff(string $path) protected function viewDiff(string $path): void
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (0 !== $this->process->execute('git diff HEAD', $output, $path)) { if (0 !== $this->process->execute('git diff HEAD', $output, $path)) {
@ -606,7 +606,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* *
* @return string * @return string
*/ */
protected function normalizePath(string $path) protected function normalizePath(string $path): string
{ {
if (Platform::isWindows() && strlen($path) > 0) { if (Platform::isWindows() && strlen($path) > 0) {
$basePath = $path; $basePath = $path;
@ -630,7 +630,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function hasMetadataRepository(string $path) protected function hasMetadataRepository(string $path): bool
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -641,7 +641,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
* @param string $reference * @param string $reference
* @return string * @return string
*/ */
protected function getShortHash(string $reference) protected function getShortHash(string $reference): string
{ {
if (!$this->io->isVerbose() && Preg::isMatch('{^[0-9a-f]{40}$}', $reference)) { if (!$this->io->isVerbose() && Preg::isMatch('{^[0-9a-f]{40}$}', $reference)) {
return substr($reference, 0, 10); return substr($reference, 0, 10);

View File

@ -24,7 +24,7 @@ use Composer\Util\ProcessExecutor;
*/ */
class GzipDownloader extends ArchiveDownloader class GzipDownloader extends ArchiveDownloader
{ {
protected function extract(PackageInterface $package, string $file, string $path): ?PromiseInterface protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface
{ {
$filename = pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_FILENAME); $filename = pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_FILENAME);
$targetFilepath = $path . DIRECTORY_SEPARATOR . $filename; $targetFilepath = $path . DIRECTORY_SEPARATOR . $filename;

View File

@ -25,7 +25,7 @@ class HgDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): PromiseInterface
{ {
if (null === HgUtils::getVersion($this->process)) { if (null === HgUtils::getVersion($this->process)) {
throw new \RuntimeException('hg was not found in your PATH, skipping source download'); throw new \RuntimeException('hg was not found in your PATH, skipping source download');
@ -37,7 +37,7 @@ class HgDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface
{ {
$hgUtils = new HgUtils($this->io, $this->config, $this->process); $hgUtils = new HgUtils($this->io, $this->config, $this->process);
@ -59,7 +59,7 @@ class HgDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface
{ {
$hgUtils = new HgUtils($this->io, $this->config, $this->process); $hgUtils = new HgUtils($this->io, $this->config, $this->process);

View File

@ -39,7 +39,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true): ?PromiseInterface public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true): PromiseInterface
{ {
$path = Filesystem::trimTrailingSlash($path); $path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl(); $url = $package->getDistUrl();
@ -75,7 +75,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function install(PackageInterface $package, string $path, bool $output = true): ?PromiseInterface public function install(PackageInterface $package, string $path, bool $output = true): PromiseInterface
{ {
$path = Filesystem::trimTrailingSlash($path); $path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl(); $url = $package->getDistUrl();
@ -161,7 +161,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function remove(PackageInterface $package, string $path, bool $output = true): ?PromiseInterface public function remove(PackageInterface $package, string $path, bool $output = true): PromiseInterface
{ {
$path = Filesystem::trimTrailingSlash($path); $path = Filesystem::trimTrailingSlash($path);
/** /**
@ -250,7 +250,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
* *
* @phpstan-return array{self::STRATEGY_*, non-empty-list<self::STRATEGY_*>} * @phpstan-return array{self::STRATEGY_*, non-empty-list<self::STRATEGY_*>}
*/ */
private function computeAllowedStrategies(array $transportOptions) private function computeAllowedStrategies(array $transportOptions): array
{ {
// When symlink transport option is null, both symlink and mirror are allowed // When symlink transport option is null, both symlink and mirror are allowed
$currentStrategy = self::STRATEGY_SYMLINK; $currentStrategy = self::STRATEGY_SYMLINK;

View File

@ -28,7 +28,7 @@ class PerforceDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): ?PromiseInterface protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): PromiseInterface
{ {
return \React\Promise\resolve(); return \React\Promise\resolve();
} }
@ -36,7 +36,7 @@ class PerforceDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface public function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface
{ {
$ref = $package->getSourceReference(); $ref = $package->getSourceReference();
$label = $this->getLabelFromSourceReference((string) $ref); $label = $this->getLabelFromSourceReference((string) $ref);
@ -101,7 +101,7 @@ class PerforceDownloader extends VcsDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): ?PromiseInterface protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface
{ {
return $this->doInstall($target, $path, $url); return $this->doInstall($target, $path, $url);
} }

View File

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@
namespace Composer\Downloader; namespace Composer\Downloader;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use React\Promise\PromiseInterface;
/** /**
* Downloader for tar files: tar, tar.gz or tar.bz2 * Downloader for tar files: tar, tar.gz or tar.bz2
@ -24,7 +25,7 @@ class TarDownloader extends ArchiveDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function extract(PackageInterface $package, string $file, string $path) protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface
{ {
// Can throw an UnexpectedValueException // Can throw an UnexpectedValueException
$archive = new \PharData($file); $archive = new \PharData($file);

View File

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

View File

@ -52,7 +52,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getInstallationSource() public function getInstallationSource(): string
{ {
return 'source'; return 'source';
} }
@ -60,7 +60,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
if (!$package->getSourceReference()) { if (!$package->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
@ -93,7 +93,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function prepare(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
if ($type === 'update') { if ($type === 'update') {
$this->cleanChanges($prevPackage, $path, true); $this->cleanChanges($prevPackage, $path, true);
@ -110,7 +110,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null) public function cleanup(string $type, PackageInterface $package, string $path, PackageInterface $prevPackage = null): PromiseInterface
{ {
if ($type === 'update' && isset($this->hasCleanedChanges[$prevPackage->getUniqueName()])) { if ($type === 'update' && isset($this->hasCleanedChanges[$prevPackage->getUniqueName()])) {
$this->reapplyChanges($path); $this->reapplyChanges($path);
@ -123,7 +123,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function install(PackageInterface $package, string $path) public function install(PackageInterface $package, string $path): PromiseInterface
{ {
if (!$package->getSourceReference()) { if (!$package->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
@ -158,7 +158,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function update(PackageInterface $initial, PackageInterface $target, string $path) public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface
{ {
if (!$target->getSourceReference()) { if (!$target->getSourceReference()) {
throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information'); throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
@ -222,7 +222,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function remove(PackageInterface $package, string $path) public function remove(PackageInterface $package, string $path): PromiseInterface
{ {
$this->io->writeError(" - " . UninstallOperation::format($package)); $this->io->writeError(" - " . UninstallOperation::format($package));
@ -238,7 +238,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getVcsReference(PackageInterface $package, string $path) public function getVcsReference(PackageInterface $package, string $path): ?string
{ {
$parser = new VersionParser; $parser = new VersionParser;
$guesser = new VersionGuesser($this->config, $this->process, $parser); $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 * @throws \RuntimeException in case the operation must be aborted
*/ */
protected function cleanChanges(PackageInterface $package, string $path, bool $update) protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface
{ {
// the default implementation just fails if there are any changes, override in child classes to provide stash-ability // the default implementation just fails if there are any changes, override in child classes to provide stash-ability
if (null !== $this->getLocalChanges($package, $path)) { 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 * @throws \RuntimeException in case the operation must be aborted or the patch does not apply cleanly
*/ */
protected function reapplyChanges(string $path) protected function reapplyChanges(string $path): void
{ {
} }
@ -295,9 +295,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $url package url * @param string $url package url
* @param PackageInterface|null $prevPackage previous package (in case of an update) * @param PackageInterface|null $prevPackage previous package (in case of an update)
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
abstract protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null); abstract protected function doDownload(PackageInterface $package, string $path, string $url, PackageInterface $prevPackage = null): PromiseInterface;
/** /**
* Downloads specific package into specific folder. * Downloads specific package into specific folder.
@ -306,9 +306,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path download path * @param string $path download path
* @param string $url package url * @param string $url package url
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
abstract protected function doInstall(PackageInterface $package, string $path, string $url); abstract protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface;
/** /**
* Updates specific package in specific folder from initial to target version. * Updates specific package in specific folder from initial to target version.
@ -318,9 +318,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path download path * @param string $path download path
* @param string $url package url * @param string $url package url
* *
* @return PromiseInterface|null * @return PromiseInterface
*/ */
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url); abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface;
/** /**
* Fetches the commit logs between two commits * Fetches the commit logs between two commits
@ -330,7 +330,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path the package path * @param string $path the package path
* @return string * @return string
*/ */
abstract protected function getCommitLogs(string $fromReference, string $toReference, string $path); abstract protected function getCommitLogs(string $fromReference, string $toReference, string $path): string;
/** /**
* Checks if VCS metadata repository has been initialized * Checks if VCS metadata repository has been initialized
@ -339,7 +339,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path * @param string $path
* @return bool * @return bool
*/ */
abstract protected function hasMetadataRepository(string $path); abstract protected function hasMetadataRepository(string $path): bool;
/** /**
* @param string[] $urls * @param string[] $urls

View File

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

View File

@ -39,7 +39,7 @@ class ZipDownloader extends ArchiveDownloader
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true) public function download(PackageInterface $package, string $path, PackageInterface $prevPackage = null, bool $output = true): PromiseInterface
{ {
if (null === self::$unzipCommands) { if (null === self::$unzipCommands) {
self::$unzipCommands = array(); self::$unzipCommands = array();
@ -206,9 +206,9 @@ class ZipDownloader extends ArchiveDownloader
* *
* @param string $file File to extract * @param string $file File to extract
* @param string $path Path where to extract file * @param string $path Path where to extract file
* @return PromiseInterface|null * @return PromiseInterface
*/ */
protected function extract(PackageInterface $package, string $file, string $path) protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface
{ {
return $this->extractWithSystemUnzip($package, $file, $path); return $this->extractWithSystemUnzip($package, $file, $path);
} }

View File

@ -58,7 +58,7 @@ class Event
* *
* @return string The event name * @return string The event name
*/ */
public function getName() public function getName(): string
{ {
return $this->name; return $this->name;
} }
@ -68,7 +68,7 @@ class Event
* *
* @return string[] The event arguments * @return string[] The event arguments
*/ */
public function getArguments() public function getArguments(): array
{ {
return $this->args; return $this->args;
} }
@ -78,7 +78,7 @@ class Event
* *
* @return mixed[] The event flags * @return mixed[] The event flags
*/ */
public function getFlags() public function getFlags(): array
{ {
return $this->flags; return $this->flags;
} }
@ -88,7 +88,7 @@ class Event
* *
* @return bool Whether propagation has been stopped * @return bool Whether propagation has been stopped
*/ */
public function isPropagationStopped() public function isPropagationStopped(): bool
{ {
return $this->propagationStopped; return $this->propagationStopped;
} }
@ -98,7 +98,7 @@ class Event
* *
* @return void * @return void
*/ */
public function stopPropagation() public function stopPropagation(): void
{ {
$this->propagationStopped = true; $this->propagationStopped = true;
} }

View File

@ -96,7 +96,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @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 * value is changed to 1, anything else to 0
*/ */
public function dispatch(string $eventName, Event $event = null) public function dispatch(string $eventName, Event $event = null): int
{ {
if (null === $event) { if (null === $event) {
$event = new Event($eventName); $event = new Event($eventName);
@ -115,7 +115,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @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 * value is changed to 1, anything else to 0
*/ */
public function dispatchScript(string $eventName, bool $devMode = false, array $additionalArgs = array(), array $flags = array()) public function dispatchScript(string $eventName, bool $devMode = false, array $additionalArgs = array(), array $flags = array()): int
{ {
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer')); assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -134,7 +134,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @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 * value is changed to 1, anything else to 0
*/ */
public function dispatchPackageEvent(string $eventName, bool $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation) public function dispatchPackageEvent(string $eventName, bool $devMode, RepositoryInterface $localRepo, array $operations, OperationInterface $operation): int
{ {
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer')); assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -152,7 +152,7 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @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 * value is changed to 1, anything else to 0
*/ */
public function dispatchInstallerEvent(string $eventName, bool $devMode, bool $executeOperations, Transaction $transaction) public function dispatchInstallerEvent(string $eventName, bool $devMode, bool $executeOperations, Transaction $transaction): int
{ {
assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer')); assert($this->composer instanceof Composer, new \LogicException('This should only be reached with a fully loaded Composer'));
@ -342,7 +342,7 @@ class EventDispatcher
* *
* @return int * @return int
*/ */
protected function executeTty(string $exec) protected function executeTty(string $exec): int
{ {
if ($this->io->isInteractive()) { if ($this->io->isInteractive()) {
return $this->process->executeTty($exec); return $this->process->executeTty($exec);
@ -354,7 +354,7 @@ class EventDispatcher
/** /**
* @return string * @return string
*/ */
protected function getPhpExecCommand() protected function getPhpExecCommand(): string
{ {
$finder = new PhpExecutableFinder(); $finder = new PhpExecutableFinder();
$phpPath = $finder->find(false); $phpPath = $finder->find(false);
@ -397,7 +397,7 @@ class EventDispatcher
* *
* @return void * @return void
*/ */
public function addListener(string $eventName, callable $listener, int $priority = 0) public function addListener(string $eventName, callable $listener, int $priority = 0): void
{ {
$this->listeners[$eventName][$priority][] = $listener; $this->listeners[$eventName][$priority][] = $listener;
} }
@ -407,7 +407,7 @@ class EventDispatcher
* *
* @return void * @return void
*/ */
public function removeListener($listener) public function removeListener($listener): void
{ {
foreach ($this->listeners as $eventName => $priorities) { foreach ($this->listeners as $eventName => $priorities) {
foreach ($priorities as $priority => $listeners) { foreach ($priorities as $priority => $listeners) {
@ -429,7 +429,7 @@ class EventDispatcher
* *
* @return void * @return void
*/ */
public function addSubscriber(EventSubscriberInterface $subscriber) public function addSubscriber(EventSubscriberInterface $subscriber): void
{ {
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) { foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) { if (is_string($params)) {
@ -450,7 +450,7 @@ class EventDispatcher
* @param Event $event * @param Event $event
* @return array<callable|string> All listeners: callables and scripts * @return array<callable|string> All listeners: callables and scripts
*/ */
protected function getListeners(Event $event) protected function getListeners(Event $event): array
{ {
$scriptListeners = $this->runScripts ? $this->getScriptListeners($event) : array(); $scriptListeners = $this->runScripts ? $this->getScriptListeners($event) : array();
@ -471,7 +471,7 @@ class EventDispatcher
* @param Event $event * @param Event $event
* @return bool * @return bool
*/ */
public function hasEventListeners(Event $event) public function hasEventListeners(Event $event): bool
{ {
$listeners = $this->getListeners($event); $listeners = $this->getListeners($event);
@ -484,7 +484,7 @@ class EventDispatcher
* @param Event $event Event object * @param Event $event Event object
* @return string[] Listeners * @return string[] Listeners
*/ */
protected function getScriptListeners(Event $event) protected function getScriptListeners(Event $event): array
{ {
$package = $this->composer->getPackage(); $package = $this->composer->getPackage();
$scripts = $package->getScripts(); $scripts = $package->getScripts();
@ -519,7 +519,7 @@ class EventDispatcher
* @param string $callable * @param string $callable
* @return bool * @return bool
*/ */
protected function isPhpScript(string $callable) protected function isPhpScript(string $callable): bool
{ {
return false === strpos($callable, ' ') && false !== strpos($callable, '::'); return false === strpos($callable, ' ') && false !== strpos($callable, '::');
} }
@ -530,7 +530,7 @@ class EventDispatcher
* @param string $callable * @param string $callable
* @return bool * @return bool
*/ */
protected function isComposerScript(string $callable) protected function isComposerScript(string $callable): bool
{ {
return strpos($callable, '@') === 0 && strpos($callable, '@php ') !== 0 && strpos($callable, '@putenv ') !== 0; return strpos($callable, '@') === 0 && strpos($callable, '@php ') !== 0 && strpos($callable, '@putenv ') !== 0;
} }
@ -542,7 +542,7 @@ class EventDispatcher
* @throws \RuntimeException * @throws \RuntimeException
* @return int * @return int
*/ */
protected function pushEvent(Event $event) protected function pushEvent(Event $event): int
{ {
$eventName = $event->getName(); $eventName = $event->getName();
if (in_array($eventName, $this->eventStack)) { if (in_array($eventName, $this->eventStack)) {
@ -557,7 +557,7 @@ class EventDispatcher
* *
* @return string|null * @return string|null
*/ */
protected function popEvent() protected function popEvent(): ?string
{ {
return array_pop($this->eventStack); return array_pop($this->eventStack);
} }

View File

@ -63,7 +63,7 @@ class InstallationManager
/** /**
* @return void * @return void
*/ */
public function reset() public function reset(): void
{ {
$this->notifiablePackages = array(); $this->notifiablePackages = array();
FileDownloader::$downloadMetadata = array(); FileDownloader::$downloadMetadata = array();
@ -76,7 +76,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function addInstaller(InstallerInterface $installer) public function addInstaller(InstallerInterface $installer): void
{ {
array_unshift($this->installers, $installer); array_unshift($this->installers, $installer);
$this->cache = array(); $this->cache = array();
@ -89,7 +89,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function removeInstaller(InstallerInterface $installer) public function removeInstaller(InstallerInterface $installer): void
{ {
if (false !== ($key = array_search($installer, $this->installers, true))) { if (false !== ($key = array_search($installer, $this->installers, true))) {
array_splice($this->installers, $key, 1); array_splice($this->installers, $key, 1);
@ -106,7 +106,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function disablePlugins() public function disablePlugins(): void
{ {
foreach ($this->installers as $i => $installer) { foreach ($this->installers as $i => $installer) {
if (!$installer instanceof PluginInstaller) { if (!$installer instanceof PluginInstaller) {
@ -125,7 +125,7 @@ class InstallationManager
* @throws \InvalidArgumentException if installer for provided type is not registered * @throws \InvalidArgumentException if installer for provided type is not registered
* @return InstallerInterface * @return InstallerInterface
*/ */
public function getInstaller(string $type) public function getInstaller(string $type): InstallerInterface
{ {
$type = strtolower($type); $type = strtolower($type);
@ -150,7 +150,7 @@ class InstallationManager
* *
* @return bool * @return bool
*/ */
public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool
{ {
if ($package instanceof AliasPackage) { if ($package instanceof AliasPackage) {
return $repo->hasPackage($package) && $this->isPackageInstalled($repo, $package->getAliasOf()); return $repo->hasPackage($package) && $this->isPackageInstalled($repo, $package->getAliasOf());
@ -167,7 +167,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function ensureBinariesPresence(PackageInterface $package) public function ensureBinariesPresence(PackageInterface $package): void
{ {
try { try {
$installer = $this->getInstaller($package->getType()); $installer = $this->getInstaller($package->getType());
@ -192,7 +192,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function execute(InstalledRepositoryInterface $repo, array $operations, bool $devMode = true, bool $runScripts = true) public function execute(InstalledRepositoryInterface $repo, array $operations, bool $devMode = true, bool $runScripts = true): void
{ {
/** @var PromiseInterface[] */ /** @var PromiseInterface[] */
$cleanupPromises = array(); $cleanupPromises = array();
@ -511,7 +511,7 @@ class InstallationManager
* *
* @return PromiseInterface|null * @return PromiseInterface|null
*/ */
public function install(InstalledRepositoryInterface $repo, InstallOperation $operation) public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface
{ {
$package = $operation->getPackage(); $package = $operation->getPackage();
$installer = $this->getInstaller($package->getType()); $installer = $this->getInstaller($package->getType());
@ -529,7 +529,7 @@ class InstallationManager
* *
* @return PromiseInterface|null * @return PromiseInterface|null
*/ */
public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation) public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface
{ {
$initial = $operation->getInitialPackage(); $initial = $operation->getInitialPackage();
$target = $operation->getTargetPackage(); $target = $operation->getTargetPackage();
@ -569,7 +569,7 @@ class InstallationManager
* *
* @return PromiseInterface|null * @return PromiseInterface|null
*/ */
public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation) public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface
{ {
$package = $operation->getPackage(); $package = $operation->getPackage();
$installer = $this->getInstaller($package->getType()); $installer = $this->getInstaller($package->getType());
@ -585,7 +585,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation) public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation): void
{ {
$package = $operation->getPackage(); $package = $operation->getPackage();
@ -602,7 +602,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation) public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation): void
{ {
$package = $operation->getPackage(); $package = $operation->getPackage();
@ -615,7 +615,7 @@ class InstallationManager
* @param PackageInterface $package * @param PackageInterface $package
* @return string path * @return string path
*/ */
public function getInstallPath(PackageInterface $package) public function getInstallPath(PackageInterface $package): string
{ {
$installer = $this->getInstaller($package->getType()); $installer = $this->getInstaller($package->getType());
@ -627,7 +627,7 @@ class InstallationManager
* *
* @return void * @return void
*/ */
public function setOutputProgress(bool $outputProgress) public function setOutputProgress(bool $outputProgress): void
{ {
$this->outputProgress = $outputProgress; $this->outputProgress = $outputProgress;
} }
@ -635,7 +635,7 @@ class InstallationManager
/** /**
* @return void * @return void
*/ */
public function notifyInstalls(IOInterface $io) public function notifyInstalls(IOInterface $io): void
{ {
$promises = array(); $promises = array();

View File

@ -68,7 +68,7 @@ class InstallerEvent extends Event
/** /**
* @return Composer * @return Composer
*/ */
public function getComposer() public function getComposer(): Composer
{ {
return $this->composer; return $this->composer;
} }
@ -76,7 +76,7 @@ class InstallerEvent extends Event
/** /**
* @return IOInterface * @return IOInterface
*/ */
public function getIO() public function getIO(): IOInterface
{ {
return $this->io; return $this->io;
} }
@ -84,7 +84,7 @@ class InstallerEvent extends Event
/** /**
* @return bool * @return bool
*/ */
public function isDevMode() public function isDevMode(): bool
{ {
return $this->devMode; return $this->devMode;
} }
@ -92,7 +92,7 @@ class InstallerEvent extends Event
/** /**
* @return bool * @return bool
*/ */
public function isExecutingOperations() public function isExecutingOperations(): bool
{ {
return $this->executeOperations; return $this->executeOperations;
} }
@ -100,7 +100,7 @@ class InstallerEvent extends Event
/** /**
* @return Transaction|null * @return Transaction|null
*/ */
public function getTransaction() public function getTransaction(): ?Transaction
{ {
return $this->transaction; return $this->transaction;
} }

View File

@ -81,7 +81,7 @@ class PackageEvent extends Event
/** /**
* @return Composer * @return Composer
*/ */
public function getComposer() public function getComposer(): Composer
{ {
return $this->composer; return $this->composer;
} }
@ -89,7 +89,7 @@ class PackageEvent extends Event
/** /**
* @return IOInterface * @return IOInterface
*/ */
public function getIO() public function getIO(): IOInterface
{ {
return $this->io; return $this->io;
} }
@ -97,7 +97,7 @@ class PackageEvent extends Event
/** /**
* @return bool * @return bool
*/ */
public function isDevMode() public function isDevMode(): bool
{ {
return $this->devMode; return $this->devMode;
} }
@ -105,7 +105,7 @@ class PackageEvent extends Event
/** /**
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public function getLocalRepo() public function getLocalRepo(): RepositoryInterface
{ {
return $this->localRepo; return $this->localRepo;
} }
@ -113,7 +113,7 @@ class PackageEvent extends Event
/** /**
* @return OperationInterface[] * @return OperationInterface[]
*/ */
public function getOperations() public function getOperations(): array
{ {
return $this->operations; return $this->operations;
} }
@ -123,7 +123,7 @@ class PackageEvent extends Event
* *
* @return OperationInterface * @return OperationInterface
*/ */
public function getOperation() public function getOperation(): OperationInterface
{ {
return $this->operation; return $this->operation;
} }

View File

@ -69,7 +69,7 @@ class JsonFile
/** /**
* @return string * @return string
*/ */
public function getPath() public function getPath(): string
{ {
return $this->path; return $this->path;
} }
@ -79,7 +79,7 @@ class JsonFile
* *
* @return bool * @return bool
*/ */
public function exists() public function exists(): bool
{ {
return is_file($this->path); return is_file($this->path);
} }
@ -188,7 +188,7 @@ class JsonFile
* @throws ParsingException * @throws ParsingException
* @return bool true on success * @return bool true on success
*/ */
public function validateSchema(int $schema = self::STRICT_SCHEMA, ?string $schemaFile = null) public function validateSchema(int $schema = self::STRICT_SCHEMA, ?string $schemaFile = null): bool
{ {
$content = file_get_contents($this->path); $content = file_get_contents($this->path);
$data = json_decode($content); $data = json_decode($content);
@ -309,7 +309,7 @@ class JsonFile
* @throws ParsingException * @throws ParsingException
* @return bool true on success * @return bool true on success
*/ */
protected static function validateSyntax(string $json, string $file = null) protected static function validateSyntax(string $json, string $file = null): bool
{ {
$parser = new JsonParser(); $parser = new JsonParser();
$result = $parser->lint($json); $result = $parser->lint($json);

View File

@ -58,7 +58,7 @@ class JsonManipulator
/** /**
* @return string * @return string
*/ */
public function getContents() public function getContents(): string
{ {
return $this->contents . $this->newline; return $this->contents . $this->newline;
} }
@ -70,7 +70,7 @@ class JsonManipulator
* @param bool $sortPackages * @param bool $sortPackages
* @return bool * @return bool
*/ */
public function addLink(string $type, string $package, string $constraint, bool $sortPackages = false) public function addLink(string $type, string $package, string $constraint, bool $sortPackages = false): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
@ -170,7 +170,7 @@ class JsonManipulator
* @param bool $append * @param bool $append
* @return bool * @return bool
*/ */
public function addRepository(string $name, $config, bool $append = true) public function addRepository(string $name, $config, bool $append = true): bool
{ {
return $this->addSubNode('repositories', $name, $config, $append); return $this->addSubNode('repositories', $name, $config, $append);
} }
@ -179,7 +179,7 @@ class JsonManipulator
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function removeRepository(string $name) public function removeRepository(string $name): bool
{ {
return $this->removeSubNode('repositories', $name); return $this->removeSubNode('repositories', $name);
} }
@ -189,7 +189,7 @@ class JsonManipulator
* @param mixed $value * @param mixed $value
* @return bool * @return bool
*/ */
public function addConfigSetting(string $name, $value) public function addConfigSetting(string $name, $value): bool
{ {
return $this->addSubNode('config', $name, $value); return $this->addSubNode('config', $name, $value);
} }
@ -198,7 +198,7 @@ class JsonManipulator
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function removeConfigSetting(string $name) public function removeConfigSetting(string $name): bool
{ {
return $this->removeSubNode('config', $name); return $this->removeSubNode('config', $name);
} }
@ -208,7 +208,7 @@ class JsonManipulator
* @param mixed $value * @param mixed $value
* @return bool * @return bool
*/ */
public function addProperty(string $name, $value) public function addProperty(string $name, $value): bool
{ {
if (strpos($name, 'suggest.') === 0) { if (strpos($name, 'suggest.') === 0) {
return $this->addSubNode('suggest', substr($name, 8), $value); return $this->addSubNode('suggest', substr($name, 8), $value);
@ -229,7 +229,7 @@ class JsonManipulator
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function removeProperty(string $name) public function removeProperty(string $name): bool
{ {
if (strpos($name, 'suggest.') === 0) { if (strpos($name, 'suggest.') === 0) {
return $this->removeSubNode('suggest', substr($name, 8)); return $this->removeSubNode('suggest', substr($name, 8));
@ -253,7 +253,7 @@ class JsonManipulator
* @param bool $append * @param bool $append
* @return bool * @return bool
*/ */
public function addSubNode(string $mainNode, string $name, $value, bool $append = true) public function addSubNode(string $mainNode, string $name, $value, bool $append = true): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
@ -363,7 +363,7 @@ class JsonManipulator
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function removeSubNode(string $mainNode, string $name) public function removeSubNode(string $mainNode, string $name): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
@ -468,7 +468,7 @@ class JsonManipulator
* @param mixed $content * @param mixed $content
* @return bool * @return bool
*/ */
public function addMainKey(string $key, $content) public function addMainKey(string $key, $content): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
$content = $this->format($content); $content = $this->format($content);
@ -512,7 +512,7 @@ class JsonManipulator
* @param string $key * @param string $key
* @return bool * @return bool
*/ */
public function removeMainKey(string $key) public function removeMainKey(string $key): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
@ -549,7 +549,7 @@ class JsonManipulator
* @param string $key * @param string $key
* @return bool * @return bool
*/ */
public function removeMainKeyIfEmpty(string $key) public function removeMainKeyIfEmpty(string $key): bool
{ {
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
@ -569,7 +569,7 @@ class JsonManipulator
* @param int $depth * @param int $depth
* @return string * @return string
*/ */
public function format($data, int $depth = 0) public function format($data, int $depth = 0): string
{ {
if (is_array($data)) { if (is_array($data)) {
reset($data); reset($data);
@ -597,7 +597,7 @@ class JsonManipulator
/** /**
* @return void * @return void
*/ */
protected function detectIndenting() protected function detectIndenting(): void
{ {
if (Preg::isMatch('{^([ \t]+)"}m', $this->contents, $match)) { if (Preg::isMatch('{^([ \t]+)"}m', $this->contents, $match)) {
$this->indent = $match[1]; $this->indent = $match[1];

View File

@ -159,14 +159,10 @@ class AliasPackage extends BasePackage
* Stores whether this is an alias created by an aliasing in the requirements of the root package or not * Stores whether this is an alias created by an aliasing in the requirements of the root package or not
* *
* Use by the policy for sorting manually aliased packages first, see #576 * Use by the policy for sorting manually aliased packages first, see #576
*
* @param bool $value
*
* @return mixed
*/ */
public function setRootPackageAlias(bool $value) public function setRootPackageAlias(bool $value): void
{ {
return $this->rootPackageAlias = $value; $this->rootPackageAlias = $value;
} }
/** /**
@ -225,7 +221,7 @@ class AliasPackage extends BasePackage
return $this->hasSelfVersionRequires; return $this->hasSelfVersionRequires;
} }
public function __toString() public function __toString(): string
{ {
return parent::__toString().' ('.($this->rootPackageAlias ? 'root ' : ''). 'alias of '.$this->aliasOf->getVersion().')'; return parent::__toString().' ('.($this->rootPackageAlias ? 'root ' : ''). 'alias of '.$this->aliasOf->getVersion().')';
} }

View File

@ -78,7 +78,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getName() public function getName(): string
{ {
return $this->name; return $this->name;
} }
@ -86,7 +86,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getPrettyName() public function getPrettyName(): string
{ {
return $this->prettyName; return $this->prettyName;
} }
@ -94,7 +94,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getNames($provides = true) public function getNames($provides = true): array
{ {
$names = array( $names = array(
$this->getName() => true, $this->getName() => true,
@ -116,7 +116,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setId($id) public function setId(int $id): void
{ {
$this->id = $id; $this->id = $id;
} }
@ -124,7 +124,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getId() public function getId(): int
{ {
return $this->id; return $this->id;
} }
@ -132,7 +132,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setRepository(RepositoryInterface $repository) public function setRepository(RepositoryInterface $repository): void
{ {
if ($this->repository && $repository !== $this->repository) { if ($this->repository && $repository !== $this->repository) {
throw new \LogicException('A package can only be added to one repository'); throw new \LogicException('A package can only be added to one repository');
@ -143,7 +143,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRepository() public function getRepository(): ?RepositoryInterface
{ {
return $this->repository; return $this->repository;
} }
@ -153,7 +153,7 @@ abstract class BasePackage implements PackageInterface
* *
* @return bool * @return bool
*/ */
public function isPlatform() public function isPlatform(): bool
{ {
return $this->getRepository() instanceof PlatformRepository; return $this->getRepository() instanceof PlatformRepository;
} }
@ -163,7 +163,7 @@ abstract class BasePackage implements PackageInterface
* *
* @return string * @return string
*/ */
public function getUniqueName() public function getUniqueName(): string
{ {
return $this->getName().'-'.$this->getVersion(); return $this->getName().'-'.$this->getVersion();
} }
@ -171,7 +171,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @return bool * @return bool
*/ */
public function equals(PackageInterface $package) public function equals(PackageInterface $package): bool
{ {
$self = $this; $self = $this;
if ($this instanceof AliasPackage) { if ($this instanceof AliasPackage) {
@ -189,12 +189,12 @@ abstract class BasePackage implements PackageInterface
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->getUniqueName(); return $this->getUniqueName();
} }
public function getPrettyString() public function getPrettyString(): string
{ {
return $this->getPrettyName().' '.$this->getPrettyVersion(); return $this->getPrettyName().' '.$this->getPrettyVersion();
} }
@ -202,7 +202,7 @@ abstract class BasePackage implements PackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFullPrettyVersion($truncate = true, $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV) public function getFullPrettyVersion(bool $truncate = true, int $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV): string
{ {
if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV && if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV &&
(!$this->isDev() || !\in_array($this->getSourceType(), array('hg', 'git'))) (!$this->isDev() || !\in_array($this->getSourceType(), array('hg', 'git')))
@ -239,7 +239,7 @@ abstract class BasePackage implements PackageInterface
* *
* @phpstan-return self::STABILITY_* * @phpstan-return self::STABILITY_*
*/ */
public function getStabilityPriority() public function getStabilityPriority(): int
{ {
return self::$stabilities[$this->getStability()]; return self::$stabilities[$this->getStability()];
} }
@ -257,7 +257,7 @@ abstract class BasePackage implements PackageInterface
* @param non-empty-string $wrap Wrap the cleaned string by the given string * @param non-empty-string $wrap Wrap the cleaned string by the given string
* @return non-empty-string * @return non-empty-string
*/ */
public static function packageNameToRegexp(string $allowPattern, string $wrap = '{^%s$}i') public static function packageNameToRegexp(string $allowPattern, string $wrap = '{^%s$}i'): string
{ {
$cleanedAllowPattern = str_replace('\\*', '.*', preg_quote($allowPattern)); $cleanedAllowPattern = str_replace('\\*', '.*', preg_quote($allowPattern));
@ -271,7 +271,7 @@ abstract class BasePackage implements PackageInterface
* @param non-empty-string $wrap * @param non-empty-string $wrap
* @return non-empty-string * @return non-empty-string
*/ */
public static function packageNamesToRegexp(array $packageNames, string $wrap = '{^(?:%s)$}iD') public static function packageNamesToRegexp(array $packageNames, string $wrap = '{^(?:%s)$}iD'): string
{ {
$packageNames = array_map( $packageNames = array_map(
function ($packageName): string { function ($packageName): string {

View File

@ -47,7 +47,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setScripts(array $scripts) public function setScripts(array $scripts): void
{ {
$this->scripts = $scripts; $this->scripts = $scripts;
} }
@ -55,7 +55,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getScripts() public function getScripts(): array
{ {
return $this->scripts; return $this->scripts;
} }
@ -63,7 +63,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setRepositories(array $repositories) public function setRepositories(array $repositories): void
{ {
$this->repositories = $repositories; $this->repositories = $repositories;
} }
@ -71,7 +71,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRepositories() public function getRepositories(): array
{ {
return $this->repositories; return $this->repositories;
} }
@ -79,7 +79,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setLicense(array $license) public function setLicense(array $license): void
{ {
$this->license = $license; $this->license = $license;
} }
@ -87,7 +87,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLicense() public function getLicense(): array
{ {
return $this->license; return $this->license;
} }
@ -95,7 +95,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setKeywords(array $keywords) public function setKeywords(array $keywords): void
{ {
$this->keywords = $keywords; $this->keywords = $keywords;
} }
@ -103,7 +103,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getKeywords() public function getKeywords(): array
{ {
return $this->keywords; return $this->keywords;
} }
@ -111,7 +111,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setAuthors(array $authors) public function setAuthors(array $authors): void
{ {
$this->authors = $authors; $this->authors = $authors;
} }
@ -119,7 +119,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getAuthors() public function getAuthors(): array
{ {
return $this->authors; return $this->authors;
} }
@ -127,7 +127,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setDescription(?string $description) public function setDescription(?string $description): void
{ {
$this->description = $description; $this->description = $description;
} }
@ -135,7 +135,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDescription() public function getDescription(): ?string
{ {
return $this->description; return $this->description;
} }
@ -143,7 +143,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setHomepage(?string $homepage) public function setHomepage(?string $homepage): void
{ {
$this->homepage = $homepage; $this->homepage = $homepage;
} }
@ -151,7 +151,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getHomepage() public function getHomepage(): ?string
{ {
return $this->homepage; return $this->homepage;
} }
@ -159,7 +159,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setSupport(array $support) public function setSupport(array $support): void
{ {
$this->support = $support; $this->support = $support;
} }
@ -167,7 +167,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSupport() public function getSupport(): array
{ {
return $this->support; return $this->support;
} }
@ -175,7 +175,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setFunding(array $funding) public function setFunding(array $funding): void
{ {
$this->funding = $funding; $this->funding = $funding;
} }
@ -183,7 +183,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFunding() public function getFunding(): array
{ {
return $this->funding; return $this->funding;
} }
@ -191,7 +191,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAbandoned() public function isAbandoned(): bool
{ {
return (bool) $this->abandoned; return (bool) $this->abandoned;
} }
@ -199,7 +199,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setAbandoned($abandoned) public function setAbandoned($abandoned): void
{ {
$this->abandoned = $abandoned; $this->abandoned = $abandoned;
} }
@ -207,7 +207,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getReplacementPackage() public function getReplacementPackage(): ?string
{ {
return \is_string($this->abandoned) ? $this->abandoned : null; return \is_string($this->abandoned) ? $this->abandoned : null;
} }
@ -215,7 +215,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setArchiveName(?string $name) public function setArchiveName(?string $name): void
{ {
$this->archiveName = $name; $this->archiveName = $name;
} }
@ -223,7 +223,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getArchiveName() public function getArchiveName(): ?string
{ {
return $this->archiveName; return $this->archiveName;
} }
@ -231,7 +231,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setArchiveExcludes(array $excludes) public function setArchiveExcludes(array $excludes): void
{ {
$this->archiveExcludes = $excludes; $this->archiveExcludes = $excludes;
} }
@ -239,7 +239,7 @@ class CompletePackage extends Package implements CompletePackageInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getArchiveExcludes() public function getArchiveExcludes(): array
{ {
return $this->archiveExcludes; return $this->archiveExcludes;
} }

View File

@ -15,6 +15,8 @@ namespace Composer\Package;
/** /**
* Defines package metadata that is not necessarily needed for solving and installing packages * Defines package metadata that is not necessarily needed for solving and installing packages
* *
* PackageInterface & derivatives are considered internal, you may use them in type hints but extending/implementing them is not recommended and not supported. Things may change without notice.
*
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
*/ */
interface CompletePackageInterface extends PackageInterface interface CompletePackageInterface extends PackageInterface
@ -24,20 +26,20 @@ interface CompletePackageInterface extends PackageInterface
* *
* @return array<string, string[]> Map of script name to array of handlers * @return array<string, string[]> Map of script name to array of handlers
*/ */
public function getScripts(); public function getScripts(): array;
/** /**
* @param array<string, string[]> $scripts * @param array<string, string[]> $scripts
* @return void * @return void
*/ */
public function setScripts(array $scripts); public function setScripts(array $scripts): void;
/** /**
* Returns an array of repositories * Returns an array of repositories
* *
* @return mixed[] Repositories * @return mixed[] Repositories
*/ */
public function getRepositories(); public function getRepositories(): array;
/** /**
* Set the repositories * Set the repositories
@ -45,14 +47,14 @@ interface CompletePackageInterface extends PackageInterface
* @param mixed[] $repositories * @param mixed[] $repositories
* @return void * @return void
*/ */
public function setRepositories(array $repositories); public function setRepositories(array $repositories): void;
/** /**
* Returns the package license, e.g. MIT, BSD, GPL * Returns the package license, e.g. MIT, BSD, GPL
* *
* @return string[] The package licenses * @return string[] The package licenses
*/ */
public function getLicense(); public function getLicense(): array;
/** /**
* Set the license * Set the license
@ -60,14 +62,14 @@ interface CompletePackageInterface extends PackageInterface
* @param string[] $license * @param string[] $license
* @return void * @return void
*/ */
public function setLicense(array $license); public function setLicense(array $license): void;
/** /**
* Returns an array of keywords relating to the package * Returns an array of keywords relating to the package
* *
* @return string[] * @return string[]
*/ */
public function getKeywords(); public function getKeywords(): array;
/** /**
* Set the keywords * Set the keywords
@ -75,14 +77,14 @@ interface CompletePackageInterface extends PackageInterface
* @param string[] $keywords * @param string[] $keywords
* @return void * @return void
*/ */
public function setKeywords(array $keywords); public function setKeywords(array $keywords): void;
/** /**
* Returns the package description * Returns the package description
* *
* @return ?string * @return ?string
*/ */
public function getDescription(); public function getDescription(): ?string;
/** /**
* Set the description * Set the description
@ -90,14 +92,14 @@ interface CompletePackageInterface extends PackageInterface
* @param string $description * @param string $description
* @return void * @return void
*/ */
public function setDescription(string $description); public function setDescription(string $description): void;
/** /**
* Returns the package homepage * Returns the package homepage
* *
* @return ?string * @return ?string
*/ */
public function getHomepage(); public function getHomepage(): ?string;
/** /**
* Set the homepage * Set the homepage
@ -105,7 +107,7 @@ interface CompletePackageInterface extends PackageInterface
* @param string $homepage * @param string $homepage
* @return void * @return void
*/ */
public function setHomepage(string $homepage); public function setHomepage(string $homepage): void;
/** /**
* Returns an array of authors of the package * Returns an array of authors of the package
@ -114,7 +116,7 @@ interface CompletePackageInterface extends PackageInterface
* *
* @return array<array{name?: string, homepage?: string, email?: string, role?: string}> * @return array<array{name?: string, homepage?: string, email?: string, role?: string}>
*/ */
public function getAuthors(); public function getAuthors(): array;
/** /**
* Set the authors * Set the authors
@ -122,14 +124,14 @@ interface CompletePackageInterface extends PackageInterface
* @param array<array{name?: string, homepage?: string, email?: string, role?: string}> $authors * @param array<array{name?: string, homepage?: string, email?: string, role?: string}> $authors
* @return void * @return void
*/ */
public function setAuthors(array $authors); public function setAuthors(array $authors): void;
/** /**
* Returns the support information * Returns the support information
* *
* @return array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} * @return array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string}
*/ */
public function getSupport(); public function getSupport(): array;
/** /**
* Set the support information * Set the support information
@ -137,7 +139,7 @@ interface CompletePackageInterface extends PackageInterface
* @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} $support * @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} $support
* @return void * @return void
*/ */
public function setSupport(array $support); public function setSupport(array $support): void;
/** /**
* Returns an array of funding options for the package * Returns an array of funding options for the package
@ -146,7 +148,7 @@ interface CompletePackageInterface extends PackageInterface
* *
* @return array<array{type?: string, url?: string}> * @return array<array{type?: string, url?: string}>
*/ */
public function getFunding(); public function getFunding(): array;
/** /**
* Set the funding * Set the funding
@ -154,34 +156,34 @@ interface CompletePackageInterface extends PackageInterface
* @param array<array{type?: string, url?: string}> $funding * @param array<array{type?: string, url?: string}> $funding
* @return void * @return void
*/ */
public function setFunding(array $funding); public function setFunding(array $funding): void;
/** /**
* Returns if the package is abandoned or not * Returns if the package is abandoned or not
* *
* @return bool * @return bool
*/ */
public function isAbandoned(); public function isAbandoned(): bool;
/** /**
* If the package is abandoned and has a suggested replacement, this method returns it * If the package is abandoned and has a suggested replacement, this method returns it
* *
* @return string|null * @return string|null
*/ */
public function getReplacementPackage(); public function getReplacementPackage(): ?string;
/** /**
* @param bool|string $abandoned * @param bool|string $abandoned
* @return void * @return void
*/ */
public function setAbandoned($abandoned); public function setAbandoned($abandoned): void;
/** /**
* Returns default base filename for archive * Returns default base filename for archive
* *
* @return ?string * @return ?string
*/ */
public function getArchiveName(); public function getArchiveName(): ?string;
/** /**
* Sets default base filename for archive * Sets default base filename for archive
@ -189,14 +191,14 @@ interface CompletePackageInterface extends PackageInterface
* @param string $name * @param string $name
* @return void * @return void
*/ */
public function setArchiveName(string $name); public function setArchiveName(string $name): void;
/** /**
* Returns a list of patterns to exclude from package archives * Returns a list of patterns to exclude from package archives
* *
* @return string[] * @return string[]
*/ */
public function getArchiveExcludes(); public function getArchiveExcludes(): array;
/** /**
* Sets a list of patterns to be excluded from archives * Sets a list of patterns to be excluded from archives
@ -204,5 +206,5 @@ interface CompletePackageInterface extends PackageInterface
* @param string[] $excludes * @param string[] $excludes
* @return void * @return void
*/ */
public function setArchiveExcludes(array $excludes); public function setArchiveExcludes(array $excludes): void;
} }

View File

@ -21,22 +21,22 @@ use Composer\Semver\Constraint\ConstraintInterface;
*/ */
class Link class Link
{ {
const TYPE_REQUIRE = 'requires'; public const TYPE_REQUIRE = 'requires';
const TYPE_DEV_REQUIRE = 'devRequires'; public const TYPE_DEV_REQUIRE = 'devRequires';
const TYPE_PROVIDE = 'provides'; public const TYPE_PROVIDE = 'provides';
const TYPE_CONFLICT = 'conflicts'; public const TYPE_CONFLICT = 'conflicts';
const TYPE_REPLACE = 'replaces'; public const TYPE_REPLACE = 'replaces';
/** /**
* Special type * Special type
* @internal * @internal
*/ */
const TYPE_DOES_NOT_REQUIRE = 'does not require'; public const TYPE_DOES_NOT_REQUIRE = 'does not require';
/** /**
* TODO should be marked private once 5.3 is dropped * TODO should be marked private once 5.3 is dropped
* @private * @private
*/ */
const TYPE_UNKNOWN = 'relates to'; private const TYPE_UNKNOWN = 'relates to';
/** /**
* Will be converted into a constant once the min PHP version allows this * Will be converted into a constant once the min PHP version allows this

View File

@ -120,7 +120,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isDev() public function isDev(): bool
{ {
return $this->dev; return $this->dev;
} }
@ -130,7 +130,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setType(string $type) public function setType(string $type): void
{ {
$this->type = $type; $this->type = $type;
} }
@ -138,7 +138,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getType() public function getType(): string
{ {
return $this->type ?: 'library'; return $this->type ?: 'library';
} }
@ -146,7 +146,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getStability() public function getStability(): string
{ {
return $this->stability; return $this->stability;
} }
@ -154,7 +154,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setTargetDir(?string $targetDir) public function setTargetDir(?string $targetDir): void
{ {
$this->targetDir = $targetDir; $this->targetDir = $targetDir;
} }
@ -162,7 +162,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTargetDir() public function getTargetDir(): ?string
{ {
if (null === $this->targetDir) { if (null === $this->targetDir) {
return null; return null;
@ -176,7 +176,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setExtra(array $extra) public function setExtra(array $extra): void
{ {
$this->extra = $extra; $this->extra = $extra;
} }
@ -184,7 +184,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getExtra() public function getExtra(): array
{ {
return $this->extra; return $this->extra;
} }
@ -194,7 +194,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setBinaries(array $binaries) public function setBinaries(array $binaries): void
{ {
$this->binaries = $binaries; $this->binaries = $binaries;
} }
@ -202,7 +202,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBinaries() public function getBinaries(): array
{ {
return $this->binaries; return $this->binaries;
} }
@ -212,7 +212,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setInstallationSource(?string $type) public function setInstallationSource(?string $type): void
{ {
$this->installationSource = $type; $this->installationSource = $type;
} }
@ -220,7 +220,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getInstallationSource() public function getInstallationSource(): ?string
{ {
return $this->installationSource; return $this->installationSource;
} }
@ -228,7 +228,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setSourceType(?string $type) public function setSourceType(?string $type): void
{ {
$this->sourceType = $type; $this->sourceType = $type;
} }
@ -236,7 +236,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSourceType() public function getSourceType(): ?string
{ {
return $this->sourceType; return $this->sourceType;
} }
@ -244,7 +244,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setSourceUrl(?string $url) public function setSourceUrl(?string $url): void
{ {
$this->sourceUrl = $url; $this->sourceUrl = $url;
} }
@ -252,7 +252,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSourceUrl() public function getSourceUrl(): ?string
{ {
return $this->sourceUrl; return $this->sourceUrl;
} }
@ -260,7 +260,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setSourceReference(?string $reference) public function setSourceReference(?string $reference): void
{ {
$this->sourceReference = $reference; $this->sourceReference = $reference;
} }
@ -268,7 +268,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSourceReference() public function getSourceReference(): ?string
{ {
return $this->sourceReference; return $this->sourceReference;
} }
@ -276,7 +276,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setSourceMirrors(?array $mirrors) public function setSourceMirrors(?array $mirrors): void
{ {
$this->sourceMirrors = $mirrors; $this->sourceMirrors = $mirrors;
} }
@ -284,7 +284,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSourceMirrors() public function getSourceMirrors(): ?array
{ {
return $this->sourceMirrors; return $this->sourceMirrors;
} }
@ -292,7 +292,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSourceUrls() public function getSourceUrls(): array
{ {
return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType, 'source'); return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType, 'source');
} }
@ -302,7 +302,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setDistType(?string $type) public function setDistType(?string $type): void
{ {
$this->distType = $type; $this->distType = $type;
} }
@ -310,7 +310,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistType() public function getDistType(): ?string
{ {
return $this->distType; return $this->distType;
} }
@ -320,7 +320,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setDistUrl(?string $url) public function setDistUrl(?string $url): void
{ {
$this->distUrl = $url; $this->distUrl = $url;
} }
@ -328,7 +328,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistUrl() public function getDistUrl(): ?string
{ {
return $this->distUrl; return $this->distUrl;
} }
@ -338,7 +338,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setDistReference(?string $reference) public function setDistReference(?string $reference): void
{ {
$this->distReference = $reference; $this->distReference = $reference;
} }
@ -346,7 +346,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistReference() public function getDistReference(): ?string
{ {
return $this->distReference; return $this->distReference;
} }
@ -356,7 +356,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setDistSha1Checksum(?string $sha1checksum) public function setDistSha1Checksum(?string $sha1checksum): void
{ {
$this->distSha1Checksum = $sha1checksum; $this->distSha1Checksum = $sha1checksum;
} }
@ -364,7 +364,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistSha1Checksum() public function getDistSha1Checksum(): ?string
{ {
return $this->distSha1Checksum; return $this->distSha1Checksum;
} }
@ -372,7 +372,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setDistMirrors(?array $mirrors) public function setDistMirrors(?array $mirrors): void
{ {
$this->distMirrors = $mirrors; $this->distMirrors = $mirrors;
} }
@ -380,7 +380,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistMirrors() public function getDistMirrors(): ?array
{ {
return $this->distMirrors; return $this->distMirrors;
} }
@ -388,7 +388,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDistUrls() public function getDistUrls(): array
{ {
return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType, 'dist'); return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType, 'dist');
} }
@ -396,7 +396,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTransportOptions() public function getTransportOptions(): array
{ {
return $this->transportOptions; return $this->transportOptions;
} }
@ -404,7 +404,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setTransportOptions(array $options) public function setTransportOptions(array $options): void
{ {
$this->transportOptions = $options; $this->transportOptions = $options;
} }
@ -412,7 +412,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getVersion() public function getVersion(): string
{ {
return $this->version; return $this->version;
} }
@ -420,7 +420,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getPrettyVersion() public function getPrettyVersion(): string
{ {
return $this->prettyVersion; return $this->prettyVersion;
} }
@ -428,7 +428,7 @@ class Package extends BasePackage
/** /**
* @return void * @return void
*/ */
public function setReleaseDate(?\DateTimeInterface $releaseDate) public function setReleaseDate(?\DateTimeInterface $releaseDate): void
{ {
$this->releaseDate = $releaseDate; $this->releaseDate = $releaseDate;
} }
@ -436,7 +436,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getReleaseDate() public function getReleaseDate(): ?\DateTimeInterface
{ {
return $this->releaseDate; return $this->releaseDate;
} }
@ -448,7 +448,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setRequires(array $requires) public function setRequires(array $requires): void
{ {
if (isset($requires[0])) { // @phpstan-ignore-line if (isset($requires[0])) { // @phpstan-ignore-line
$requires = $this->convertLinksToMap($requires, 'setRequires'); $requires = $this->convertLinksToMap($requires, 'setRequires');
@ -460,7 +460,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRequires() public function getRequires(): array
{ {
return $this->requires; return $this->requires;
} }
@ -472,7 +472,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setConflicts(array $conflicts) public function setConflicts(array $conflicts): void
{ {
if (isset($conflicts[0])) { // @phpstan-ignore-line if (isset($conflicts[0])) { // @phpstan-ignore-line
$conflicts = $this->convertLinksToMap($conflicts, 'setConflicts'); $conflicts = $this->convertLinksToMap($conflicts, 'setConflicts');
@ -485,7 +485,7 @@ class Package extends BasePackage
* @inheritDoc * @inheritDoc
* @return array<string, Link> * @return array<string, Link>
*/ */
public function getConflicts() public function getConflicts(): array
{ {
return $this->conflicts; return $this->conflicts;
} }
@ -497,7 +497,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setProvides(array $provides) public function setProvides(array $provides): void
{ {
if (isset($provides[0])) { // @phpstan-ignore-line if (isset($provides[0])) { // @phpstan-ignore-line
$provides = $this->convertLinksToMap($provides, 'setProvides'); $provides = $this->convertLinksToMap($provides, 'setProvides');
@ -510,7 +510,7 @@ class Package extends BasePackage
* @inheritDoc * @inheritDoc
* @return array<string, Link> * @return array<string, Link>
*/ */
public function getProvides() public function getProvides(): array
{ {
return $this->provides; return $this->provides;
} }
@ -522,7 +522,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setReplaces(array $replaces) public function setReplaces(array $replaces): void
{ {
if (isset($replaces[0])) { // @phpstan-ignore-line if (isset($replaces[0])) { // @phpstan-ignore-line
$replaces = $this->convertLinksToMap($replaces, 'setReplaces'); $replaces = $this->convertLinksToMap($replaces, 'setReplaces');
@ -535,7 +535,7 @@ class Package extends BasePackage
* @inheritDoc * @inheritDoc
* @return array<string, Link> * @return array<string, Link>
*/ */
public function getReplaces() public function getReplaces(): array
{ {
return $this->replaces; return $this->replaces;
} }
@ -547,7 +547,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setDevRequires(array $devRequires) public function setDevRequires(array $devRequires): void
{ {
if (isset($devRequires[0])) { // @phpstan-ignore-line if (isset($devRequires[0])) { // @phpstan-ignore-line
$devRequires = $this->convertLinksToMap($devRequires, 'setDevRequires'); $devRequires = $this->convertLinksToMap($devRequires, 'setDevRequires');
@ -559,7 +559,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDevRequires() public function getDevRequires(): array
{ {
return $this->devRequires; return $this->devRequires;
} }
@ -571,7 +571,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setSuggests(array $suggests) public function setSuggests(array $suggests): void
{ {
$this->suggests = $suggests; $this->suggests = $suggests;
} }
@ -579,7 +579,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSuggests() public function getSuggests(): array
{ {
return $this->suggests; return $this->suggests;
} }
@ -593,7 +593,7 @@ class Package extends BasePackage
* *
* @phpstan-param AutoloadRules $autoload * @phpstan-param AutoloadRules $autoload
*/ */
public function setAutoload(array $autoload) public function setAutoload(array $autoload): void
{ {
$this->autoload = $autoload; $this->autoload = $autoload;
} }
@ -601,7 +601,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getAutoload() public function getAutoload(): array
{ {
return $this->autoload; return $this->autoload;
} }
@ -615,7 +615,7 @@ class Package extends BasePackage
* *
* @phpstan-param DevAutoloadRules $devAutoload * @phpstan-param DevAutoloadRules $devAutoload
*/ */
public function setDevAutoload(array $devAutoload) public function setDevAutoload(array $devAutoload): void
{ {
$this->devAutoload = $devAutoload; $this->devAutoload = $devAutoload;
} }
@ -623,7 +623,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDevAutoload() public function getDevAutoload(): array
{ {
return $this->devAutoload; return $this->devAutoload;
} }
@ -635,7 +635,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setIncludePaths(array $includePaths) public function setIncludePaths(array $includePaths): void
{ {
$this->includePaths = $includePaths; $this->includePaths = $includePaths;
} }
@ -643,7 +643,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getIncludePaths() public function getIncludePaths(): array
{ {
return $this->includePaths; return $this->includePaths;
} }
@ -655,7 +655,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setNotificationUrl(string $notificationUrl) public function setNotificationUrl(string $notificationUrl): void
{ {
$this->notificationUrl = $notificationUrl; $this->notificationUrl = $notificationUrl;
} }
@ -663,7 +663,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getNotificationUrl() public function getNotificationUrl(): ?string
{ {
return $this->notificationUrl; return $this->notificationUrl;
} }
@ -673,7 +673,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function setIsDefaultBranch(bool $defaultBranch) public function setIsDefaultBranch(bool $defaultBranch): void
{ {
$this->isDefaultBranch = $defaultBranch; $this->isDefaultBranch = $defaultBranch;
} }
@ -681,7 +681,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isDefaultBranch() public function isDefaultBranch(): bool
{ {
return $this->isDefaultBranch; return $this->isDefaultBranch;
} }
@ -689,7 +689,7 @@ class Package extends BasePackage
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function setSourceDistReferences(string $reference) public function setSourceDistReferences(string $reference): void
{ {
$this->setSourceReference($reference); $this->setSourceReference($reference);
@ -715,7 +715,7 @@ class Package extends BasePackage
* *
* @return void * @return void
*/ */
public function replaceVersion(string $version, string $prettyVersion) public function replaceVersion(string $version, string $prettyVersion): void
{ {
$this->version = $version; $this->version = $version;
$this->prettyVersion = $prettyVersion; $this->prettyVersion = $prettyVersion;
@ -735,7 +735,7 @@ class Package extends BasePackage
* *
* @phpstan-param list<array{url: string, preferred: bool}>|null $mirrors * @phpstan-param list<array{url: string, preferred: bool}>|null $mirrors
*/ */
protected function getUrls(?string $url, ?array $mirrors, ?string $ref, ?string $type, string $urlType) protected function getUrls(?string $url, ?array $mirrors, ?string $ref, ?string $type, string $urlType): array
{ {
if (!$url) { if (!$url) {
return array(); return array();

View File

@ -17,6 +17,8 @@ use Composer\Repository\RepositoryInterface;
/** /**
* Defines the essential information a package has that is used during solving/installation * Defines the essential information a package has that is used during solving/installation
* *
* PackageInterface & derivatives are considered internal, you may use them in type hints but extending/implementing them is not recommended and not supported. Things may change without notice.
*
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* *
* @phpstan-type AutoloadRules array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>, exclude-from-classmap?: list<string>} * @phpstan-type AutoloadRules array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>, exclude-from-classmap?: list<string>}
@ -33,14 +35,14 @@ interface PackageInterface
* *
* @return string package name * @return string package name
*/ */
public function getName(); public function getName(): string;
/** /**
* Returns the package's pretty (i.e. with proper case) name * Returns the package's pretty (i.e. with proper case) name
* *
* @return string package name * @return string package name
*/ */
public function getPrettyName(); public function getPrettyName(): string;
/** /**
* Returns a set of names that could refer to this package * Returns a set of names that could refer to this package
@ -52,7 +54,7 @@ interface PackageInterface
* *
* @return string[] An array of strings referring to this package * @return string[] An array of strings referring to this package
*/ */
public function getNames(bool $provides = true); public function getNames(bool $provides = true): array;
/** /**
* Allows the solver to set an id for this package to refer to it. * Allows the solver to set an id for this package to refer to it.
@ -61,42 +63,42 @@ interface PackageInterface
* *
* @return void * @return void
*/ */
public function setId(int $id); public function setId(int $id): void;
/** /**
* Retrieves the package's id set through setId * Retrieves the package's id set through setId
* *
* @return int The previously set package id * @return int The previously set package id
*/ */
public function getId(); public function getId(): int;
/** /**
* Returns whether the package is a development virtual package or a concrete one * Returns whether the package is a development virtual package or a concrete one
* *
* @return bool * @return bool
*/ */
public function isDev(); public function isDev(): bool;
/** /**
* Returns the package type, e.g. library * Returns the package type, e.g. library
* *
* @return string The package type * @return string The package type
*/ */
public function getType(); public function getType(): string;
/** /**
* Returns the package targetDir property * Returns the package targetDir property
* *
* @return ?string The package targetDir * @return ?string The package targetDir
*/ */
public function getTargetDir(); public function getTargetDir(): ?string;
/** /**
* Returns the package extra data * Returns the package extra data
* *
* @return mixed[] The package extra data * @return mixed[] The package extra data
*/ */
public function getExtra(); public function getExtra(): array;
/** /**
* Sets source from which this package was installed (source/dist). * Sets source from which this package was installed (source/dist).
@ -106,7 +108,7 @@ interface PackageInterface
* *
* @return void * @return void
*/ */
public function setInstallationSource(?string $type); public function setInstallationSource(?string $type): void;
/** /**
* Returns source from which this package was installed (source/dist). * Returns source from which this package was installed (source/dist).
@ -114,110 +116,110 @@ interface PackageInterface
* @return ?string source/dist * @return ?string source/dist
* @phpstan-return 'source'|'dist'|null * @phpstan-return 'source'|'dist'|null
*/ */
public function getInstallationSource(); public function getInstallationSource(): ?string;
/** /**
* Returns the repository type of this package, e.g. git, svn * Returns the repository type of this package, e.g. git, svn
* *
* @return ?string The repository type * @return ?string The repository type
*/ */
public function getSourceType(); public function getSourceType(): ?string;
/** /**
* Returns the repository url of this package, e.g. git://github.com/naderman/composer.git * Returns the repository url of this package, e.g. git://github.com/naderman/composer.git
* *
* @return ?string The repository url * @return ?string The repository url
*/ */
public function getSourceUrl(); public function getSourceUrl(): ?string;
/** /**
* Returns the repository urls of this package including mirrors, e.g. git://github.com/naderman/composer.git * Returns the repository urls of this package including mirrors, e.g. git://github.com/naderman/composer.git
* *
* @return string[] * @return string[]
*/ */
public function getSourceUrls(); public function getSourceUrls(): array;
/** /**
* Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git * Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git
* *
* @return ?string The repository reference * @return ?string The repository reference
*/ */
public function getSourceReference(); public function getSourceReference(): ?string;
/** /**
* Returns the source mirrors of this package * Returns the source mirrors of this package
* *
* @return ?array<int, array{url: string, preferred: bool}> * @return ?array<int, array{url: string, preferred: bool}>
*/ */
public function getSourceMirrors(); public function getSourceMirrors(): ?array;
/** /**
* @param null|array<int, array{url: string, preferred: bool}> $mirrors * @param null|array<int, array{url: string, preferred: bool}> $mirrors
* @return void * @return void
*/ */
public function setSourceMirrors(?array $mirrors); public function setSourceMirrors(?array $mirrors): void;
/** /**
* Returns the type of the distribution archive of this version, e.g. zip, tarball * Returns the type of the distribution archive of this version, e.g. zip, tarball
* *
* @return ?string The repository type * @return ?string The repository type
*/ */
public function getDistType(); public function getDistType(): ?string;
/** /**
* Returns the url of the distribution archive of this version * Returns the url of the distribution archive of this version
* *
* @return ?string * @return ?string
*/ */
public function getDistUrl(); public function getDistUrl(): ?string;
/** /**
* Returns the urls of the distribution archive of this version, including mirrors * Returns the urls of the distribution archive of this version, including mirrors
* *
* @return string[] * @return string[]
*/ */
public function getDistUrls(); public function getDistUrls(): array;
/** /**
* Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git * Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git
* *
* @return ?string * @return ?string
*/ */
public function getDistReference(); public function getDistReference(): ?string;
/** /**
* Returns the sha1 checksum for the distribution archive of this version * Returns the sha1 checksum for the distribution archive of this version
* *
* @return ?string * @return ?string
*/ */
public function getDistSha1Checksum(); public function getDistSha1Checksum(): ?string;
/** /**
* Returns the dist mirrors of this package * Returns the dist mirrors of this package
* *
* @return ?array<int, array{url: string, preferred: bool}> * @return ?array<int, array{url: string, preferred: bool}>
*/ */
public function getDistMirrors(); public function getDistMirrors(): ?array;
/** /**
* @param null|array<int, array{url: string, preferred: bool}> $mirrors * @param null|array<int, array{url: string, preferred: bool}> $mirrors
* @return void * @return void
*/ */
public function setDistMirrors(?array $mirrors); public function setDistMirrors(?array $mirrors): void;
/** /**
* Returns the version of this package * Returns the version of this package
* *
* @return string version * @return string version
*/ */
public function getVersion(); public function getVersion(): string;
/** /**
* Returns the pretty (i.e. non-normalized) version string of this package * Returns the pretty (i.e. non-normalized) version string of this package
* *
* @return string version * @return string version
*/ */
public function getPrettyVersion(); public function getPrettyVersion(): string;
/** /**
* Returns the pretty version string plus a git or hg commit hash of this package * Returns the pretty version string plus a git or hg commit hash of this package
@ -230,14 +232,14 @@ interface PackageInterface
* *
* @phpstan-param self::DISPLAY_SOURCE_REF_IF_DEV|self::DISPLAY_SOURCE_REF|self::DISPLAY_DIST_REF $displayMode * @phpstan-param self::DISPLAY_SOURCE_REF_IF_DEV|self::DISPLAY_SOURCE_REF|self::DISPLAY_DIST_REF $displayMode
*/ */
public function getFullPrettyVersion(bool $truncate = true, int $displayMode = self::DISPLAY_SOURCE_REF_IF_DEV); public function getFullPrettyVersion(bool $truncate = true, int $displayMode = self::DISPLAY_SOURCE_REF_IF_DEV): string;
/** /**
* Returns the release date of the package * Returns the release date of the package
* *
* @return ?\DateTimeInterface * @return ?\DateTimeInterface
*/ */
public function getReleaseDate(); public function getReleaseDate(): ?\DateTimeInterface;
/** /**
* Returns the stability of this package: one of (dev, alpha, beta, RC, stable) * Returns the stability of this package: one of (dev, alpha, beta, RC, stable)
@ -246,7 +248,7 @@ interface PackageInterface
* *
* @phpstan-return 'stable'|'RC'|'beta'|'alpha'|'dev' * @phpstan-return 'stable'|'RC'|'beta'|'alpha'|'dev'
*/ */
public function getStability(); public function getStability(): string;
/** /**
* Returns a set of links to packages which need to be installed before * Returns a set of links to packages which need to be installed before
@ -254,7 +256,7 @@ interface PackageInterface
* *
* @return array<string, Link> A map of package links defining required packages, indexed by the require package's name * @return array<string, Link> A map of package links defining required packages, indexed by the require package's name
*/ */
public function getRequires(); public function getRequires(): array;
/** /**
* Returns a set of links to packages which must not be installed at the * Returns a set of links to packages which must not be installed at the
@ -262,7 +264,7 @@ interface PackageInterface
* *
* @return Link[] An array of package links defining conflicting packages * @return Link[] An array of package links defining conflicting packages
*/ */
public function getConflicts(); public function getConflicts(): array;
/** /**
* Returns a set of links to virtual packages that are provided through * Returns a set of links to virtual packages that are provided through
@ -270,7 +272,7 @@ interface PackageInterface
* *
* @return Link[] An array of package links defining provided packages * @return Link[] An array of package links defining provided packages
*/ */
public function getProvides(); public function getProvides(): array;
/** /**
* Returns a set of links to packages which can alternatively be * Returns a set of links to packages which can alternatively be
@ -278,7 +280,7 @@ interface PackageInterface
* *
* @return Link[] An array of package links defining replaced packages * @return Link[] An array of package links defining replaced packages
*/ */
public function getReplaces(); public function getReplaces(): array;
/** /**
* Returns a set of links to packages which are required to develop * Returns a set of links to packages which are required to develop
@ -286,7 +288,7 @@ interface PackageInterface
* *
* @return array<string, Link> A map of package links defining packages required for development, indexed by the require package's name * @return array<string, Link> A map of package links defining packages required for development, indexed by the require package's name
*/ */
public function getDevRequires(); public function getDevRequires(): array;
/** /**
* Returns a set of package names and reasons why they are useful in * Returns a set of package names and reasons why they are useful in
@ -295,7 +297,7 @@ interface PackageInterface
* @return array An array of package suggestions with descriptions * @return array An array of package suggestions with descriptions
* @phpstan-return array<string, string> * @phpstan-return array<string, string>
*/ */
public function getSuggests(); public function getSuggests(): array;
/** /**
* Returns an associative array of autoloading rules * Returns an associative array of autoloading rules
@ -308,7 +310,7 @@ interface PackageInterface
* @return array Mapping of autoloading rules * @return array Mapping of autoloading rules
* @phpstan-return AutoloadRules * @phpstan-return AutoloadRules
*/ */
public function getAutoload(); public function getAutoload(): array;
/** /**
* Returns an associative array of dev autoloading rules * Returns an associative array of dev autoloading rules
@ -321,7 +323,7 @@ interface PackageInterface
* @return array Mapping of dev autoloading rules * @return array Mapping of dev autoloading rules
* @phpstan-return DevAutoloadRules * @phpstan-return DevAutoloadRules
*/ */
public function getDevAutoload(); public function getDevAutoload(): array;
/** /**
* Returns a list of directories which should get added to PHP's * Returns a list of directories which should get added to PHP's
@ -329,7 +331,7 @@ interface PackageInterface
* *
* @return string[] * @return string[]
*/ */
public function getIncludePaths(); public function getIncludePaths(): array;
/** /**
* Stores a reference to the repository that owns the package * Stores a reference to the repository that owns the package
@ -338,61 +340,61 @@ interface PackageInterface
* *
* @return void * @return void
*/ */
public function setRepository(RepositoryInterface $repository); public function setRepository(RepositoryInterface $repository): void;
/** /**
* Returns a reference to the repository that owns the package * Returns a reference to the repository that owns the package
* *
* @return ?RepositoryInterface * @return ?RepositoryInterface
*/ */
public function getRepository(); public function getRepository(): ?RepositoryInterface;
/** /**
* Returns the package binaries * Returns the package binaries
* *
* @return string[] * @return string[]
*/ */
public function getBinaries(); public function getBinaries(): array;
/** /**
* Returns package unique name, constructed from name and version. * Returns package unique name, constructed from name and version.
* *
* @return string * @return string
*/ */
public function getUniqueName(); public function getUniqueName(): string;
/** /**
* Returns the package notification url * Returns the package notification url
* *
* @return ?string * @return ?string
*/ */
public function getNotificationUrl(); public function getNotificationUrl(): ?string;
/** /**
* Converts the package into a readable and unique string * Converts the package into a readable and unique string
* *
* @return string * @return string
*/ */
public function __toString(); public function __toString(): string;
/** /**
* Converts the package into a pretty readable string * Converts the package into a pretty readable string
* *
* @return string * @return string
*/ */
public function getPrettyString(); public function getPrettyString(): string;
/** /**
* @return bool * @return bool
*/ */
public function isDefaultBranch(); public function isDefaultBranch(): bool;
/** /**
* Returns a list of options to download package dist files * Returns a list of options to download package dist files
* *
* @return mixed[] * @return mixed[]
*/ */
public function getTransportOptions(); public function getTransportOptions(): array;
/** /**
* Configures the list of options to download package dist files * Configures the list of options to download package dist files
@ -401,32 +403,32 @@ interface PackageInterface
* *
* @return void * @return void
*/ */
public function setTransportOptions(array $options); public function setTransportOptions(array $options): void;
/** /**
* @return void * @return void
*/ */
public function setSourceReference(?string $reference); public function setSourceReference(?string $reference): void;
/** /**
* @return void * @return void
*/ */
public function setDistUrl(?string $url); public function setDistUrl(?string $url): void;
/** /**
* @return void * @return void
*/ */
public function setDistType(?string $type); public function setDistType(?string $type): void;
/** /**
* @return void * @return void
*/ */
public function setDistReference(?string $reference); public function setDistReference(?string $reference): void;
/** /**
* Set dist and source references and update dist URL for ones that contain a reference * Set dist and source references and update dist URL for ones that contain a reference
* *
* @return void * @return void
*/ */
public function setSourceDistReferences(string $reference); public function setSourceDistReferences(string $reference): void;
} }

View File

@ -15,6 +15,8 @@ namespace Composer\Package;
/** /**
* Defines additional fields that are only needed for the root package * Defines additional fields that are only needed for the root package
* *
* PackageInterface & derivatives are considered internal, you may use them in type hints but extending/implementing them is not recommended and not supported. Things may change without notice.
*
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* *
* @phpstan-import-type AutoloadRules from PackageInterface * @phpstan-import-type AutoloadRules from PackageInterface
@ -27,14 +29,14 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return array<array{package: string, version: string, alias: string, alias_normalized: string}> * @return array<array{package: string, version: string, alias: string, alias_normalized: string}>
*/ */
public function getAliases(); public function getAliases(): array;
/** /**
* Returns the minimum stability of the package * Returns the minimum stability of the package
* *
* @return string * @return string
*/ */
public function getMinimumStability(); public function getMinimumStability(): string;
/** /**
* Returns the stability flags to apply to dependencies * Returns the stability flags to apply to dependencies
@ -43,7 +45,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return array<string, BasePackage::STABILITY_*> * @return array<string, BasePackage::STABILITY_*>
*/ */
public function getStabilityFlags(); public function getStabilityFlags(): array;
/** /**
* Returns a set of package names and source references that must be enforced on them * Returns a set of package names and source references that must be enforced on them
@ -52,21 +54,21 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return array<string, string> * @return array<string, string>
*/ */
public function getReferences(); public function getReferences(): array;
/** /**
* Returns true if the root package prefers picking stable packages over unstable ones * Returns true if the root package prefers picking stable packages over unstable ones
* *
* @return bool * @return bool
*/ */
public function getPreferStable(); public function getPreferStable(): bool;
/** /**
* Returns the root package's configuration * Returns the root package's configuration
* *
* @return mixed[] * @return mixed[]
*/ */
public function getConfig(); public function getConfig(): array;
/** /**
* Set the required packages * Set the required packages
@ -75,7 +77,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setRequires(array $requires); public function setRequires(array $requires): void;
/** /**
* Set the recommended packages * Set the recommended packages
@ -84,7 +86,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setDevRequires(array $devRequires); public function setDevRequires(array $devRequires): void;
/** /**
* Set the conflicting packages * Set the conflicting packages
@ -93,7 +95,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setConflicts(array $conflicts); public function setConflicts(array $conflicts): void;
/** /**
* Set the provided virtual packages * Set the provided virtual packages
@ -102,7 +104,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setProvides(array $provides); public function setProvides(array $provides): void;
/** /**
* Set the packages this one replaces * Set the packages this one replaces
@ -111,7 +113,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setReplaces(array $replaces); public function setReplaces(array $replaces): void;
/** /**
* Set the repositories * Set the repositories
@ -120,7 +122,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setRepositories(array $repositories); public function setRepositories(array $repositories): void;
/** /**
* Set the autoload mapping * Set the autoload mapping
@ -130,7 +132,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setAutoload(array $autoload); public function setAutoload(array $autoload): void;
/** /**
* Set the dev autoload mapping * Set the dev autoload mapping
@ -140,7 +142,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setDevAutoload(array $devAutoload); public function setDevAutoload(array $devAutoload): void;
/** /**
* Set the stabilityFlags * Set the stabilityFlags
@ -149,7 +151,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setStabilityFlags(array $stabilityFlags); public function setStabilityFlags(array $stabilityFlags): void;
/** /**
* Set the minimumStability * Set the minimumStability
@ -158,7 +160,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setMinimumStability(string $minimumStability); public function setMinimumStability(string $minimumStability): void;
/** /**
* Set the preferStable * Set the preferStable
@ -167,7 +169,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setPreferStable(bool $preferStable); public function setPreferStable(bool $preferStable): void;
/** /**
* Set the config * Set the config
@ -176,7 +178,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setConfig(array $config); public function setConfig(array $config): void;
/** /**
* Set the references * Set the references
@ -185,7 +187,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setReferences(array $references); public function setReferences(array $references): void;
/** /**
* Set the aliases * Set the aliases
@ -194,7 +196,7 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setAliases(array $aliases); public function setAliases(array $aliases): void;
/** /**
* Set the suggested packages * Set the suggested packages
@ -203,12 +205,12 @@ interface RootPackageInterface extends CompletePackageInterface
* *
* @return void * @return void
*/ */
public function setSuggests(array $suggests); public function setSuggests(array $suggests): void;
/** /**
* @param mixed[] $extra * @param mixed[] $extra
* *
* @return void * @return void
*/ */
public function setExtra(array $extra); public function setExtra(array $extra): void;
} }

View File

@ -28,7 +28,7 @@ class VersionParser extends SemverVersionParser
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function parseConstraints($constraints) public function parseConstraints($constraints): ConstraintInterface
{ {
if (!isset(self::$constraints[$constraints])) { if (!isset(self::$constraints[$constraints])) {
self::$constraints[$constraints] = parent::parseConstraints($constraints); self::$constraints[$constraints] = parent::parseConstraints($constraints);
@ -47,7 +47,7 @@ class VersionParser extends SemverVersionParser
* *
* @return list<array{name: string, version?: string}> * @return list<array{name: string, version?: string}>
*/ */
public function parseNameVersionPairs(array $pairs) public function parseNameVersionPairs(array $pairs): array
{ {
$pairs = array_values($pairs); $pairs = array_values($pairs);
$result = array(); $result = array();
@ -76,7 +76,7 @@ class VersionParser extends SemverVersionParser
* *
* @return bool * @return bool
*/ */
public static function isUpgrade(string $normalizedFrom, string $normalizedTo) public static function isUpgrade(string $normalizedFrom, string $normalizedTo): bool
{ {
if ($normalizedFrom === $normalizedTo) { if ($normalizedFrom === $normalizedTo) {
return true; return true;

View File

@ -62,7 +62,7 @@ class RepositoryManager
* *
* @return PackageInterface|null * @return PackageInterface|null
*/ */
public function findPackage(string $name, $constraint) public function findPackage(string $name, $constraint): ?PackageInterface
{ {
foreach ($this->repositories as $repository) { foreach ($this->repositories as $repository) {
/** @var RepositoryInterface $repository */ /** @var RepositoryInterface $repository */
@ -82,7 +82,7 @@ class RepositoryManager
* *
* @return PackageInterface[] * @return PackageInterface[]
*/ */
public function findPackages(string $name, $constraint) public function findPackages(string $name, $constraint): array
{ {
$packages = array(); $packages = array();
@ -100,7 +100,7 @@ class RepositoryManager
* *
* @return void * @return void
*/ */
public function addRepository(RepositoryInterface $repository) public function addRepository(RepositoryInterface $repository): void
{ {
$this->repositories[] = $repository; $this->repositories[] = $repository;
} }
@ -114,7 +114,7 @@ class RepositoryManager
* *
* @return void * @return void
*/ */
public function prependRepository(RepositoryInterface $repository) public function prependRepository(RepositoryInterface $repository): void
{ {
array_unshift($this->repositories, $repository); array_unshift($this->repositories, $repository);
} }
@ -128,7 +128,7 @@ class RepositoryManager
* @throws \InvalidArgumentException if repository for provided type is not registered * @throws \InvalidArgumentException if repository for provided type is not registered
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public function createRepository(string $type, array $config, string $name = null) public function createRepository(string $type, array $config, string $name = null): RepositoryInterface
{ {
if (!isset($this->repositoryClasses[$type])) { if (!isset($this->repositoryClasses[$type])) {
throw new \InvalidArgumentException('Repository type is not registered: '.$type); throw new \InvalidArgumentException('Repository type is not registered: '.$type);
@ -162,7 +162,7 @@ class RepositoryManager
* *
* @return void * @return void
*/ */
public function setRepositoryClass(string $type, $class) public function setRepositoryClass(string $type, $class): void
{ {
$this->repositoryClasses[$type] = $class; $this->repositoryClasses[$type] = $class;
} }
@ -172,7 +172,7 @@ class RepositoryManager
* *
* @return RepositoryInterface[] * @return RepositoryInterface[]
*/ */
public function getRepositories() public function getRepositories(): array
{ {
return $this->repositories; return $this->repositories;
} }
@ -184,7 +184,7 @@ class RepositoryManager
* *
* @return void * @return void
*/ */
public function setLocalRepository(InstalledRepositoryInterface $repository) public function setLocalRepository(InstalledRepositoryInterface $repository): void
{ {
$this->localRepository = $repository; $this->localRepository = $repository;
} }
@ -194,7 +194,7 @@ class RepositoryManager
* *
* @return InstalledRepositoryInterface * @return InstalledRepositoryInterface
*/ */
public function getLocalRepository() public function getLocalRepository(): InstalledRepositoryInterface
{ {
return $this->localRepository; return $this->localRepository;
} }

View File

@ -172,12 +172,12 @@ class FossilDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier): ?\DateTime public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
$this->process->execute('fossil finfo -b -n 1 composer.json', $output, $this->checkoutDir); $this->process->execute('fossil finfo -b -n 1 composer.json', $output, $this->checkoutDir);
list(, $date) = explode(' ', trim($output), 3); list(, $date) = explode(' ', trim($output), 3);
return new \DateTime($date, new \DateTimeZone('UTC')); return new \DateTimeImmutable($date, new \DateTimeZone('UTC'));
} }
/** /**

View File

@ -59,7 +59,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
if (!Preg::isMatch('#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i', $this->url, $match)) { if (!Preg::isMatch('#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i', $this->url, $match)) {
throw new \InvalidArgumentException(sprintf('The Bitbucket repository URL %s is invalid. It must be the HTTPS URL of a Bitbucket repository.', $this->url)); throw new \InvalidArgumentException(sprintf('The Bitbucket repository URL %s is invalid. It must be the HTTPS URL of a Bitbucket repository.', $this->url));
@ -83,7 +83,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getUrl(); return $this->fallbackDriver->getUrl();
@ -99,7 +99,7 @@ class GitBitbucketDriver extends VcsDriver
* @return bool * @return bool
* @phpstan-impure * @phpstan-impure
*/ */
protected function getRepoData() protected function getRepoData(): bool
{ {
$resource = sprintf( $resource = sprintf(
'https://api.bitbucket.org/2.0/repositories/%s/%s?%s', 'https://api.bitbucket.org/2.0/repositories/%s/%s?%s',
@ -131,7 +131,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getComposerInformation(string $identifier) public function getComposerInformation(string $identifier): ?array
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getComposerInformation($identifier); return $this->fallbackDriver->getComposerInformation($identifier);
@ -148,7 +148,7 @@ class GitBitbucketDriver extends VcsDriver
} }
} }
if ($composer) { if ($composer !== null) {
// specials for bitbucket // specials for bitbucket
if (!isset($composer['support']['source'])) { if (!isset($composer['support']['source'])) {
$label = array_search( $label = array_search(
@ -205,7 +205,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getFileContent($file, $identifier); return $this->fallbackDriver->getFileContent($file, $identifier);
@ -232,7 +232,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getChangeDate($identifier); return $this->fallbackDriver->getChangeDate($identifier);
@ -253,13 +253,13 @@ class GitBitbucketDriver extends VcsDriver
); );
$commit = $this->fetchWithOAuthCredentials($resource)->decodeJson(); $commit = $this->fetchWithOAuthCredentials($resource)->decodeJson();
return new \DateTime($commit['date']); return new \DateTimeImmutable($commit['date']);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getSource($identifier); return $this->fallbackDriver->getSource($identifier);
@ -271,7 +271,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getDist($identifier); return $this->fallbackDriver->getDist($identifier);
@ -290,7 +290,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getTags(); return $this->fallbackDriver->getTags();
@ -333,7 +333,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getBranches(); return $this->fallbackDriver->getBranches();
@ -383,7 +383,7 @@ class GitBitbucketDriver extends VcsDriver
* *
* @phpstan-impure * @phpstan-impure
*/ */
protected function fetchWithOAuthCredentials(string $url, bool $fetchingRepoData = false) protected function fetchWithOAuthCredentials(string $url, bool $fetchingRepoData = false): Response
{ {
try { try {
return parent::getContents($url); return parent::getContents($url);
@ -413,7 +413,7 @@ class GitBitbucketDriver extends VcsDriver
* *
* @return string * @return string
*/ */
protected function generateSshUrl() protected function generateSshUrl(): string
{ {
return 'git@' . $this->originUrl . ':' . $this->owner.'/'.$this->repository.'.git'; return 'git@' . $this->originUrl . ':' . $this->owner.'/'.$this->repository.'.git';
} }
@ -424,7 +424,7 @@ class GitBitbucketDriver extends VcsDriver
* @return true * @return true
* @throws \RuntimeException * @throws \RuntimeException
*/ */
protected function attemptCloneFallback() protected function attemptCloneFallback(): bool
{ {
try { try {
$this->setupFallbackDriver($this->generateSshUrl()); $this->setupFallbackDriver($this->generateSshUrl());
@ -445,7 +445,7 @@ class GitBitbucketDriver extends VcsDriver
* @param string $url * @param string $url
* @return void * @return void
*/ */
protected function setupFallbackDriver(string $url) protected function setupFallbackDriver(string $url): void
{ {
$this->fallbackDriver = new GitDriver( $this->fallbackDriver = new GitDriver(
array('url' => $url), array('url' => $url),
@ -461,7 +461,7 @@ class GitBitbucketDriver extends VcsDriver
* @param array<array{name: string, href: string}> $cloneLinks * @param array<array{name: string, href: string}> $cloneLinks
* @return void * @return void
*/ */
protected function parseCloneUrls(array $cloneLinks) protected function parseCloneUrls(array $cloneLinks): void
{ {
foreach ($cloneLinks as $cloneLink) { foreach ($cloneLinks as $cloneLink) {
if ($cloneLink['name'] === 'https') { if ($cloneLink['name'] === 'https') {
@ -475,7 +475,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @return (array{name: string}&mixed[])|null * @return (array{name: string}&mixed[])|null
*/ */
protected function getMainBranchData() protected function getMainBranchData(): ?array
{ {
$resource = sprintf( $resource = sprintf(
'https://api.bitbucket.org/2.0/repositories/%s/%s?fields=mainbranch', 'https://api.bitbucket.org/2.0/repositories/%s/%s?fields=mainbranch',
@ -494,7 +494,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
if ($this->fallbackDriver) { if ($this->fallbackDriver) {
return $this->fallbackDriver->getRootIdentifier(); return $this->fallbackDriver->getRootIdentifier();
@ -527,7 +527,7 @@ class GitBitbucketDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
if (!Preg::isMatch('#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i', $url)) { if (!Preg::isMatch('#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i', $url)) {
return false; return false;

View File

@ -38,7 +38,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
if (Filesystem::isLocalPath($this->url)) { if (Filesystem::isLocalPath($this->url)) {
$this->url = Preg::replace('{[\\/]\.git/?$}', '', $this->url); $this->url = Preg::replace('{[\\/]\.git/?$}', '', $this->url);
@ -88,7 +88,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
if (null === $this->rootIdentifier) { if (null === $this->rootIdentifier) {
$this->rootIdentifier = 'master'; $this->rootIdentifier = 'master';
@ -112,7 +112,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
return $this->url; return $this->url;
} }
@ -120,7 +120,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
return array('type' => 'git', 'url' => $this->getUrl(), 'reference' => $identifier); return array('type' => 'git', 'url' => $this->getUrl(), 'reference' => $identifier);
} }
@ -128,7 +128,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
return null; return null;
} }
@ -136,7 +136,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
$resource = sprintf('%s:%s', ProcessExecutor::escape($identifier), ProcessExecutor::escape($file)); $resource = sprintf('%s:%s', ProcessExecutor::escape($identifier), ProcessExecutor::escape($file));
$this->process->execute(sprintf('git show %s', $resource), $content, $this->repoDir); $this->process->execute(sprintf('git show %s', $resource), $content, $this->repoDir);
@ -151,20 +151,20 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
$this->process->execute(sprintf( $this->process->execute(sprintf(
'git -c log.showSignature=false log -1 --format=%%at %s', 'git -c log.showSignature=false log -1 --format=%%at %s',
ProcessExecutor::escape($identifier) ProcessExecutor::escape($identifier)
), $output, $this->repoDir); ), $output, $this->repoDir);
return new \DateTime('@'.trim($output), new \DateTimeZone('UTC')); return new \DateTimeImmutable('@'.trim($output), new \DateTimeZone('UTC'));
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
if (null === $this->tags) { if (null === $this->tags) {
$this->tags = array(); $this->tags = array();
@ -183,7 +183,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
if (null === $this->branches) { if (null === $this->branches) {
$branches = array(); $branches = array();
@ -206,7 +206,7 @@ class GitDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
if (Preg::isMatch('#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i', $url)) { if (Preg::isMatch('#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i', $url)) {
return true; return true;

View File

@ -57,7 +57,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
if (!Preg::isMatch('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match)) { if (!Preg::isMatch('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match)) {
throw new \InvalidArgumentException(sprintf('The GitHub repository URL %s is invalid.', $this->url)); throw new \InvalidArgumentException(sprintf('The GitHub repository URL %s is invalid.', $this->url));
@ -84,7 +84,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @return string * @return string
*/ */
public function getRepositoryUrl() public function getRepositoryUrl(): string
{ {
return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository; return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository;
} }
@ -92,7 +92,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getRootIdentifier(); return $this->gitDriver->getRootIdentifier();
@ -104,7 +104,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getUrl(); return $this->gitDriver->getUrl();
@ -116,7 +116,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @return string * @return string
*/ */
protected function getApiUrl() protected function getApiUrl(): string
{ {
if ('github.com' === $this->originUrl) { if ('github.com' === $this->originUrl) {
$apiUrl = 'api.github.com'; $apiUrl = 'api.github.com';
@ -130,7 +130,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getSource($identifier); return $this->gitDriver->getSource($identifier);
@ -149,7 +149,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
$url = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/zipball/'.$identifier; $url = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/zipball/'.$identifier;
@ -159,7 +159,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getComposerInformation(string $identifier) public function getComposerInformation(string $identifier): ?array
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getComposerInformation($identifier); return $this->gitDriver->getComposerInformation($identifier);
@ -176,7 +176,7 @@ class GitHubDriver extends VcsDriver
} }
} }
if ($composer) { if ($composer !== null) {
// specials for github // specials for github
if (!isset($composer['support']['source'])) { if (!isset($composer['support']['source'])) {
$label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier; $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
@ -287,7 +287,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getFileContent($file, $identifier); return $this->gitDriver->getFileContent($file, $identifier);
@ -305,7 +305,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getChangeDate($identifier); return $this->gitDriver->getChangeDate($identifier);
@ -314,13 +314,13 @@ class GitHubDriver extends VcsDriver
$resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/commits/'.urlencode($identifier); $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/commits/'.urlencode($identifier);
$commit = $this->getContents($resource)->decodeJson(); $commit = $this->getContents($resource)->decodeJson();
return new \DateTime($commit['commit']['committer']['date']); return new \DateTimeImmutable($commit['commit']['committer']['date']);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getTags(); return $this->gitDriver->getTags();
@ -348,7 +348,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getBranches(); return $this->gitDriver->getBranches();
@ -379,7 +379,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
if (!Preg::isMatch('#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $url, $matches)) { if (!Preg::isMatch('#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $url, $matches)) {
return false; return false;
@ -404,7 +404,7 @@ class GitHubDriver extends VcsDriver
* *
* @return mixed[]|null * @return mixed[]|null
*/ */
public function getRepoData() public function getRepoData(): ?array
{ {
$this->fetchRootIdentifier(); $this->fetchRootIdentifier();
@ -416,7 +416,7 @@ class GitHubDriver extends VcsDriver
* *
* @return string * @return string
*/ */
protected function generateSshUrl() protected function generateSshUrl(): string
{ {
if (false !== strpos($this->originUrl, ':')) { if (false !== strpos($this->originUrl, ':')) {
return 'ssh://git@' . $this->originUrl . '/'.$this->owner.'/'.$this->repository.'.git'; return 'ssh://git@' . $this->originUrl . '/'.$this->owner.'/'.$this->repository.'.git';
@ -430,7 +430,7 @@ class GitHubDriver extends VcsDriver
* *
* @param bool $fetchingRepoData * @param bool $fetchingRepoData
*/ */
protected function getContents(string $url, bool $fetchingRepoData = false) protected function getContents(string $url, bool $fetchingRepoData = false): Response
{ {
try { try {
return parent::getContents($url); return parent::getContents($url);
@ -521,7 +521,7 @@ class GitHubDriver extends VcsDriver
* @return void * @return void
* @throws TransportException * @throws TransportException
*/ */
protected function fetchRootIdentifier() protected function fetchRootIdentifier(): void
{ {
if ($this->repoData) { if ($this->repoData) {
return; return;
@ -563,7 +563,7 @@ class GitHubDriver extends VcsDriver
* @return true * @return true
* @throws \RuntimeException * @throws \RuntimeException
*/ */
protected function attemptCloneFallback() protected function attemptCloneFallback(): bool
{ {
$this->isPrivate = true; $this->isPrivate = true;
@ -588,7 +588,7 @@ class GitHubDriver extends VcsDriver
* *
* @return void * @return void
*/ */
protected function setupGitDriver(string $url) protected function setupGitDriver(string $url): void
{ {
$this->gitDriver = new GitDriver( $this->gitDriver = new GitDriver(
array('url' => $url), array('url' => $url),
@ -603,7 +603,7 @@ class GitHubDriver extends VcsDriver
/** /**
* @return string|null * @return string|null
*/ */
protected function getNextPage(Response $response) protected function getNextPage(Response $response): ?string
{ {
$header = $response->getHeader('link'); $header = $response->getHeader('link');
if (!$header) { if (!$header) {

View File

@ -144,7 +144,7 @@ class GitLabDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getComposerInformation($identifier): array public function getComposerInformation(string $identifier): ?array
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getComposerInformation($identifier); return $this->gitDriver->getComposerInformation($identifier);
@ -161,7 +161,7 @@ class GitLabDriver extends VcsDriver
} }
} }
if ($composer) { if (null !== $composer) {
// specials for gitlab (this data is only available if authentication is provided) // specials for gitlab (this data is only available if authentication is provided)
if (!isset($composer['support']['source']) && isset($this->project['web_url'])) { if (!isset($composer['support']['source']) && isset($this->project['web_url'])) {
$label = array_search($identifier, $this->getTags(), true) ?: array_search($identifier, $this->getBranches(), true) ?: $identifier; $label = array_search($identifier, $this->getTags(), true) ?: array_search($identifier, $this->getBranches(), true) ?: $identifier;
@ -216,17 +216,17 @@ class GitLabDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier): ?\DateTime public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
if ($this->gitDriver) { if ($this->gitDriver) {
return $this->gitDriver->getChangeDate($identifier); return $this->gitDriver->getChangeDate($identifier);
} }
if (isset($this->commits[$identifier])) { if (isset($this->commits[$identifier])) {
return new \DateTime($this->commits[$identifier]['committed_date']); return new \DateTimeImmutable($this->commits[$identifier]['committed_date']);
} }
return new \DateTime(); return null;
} }
/** /**

View File

@ -37,7 +37,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
if (Filesystem::isLocalPath($this->url)) { if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = $this->url; $this->repoDir = $this->url;
@ -86,7 +86,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
if (null === $this->rootIdentifier) { if (null === $this->rootIdentifier) {
$this->process->execute(sprintf('hg tip --template "{node}"'), $output, $this->repoDir); $this->process->execute(sprintf('hg tip --template "{node}"'), $output, $this->repoDir);
@ -100,7 +100,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
return $this->url; return $this->url;
} }
@ -108,7 +108,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
return array('type' => 'hg', 'url' => $this->getUrl(), 'reference' => $identifier); return array('type' => 'hg', 'url' => $this->getUrl(), 'reference' => $identifier);
} }
@ -116,7 +116,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
return null; return null;
} }
@ -124,7 +124,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
$resource = sprintf('hg cat -r %s %s', ProcessExecutor::escape($identifier), ProcessExecutor::escape($file)); $resource = sprintf('hg cat -r %s %s', ProcessExecutor::escape($identifier), ProcessExecutor::escape($file));
$this->process->execute($resource, $content, $this->repoDir); $this->process->execute($resource, $content, $this->repoDir);
@ -139,7 +139,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
$this->process->execute( $this->process->execute(
sprintf( sprintf(
@ -150,13 +150,13 @@ class HgDriver extends VcsDriver
$this->repoDir $this->repoDir
); );
return new \DateTime(trim($output), new \DateTimeZone('UTC')); return new \DateTimeImmutable(trim($output), new \DateTimeZone('UTC'));
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
if (null === $this->tags) { if (null === $this->tags) {
$tags = array(); $tags = array();
@ -178,7 +178,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
if (null === $this->branches) { if (null === $this->branches) {
$branches = array(); $branches = array();
@ -208,7 +208,7 @@ class HgDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
if (Preg::isMatch('#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { if (Preg::isMatch('#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) {
return true; return true;

View File

@ -18,6 +18,7 @@ use Composer\IO\IOInterface;
use Composer\Pcre\Preg; use Composer\Pcre\Preg;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Perforce; use Composer\Util\Perforce;
use Composer\Util\Http\Response;
/** /**
* @author Matt Whittom <Matt.Whittom@veteransunited.com> * @author Matt Whittom <Matt.Whittom@veteransunited.com>
@ -34,7 +35,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
$this->depot = $this->repoConfig['depot']; $this->depot = $this->repoConfig['depot'];
$this->branch = ''; $this->branch = '';
@ -72,7 +73,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
return $this->perforce->getFileContent($file, $identifier); return $this->perforce->getFileContent($file, $identifier);
} }
@ -80,7 +81,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
return null; return null;
} }
@ -88,7 +89,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
return $this->branch; return $this->branch;
} }
@ -96,7 +97,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
return $this->perforce->getBranches(); return $this->perforce->getBranches();
} }
@ -104,7 +105,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
return $this->perforce->getTags(); return $this->perforce->getTags();
} }
@ -112,7 +113,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
return null; return null;
} }
@ -120,7 +121,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
return array( return array(
'type' => 'perforce', 'type' => 'perforce',
@ -133,7 +134,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
return $this->url; return $this->url;
} }
@ -141,7 +142,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function hasComposerFile(string $identifier) public function hasComposerFile(string $identifier): bool
{ {
$composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier);
@ -151,7 +152,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getContents(string $url) public function getContents(string $url): Response
{ {
throw new \BadMethodCallException('Not implemented/used in PerforceDriver'); throw new \BadMethodCallException('Not implemented/used in PerforceDriver');
} }
@ -159,7 +160,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
if ($deep || Preg::isMatch('#\b(perforce|p4)\b#i', $url)) { if ($deep || Preg::isMatch('#\b(perforce|p4)\b#i', $url)) {
return Perforce::checkServerExists($url, new ProcessExecutor($io)); return Perforce::checkServerExists($url, new ProcessExecutor($io));
@ -171,7 +172,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function cleanup() public function cleanup(): void
{ {
$this->perforce->cleanupClientSpec(); $this->perforce->cleanupClientSpec();
$this->perforce = null; $this->perforce = null;
@ -180,7 +181,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @return string * @return string
*/ */
public function getDepot() public function getDepot(): string
{ {
return $this->depot; return $this->depot;
} }
@ -188,7 +189,7 @@ class PerforceDriver extends VcsDriver
/** /**
* @return string * @return string
*/ */
public function getBranch() public function getBranch(): string
{ {
return $this->branch; return $this->branch;
} }

View File

@ -57,7 +57,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function initialize() public function initialize(): void
{ {
$this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
@ -93,7 +93,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getRootIdentifier() public function getRootIdentifier(): string
{ {
return $this->rootIdentifier ?: $this->trunkPath; return $this->rootIdentifier ?: $this->trunkPath;
} }
@ -101,7 +101,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getUrl() public function getUrl(): string
{ {
return $this->url; return $this->url;
} }
@ -109,7 +109,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getSource(string $identifier) public function getSource(string $identifier): array
{ {
return array('type' => 'svn', 'url' => $this->baseUrl, 'reference' => $identifier); return array('type' => 'svn', 'url' => $this->baseUrl, 'reference' => $identifier);
} }
@ -117,7 +117,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getDist(string $identifier) public function getDist(string $identifier): ?array
{ {
return null; return null;
} }
@ -125,7 +125,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function shouldCache(string $identifier) protected function shouldCache(string $identifier): bool
{ {
return $this->cache && Preg::isMatch('{@\d+$}', $identifier); return $this->cache && Preg::isMatch('{@\d+$}', $identifier);
} }
@ -133,7 +133,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getComposerInformation(string $identifier) public function getComposerInformation(string $identifier): ?array
{ {
if (!isset($this->infoCache[$identifier])) { if (!isset($this->infoCache[$identifier])) {
if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier.'.json')) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier.'.json')) {
@ -165,7 +165,7 @@ class SvnDriver extends VcsDriver
* @param string $file * @param string $file
* @param string $identifier * @param string $identifier
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
$identifier = '/' . trim($identifier, '/') . '/'; $identifier = '/' . trim($identifier, '/') . '/';
@ -194,7 +194,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getChangeDate(string $identifier) public function getChangeDate(string $identifier): ?\DateTimeImmutable
{ {
$identifier = '/' . trim($identifier, '/') . '/'; $identifier = '/' . trim($identifier, '/') . '/';
@ -210,7 +210,7 @@ class SvnDriver extends VcsDriver
$output = $this->execute('svn info', $this->baseUrl . $path . $rev); $output = $this->execute('svn info', $this->baseUrl . $path . $rev);
foreach ($this->process->splitLines($output) as $line) { foreach ($this->process->splitLines($output) as $line) {
if ($line && Preg::isMatch('{^Last Changed Date: ([^(]+)}', $line, $match)) { if ($line && Preg::isMatch('{^Last Changed Date: ([^(]+)}', $line, $match)) {
return new \DateTime($match[1], new \DateTimeZone('UTC')); return new \DateTimeImmutable($match[1], new \DateTimeZone('UTC'));
} }
} }
@ -220,7 +220,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTags() public function getTags(): array
{ {
if (null === $this->tags) { if (null === $this->tags) {
$tags = array(); $tags = array();
@ -251,7 +251,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getBranches() public function getBranches(): array
{ {
if (null === $this->branches) { if (null === $this->branches) {
$branches = array(); $branches = array();
@ -306,7 +306,7 @@ class SvnDriver extends VcsDriver
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool
{ {
$url = self::normalizeUrl($url); $url = self::normalizeUrl($url);
if (Preg::isMatch('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) { if (Preg::isMatch('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) {
@ -353,7 +353,7 @@ class SvnDriver extends VcsDriver
* *
* @return string * @return string
*/ */
protected static function normalizeUrl(string $url) protected static function normalizeUrl(string $url): string
{ {
$fs = new Filesystem(); $fs = new Filesystem();
if ($fs->isAbsolutePath($url)) { if ($fs->isAbsolutePath($url)) {
@ -372,7 +372,7 @@ class SvnDriver extends VcsDriver
* @throws \RuntimeException * @throws \RuntimeException
* @return string * @return string
*/ */
protected function execute(string $command, string $url) protected function execute(string $command, string $url): string
{ {
if (null === $this->util) { if (null === $this->util) {
$this->util = new SvnUtil($this->baseUrl, $this->io, $this->config, $this->process); $this->util = new SvnUtil($this->baseUrl, $this->io, $this->config, $this->process);
@ -400,7 +400,7 @@ class SvnDriver extends VcsDriver
* *
* @return string * @return string
*/ */
protected function buildIdentifier(string $baseDir, int $revision) protected function buildIdentifier(string $baseDir, int $revision): string
{ {
return rtrim($baseDir, '/') . $this->packagePath . '/@' . $revision; return rtrim($baseDir, '/') . $this->packagePath . '/@' . $revision;
} }

View File

@ -79,7 +79,7 @@ abstract class VcsDriver implements VcsDriverInterface
* @param string $identifier * @param string $identifier
* @return bool * @return bool
*/ */
protected function shouldCache(string $identifier) protected function shouldCache(string $identifier): bool
{ {
return $this->cache && Preg::isMatch('{^[a-f0-9]{40}$}iD', $identifier); return $this->cache && Preg::isMatch('{^[a-f0-9]{40}$}iD', $identifier);
} }
@ -87,7 +87,7 @@ abstract class VcsDriver implements VcsDriverInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getComposerInformation(string $identifier) public function getComposerInformation(string $identifier): ?array
{ {
if (!isset($this->infoCache[$identifier])) { if (!isset($this->infoCache[$identifier])) {
if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) {
@ -111,7 +111,7 @@ abstract class VcsDriver implements VcsDriverInterface
* *
* @return array<string, mixed>|null * @return array<string, mixed>|null
*/ */
protected function getBaseComposerInformation(string $identifier) protected function getBaseComposerInformation(string $identifier): ?array
{ {
$composerFileContent = $this->getFileContent('composer.json', $identifier); $composerFileContent = $this->getFileContent('composer.json', $identifier);
@ -121,7 +121,7 @@ abstract class VcsDriver implements VcsDriverInterface
$composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json'); $composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json');
if (empty($composer['time']) && $changeDate = $this->getChangeDate($identifier)) { if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) {
$composer['time'] = $changeDate->format(DATE_RFC3339); $composer['time'] = $changeDate->format(DATE_RFC3339);
} }
@ -131,7 +131,7 @@ abstract class VcsDriver implements VcsDriverInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function hasComposerFile(string $identifier) public function hasComposerFile(string $identifier): bool
{ {
try { try {
return (bool) $this->getComposerInformation($identifier); return (bool) $this->getComposerInformation($identifier);
@ -148,7 +148,7 @@ abstract class VcsDriver implements VcsDriverInterface
* *
* @return string The correct type of protocol * @return string The correct type of protocol
*/ */
protected function getScheme() protected function getScheme(): string
{ {
if (extension_loaded('openssl')) { if (extension_loaded('openssl')) {
return 'https'; return 'https';
@ -165,7 +165,7 @@ abstract class VcsDriver implements VcsDriverInterface
* @return Response * @return Response
* @throws TransportException * @throws TransportException
*/ */
protected function getContents(string $url) protected function getContents(string $url): Response
{ {
$options = $this->repoConfig['options'] ?? array(); $options = $this->repoConfig['options'] ?? array();
@ -175,7 +175,7 @@ abstract class VcsDriver implements VcsDriverInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function cleanup() public function cleanup(): void
{ {
return; return;
} }

View File

@ -17,6 +17,7 @@ use Composer\IO\IOInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* @internal
*/ */
interface VcsDriverInterface interface VcsDriverInterface
{ {
@ -25,15 +26,15 @@ interface VcsDriverInterface
* *
* @return void * @return void
*/ */
public function initialize(); public function initialize(): void;
/** /**
* Return the composer.json file information * Return the composer.json file information
* *
* @param string $identifier Any identifier to a specific branch/tag/commit * @param string $identifier Any identifier to a specific branch/tag/commit
* @return mixed[] containing all infos from the composer.json file * @return mixed[]|null containing all infos from the composer.json file
*/ */
public function getComposerInformation(string $identifier); public function getComposerInformation(string $identifier): ?array;
/** /**
* Return the content of $file or null if the file does not exist. * Return the content of $file or null if the file does not exist.
@ -42,57 +43,56 @@ interface VcsDriverInterface
* @param string $identifier * @param string $identifier
* @return string|null * @return string|null
*/ */
public function getFileContent(string $file, string $identifier); public function getFileContent(string $file, string $identifier): ?string;
/** /**
* Get the changedate for $identifier. * Get the changedate for $identifier.
* *
* @param string $identifier * @param string $identifier
* @return \DateTime|null
*/ */
public function getChangeDate(string $identifier); public function getChangeDate(string $identifier): ?\DateTimeImmutable;
/** /**
* Return the root identifier (trunk, master, default/tip ..) * Return the root identifier (trunk, master, default/tip ..)
* *
* @return string Identifier * @return string Identifier
*/ */
public function getRootIdentifier(); public function getRootIdentifier(): string;
/** /**
* Return list of branches in the repository * Return list of branches in the repository
* *
* @return array<int|string, string> Branch names as keys, identifiers as values * @return array<int|string, string> Branch names as keys, identifiers as values
*/ */
public function getBranches(); public function getBranches(): array;
/** /**
* Return list of tags in the repository * Return list of tags in the repository
* *
* @return array<int|string, string> Tag names as keys, identifiers as values * @return array<int|string, string> Tag names as keys, identifiers as values
*/ */
public function getTags(); public function getTags(): array;
/** /**
* @param string $identifier Any identifier to a specific branch/tag/commit * @param string $identifier Any identifier to a specific branch/tag/commit
* *
* @return array{type: string, url: string, reference: string, shasum: string}|null * @return array{type: string, url: string, reference: string, shasum: string}|null
*/ */
public function getDist(string $identifier); public function getDist(string $identifier): ?array;
/** /**
* @param string $identifier Any identifier to a specific branch/tag/commit * @param string $identifier Any identifier to a specific branch/tag/commit
* *
* @return array{type: string, url: string, reference: string} * @return array{type: string, url: string, reference: string}
*/ */
public function getSource(string $identifier); public function getSource(string $identifier): array;
/** /**
* Return the URL of the repository * Return the URL of the repository
* *
* @return string * @return string
*/ */
public function getUrl(); public function getUrl(): string;
/** /**
* Return true if the repository has a composer file for a given identifier, * Return true if the repository has a composer file for a given identifier,
@ -101,14 +101,14 @@ interface VcsDriverInterface
* @param string $identifier Any identifier to a specific branch/tag/commit * @param string $identifier Any identifier to a specific branch/tag/commit
* @return bool Whether the repository has a composer file for a given identifier. * @return bool Whether the repository has a composer file for a given identifier.
*/ */
public function hasComposerFile(string $identifier); public function hasComposerFile(string $identifier): bool;
/** /**
* Performs any cleanup necessary as the driver is not longer needed * Performs any cleanup necessary as the driver is not longer needed
* *
* @return void * @return void
*/ */
public function cleanup(); public function cleanup(): void;
/** /**
* Checks if this driver can handle a given url * Checks if this driver can handle a given url
@ -119,5 +119,5 @@ interface VcsDriverInterface
* @param bool $deep unless true, only shallow checks (url matching typically) should be done * @param bool $deep unless true, only shallow checks (url matching typically) should be done
* @return bool * @return bool
*/ */
public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false); public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false): bool;
} }

View File

@ -121,7 +121,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
/** /**
* @return void * @return void
*/ */
public function setLoader(LoaderInterface $loader) public function setLoader(LoaderInterface $loader): void
{ {
$this->loader = $loader; $this->loader = $loader;
} }
@ -129,7 +129,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
/** /**
* @return VcsDriverInterface|null * @return VcsDriverInterface|null
*/ */
public function getDriver() public function getDriver(): ?VcsDriverInterface
{ {
if ($this->driver) { if ($this->driver) {
return $this->driver; return $this->driver;
@ -167,7 +167,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
/** /**
* @return bool * @return bool
*/ */
public function hadInvalidBranches() public function hadInvalidBranches(): bool
{ {
return $this->branchErrorOccurred; return $this->branchErrorOccurred;
} }
@ -175,7 +175,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
/** /**
* @return string[] * @return string[]
*/ */
public function getEmptyReferences() public function getEmptyReferences(): array
{ {
return $this->emptyReferences; return $this->emptyReferences;
} }
@ -183,7 +183,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
/** /**
* @return array<'tags'|'branches', array<string, TransportException>> * @return array<'tags'|'branches', array<string, TransportException>>
*/ */
public function getVersionTransportExceptions() public function getVersionTransportExceptions(): array
{ {
return $this->versionTransportExceptions; return $this->versionTransportExceptions;
} }
@ -254,7 +254,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
try { try {
if (!$data = $driver->getComposerInformation($identifier)) { $data = $driver->getComposerInformation($identifier);
if (null === $data) {
if ($isVeryVerbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', no composer file</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', no composer file</warning>');
} }
@ -367,7 +368,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
try { try {
if (!$data = $driver->getComposerInformation($identifier)) { $data = $driver->getComposerInformation($identifier);
if (null === $data) {
if ($isVeryVerbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', no composer file</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', no composer file</warning>');
} }

View File

@ -67,7 +67,7 @@ class Event extends BaseEvent
* *
* @return Composer * @return Composer
*/ */
public function getComposer() public function getComposer(): Composer
{ {
return $this->composer; return $this->composer;
} }
@ -77,7 +77,7 @@ class Event extends BaseEvent
* *
* @return IOInterface * @return IOInterface
*/ */
public function getIO() public function getIO(): IOInterface
{ {
return $this->io; return $this->io;
} }
@ -87,7 +87,7 @@ class Event extends BaseEvent
* *
* @return bool * @return bool
*/ */
public function isDevMode() public function isDevMode(): bool
{ {
return $this->devMode; return $this->devMode;
} }

View File

@ -49,7 +49,7 @@ class Git
* *
* @return void * @return void
*/ */
public function runCommand(callable $commandCallable, string $url, ?string $cwd, bool $initialClone = false) public function runCommand(callable $commandCallable, string $url, ?string $cwd, bool $initialClone = false): void
{ {
// Ensure we are allowed to use this URL by config // Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io); $this->config->prohibitUrlByConfig($url, $this->io);
@ -272,7 +272,7 @@ class Git
* *
* @return bool * @return bool
*/ */
public function syncMirror(string $url, string $dir) public function syncMirror(string $url, string $dir): bool
{ {
if (Platform::getEnv('COMPOSER_DISABLE_NETWORK') && Platform::getEnv('COMPOSER_DISABLE_NETWORK') !== 'prime') { if (Platform::getEnv('COMPOSER_DISABLE_NETWORK') && Platform::getEnv('COMPOSER_DISABLE_NETWORK') !== 'prime') {
$this->io->writeError('<warning>Aborting git mirror sync of '.$url.' as network is disabled</warning>'); $this->io->writeError('<warning>Aborting git mirror sync of '.$url.' as network is disabled</warning>');
@ -317,7 +317,7 @@ class Git
* *
* @return bool * @return bool
*/ */
public function fetchRefOrSyncMirror(string $url, string $dir, string $ref) public function fetchRefOrSyncMirror(string $url, string $dir, string $ref): bool
{ {
if ($this->checkRefIsInMirror($dir, $ref)) { if ($this->checkRefIsInMirror($dir, $ref)) {
return true; return true;
@ -333,7 +333,7 @@ class Git
/** /**
* @return string * @return string
*/ */
public static function getNoShowSignatureFlag(ProcessExecutor $process) public static function getNoShowSignatureFlag(ProcessExecutor $process): string
{ {
$gitVersion = self::getVersion($process); $gitVersion = self::getVersion($process);
if ($gitVersion && version_compare($gitVersion, '2.10.0-rc0', '>=')) { if ($gitVersion && version_compare($gitVersion, '2.10.0-rc0', '>=')) {
@ -395,7 +395,7 @@ class Git
/** /**
* @return void * @return void
*/ */
public static function cleanEnv() public static function cleanEnv(): void
{ {
// added in git 1.7.1, prevents prompting the user for username/password // added in git 1.7.1, prevents prompting the user for username/password
if (Platform::getEnv('GIT_ASKPASS') !== 'echo') { if (Platform::getEnv('GIT_ASKPASS') !== 'echo') {
@ -458,7 +458,7 @@ class Git
* *
* @return string|null The git version number, if present. * @return string|null The git version number, if present.
*/ */
public static function getVersion(ProcessExecutor $process) public static function getVersion(ProcessExecutor $process): ?string
{ {
if (false === self::$version) { if (false === self::$version) {
self::$version = null; self::$version = null;

View File

@ -85,7 +85,7 @@ class Perforce
* *
* @return self * @return self
*/ */
public static function create($repoConfig, string $port, string $path, ProcessExecutor $process, IOInterface $io) public static function create($repoConfig, string $port, string $path, ProcessExecutor $process, IOInterface $io): self
{ {
return new Perforce($repoConfig, $port, $path, $process, Platform::isWindows(), $io); return new Perforce($repoConfig, $port, $path, $process, Platform::isWindows(), $io);
} }
@ -96,7 +96,7 @@ class Perforce
* *
* @return bool * @return bool
*/ */
public static function checkServerExists(string $url, ProcessExecutor $processExecutor) public static function checkServerExists(string $url, ProcessExecutor $processExecutor): bool
{ {
return 0 === $processExecutor->execute('p4 -p ' . ProcessExecutor::escape($url) . ' info -s', $ignoredOutput); return 0 === $processExecutor->execute('p4 -p ' . ProcessExecutor::escape($url) . ' info -s', $ignoredOutput);
} }
@ -106,7 +106,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function initialize($repoConfig) public function initialize($repoConfig): void
{ {
$this->uniquePerforceClientName = $this->generateUniquePerforceClientName(); $this->uniquePerforceClientName = $this->generateUniquePerforceClientName();
if (!$repoConfig) { if (!$repoConfig) {
@ -138,7 +138,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function initializeDepotAndBranch(?string $depot, ?string $branch) public function initializeDepotAndBranch(?string $depot, ?string $branch): void
{ {
if (isset($depot)) { if (isset($depot)) {
$this->p4Depot = $depot; $this->p4Depot = $depot;
@ -159,7 +159,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function cleanupClientSpec() public function cleanupClientSpec(): void
{ {
$client = $this->getClient(); $client = $this->getClient();
$task = 'client -d ' . ProcessExecutor::escape($client); $task = 'client -d ' . ProcessExecutor::escape($client);
@ -176,7 +176,7 @@ class Perforce
* *
* @return int * @return int
*/ */
protected function executeCommand($command) protected function executeCommand($command): int
{ {
$this->commandResult = ''; $this->commandResult = '';
@ -186,7 +186,7 @@ class Perforce
/** /**
* @return string * @return string
*/ */
public function getClient() public function getClient(): string
{ {
if (!isset($this->p4Client)) { if (!isset($this->p4Client)) {
$cleanStreamName = str_replace(array('//', '/', '@'), array('', '_', ''), $this->getStream()); $cleanStreamName = str_replace(array('//', '/', '@'), array('', '_', ''), $this->getStream());
@ -199,7 +199,7 @@ class Perforce
/** /**
* @return string * @return string
*/ */
protected function getPath() protected function getPath(): string
{ {
return $this->path; return $this->path;
} }
@ -209,7 +209,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function initializePath(string $path) public function initializePath(string $path): void
{ {
$this->path = $path; $this->path = $path;
$fs = $this->getFilesystem(); $fs = $this->getFilesystem();
@ -219,7 +219,7 @@ class Perforce
/** /**
* @return string * @return string
*/ */
protected function getPort() protected function getPort(): string
{ {
return $this->p4Port; return $this->p4Port;
} }
@ -229,7 +229,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function setStream(string $stream) public function setStream(string $stream): void
{ {
$this->p4Stream = $stream; $this->p4Stream = $stream;
$index = strrpos($stream, '/'); $index = strrpos($stream, '/');
@ -242,7 +242,7 @@ class Perforce
/** /**
* @return bool * @return bool
*/ */
public function isStream() public function isStream(): bool
{ {
return is_string($this->p4DepotType) && (strcmp($this->p4DepotType, 'stream') === 0); return is_string($this->p4DepotType) && (strcmp($this->p4DepotType, 'stream') === 0);
} }
@ -250,7 +250,7 @@ class Perforce
/** /**
* @return string * @return string
*/ */
public function getStream() public function getStream(): string
{ {
if (!isset($this->p4Stream)) { if (!isset($this->p4Stream)) {
if ($this->isStream()) { if ($this->isStream()) {
@ -268,7 +268,7 @@ class Perforce
* *
* @return string * @return string
*/ */
public function getStreamWithoutLabel(string $stream) public function getStreamWithoutLabel(string $stream): string
{ {
$index = strpos($stream, '@'); $index = strpos($stream, '@');
if ($index === false) { if ($index === false) {
@ -289,7 +289,7 @@ class Perforce
/** /**
* @return string|null * @return string|null
*/ */
public function getUser() public function getUser(): ?string
{ {
return $this->p4User; return $this->p4User;
} }
@ -299,7 +299,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function setUser(?string $user) public function setUser(?string $user): void
{ {
$this->p4User = $user; $this->p4User = $user;
} }
@ -307,7 +307,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function queryP4User() public function queryP4User(): void
{ {
$this->getUser(); $this->getUser();
if (strlen((string) $this->p4User) > 0) { if (strlen((string) $this->p4User) > 0) {
@ -365,7 +365,7 @@ class Perforce
/** /**
* @return string|null * @return string|null
*/ */
public function queryP4Password() public function queryP4Password(): ?string
{ {
if (isset($this->p4Password)) { if (isset($this->p4Password)) {
return $this->p4Password; return $this->p4Password;
@ -400,7 +400,7 @@ class Perforce
/** /**
* @return bool * @return bool
*/ */
public function isLoggedIn() public function isLoggedIn(): bool
{ {
$command = $this->generateP4Command('login -s', false); $command = $this->generateP4Command('login -s', false);
$exitCode = $this->executeCommand($command); $exitCode = $this->executeCommand($command);
@ -423,7 +423,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function connectClient() public function connectClient(): void
{ {
$p4CreateClientCommand = $this->generateP4Command( $p4CreateClientCommand = $this->generateP4Command(
'client -i < ' . str_replace(" ", "\\ ", $this->getP4ClientSpec()) 'client -i < ' . str_replace(" ", "\\ ", $this->getP4ClientSpec())
@ -436,7 +436,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function syncCodeBase(?string $sourceReference) public function syncCodeBase(?string $sourceReference): void
{ {
$prevDir = Platform::getCwd(); $prevDir = Platform::getCwd();
chdir($this->path); chdir($this->path);
@ -453,7 +453,7 @@ class Perforce
* *
* @return void * @return void
*/ */
public function writeClientSpecToFile($spec) public function writeClientSpecToFile($spec): void
{ {
fwrite($spec, 'Client: ' . $this->getClient() . PHP_EOL . PHP_EOL); fwrite($spec, 'Client: ' . $this->getClient() . PHP_EOL . PHP_EOL);
fwrite($spec, 'Update: ' . date('Y/m/d H:i:s') . PHP_EOL . PHP_EOL); fwrite($spec, 'Update: ' . date('Y/m/d H:i:s') . PHP_EOL . PHP_EOL);
@ -479,7 +479,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function writeP4ClientSpec() public function writeP4ClientSpec(): void
{ {
$clientSpec = $this->getP4ClientSpec(); $clientSpec = $this->getP4ClientSpec();
$spec = fopen($clientSpec, 'w'); $spec = fopen($clientSpec, 'w');
@ -498,7 +498,7 @@ class Perforce
* *
* @return void * @return void
*/ */
protected function read($pipe, $name) protected function read($pipe, $name): void
{ {
if (feof($pipe)) { if (feof($pipe)) {
return; return;
@ -514,7 +514,7 @@ class Perforce
* *
* @return int * @return int
*/ */
public function windowsLogin(?string $password) public function windowsLogin(?string $password): int
{ {
$command = $this->generateP4Command(' login -a'); $command = $this->generateP4Command(' login -a');
@ -526,7 +526,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function p4Login() public function p4Login(): void
{ {
$this->queryP4User(); $this->queryP4User();
if (!$this->isLoggedIn()) { if (!$this->isLoggedIn()) {
@ -546,14 +546,14 @@ class Perforce
/** /**
* @param string $identifier * @param string $identifier
* *
* @return mixed|void * @return mixed[]|null
*/ */
public function getComposerInformation(string $identifier) public function getComposerInformation(string $identifier): ?array
{ {
$composerFileContent = $this->getFileContent('composer.json', $identifier); $composerFileContent = $this->getFileContent('composer.json', $identifier);
if (!$composerFileContent) { if (!$composerFileContent) {
return; return null;
} }
return json_decode($composerFileContent, true); return json_decode($composerFileContent, true);
@ -565,7 +565,7 @@ class Perforce
* *
* @return string|null * @return string|null
*/ */
public function getFileContent(string $file, string $identifier) public function getFileContent(string $file, string $identifier): ?string
{ {
$path = $this->getFilePath($file, $identifier); $path = $this->getFilePath($file, $identifier);
@ -586,7 +586,7 @@ class Perforce
* *
* @return string|null * @return string|null
*/ */
public function getFilePath(string $file, string $identifier) public function getFilePath(string $file, string $identifier): ?string
{ {
$index = strpos($identifier, '@'); $index = strpos($identifier, '@');
if ($index === false) { if ($index === false) {
@ -646,7 +646,7 @@ class Perforce
/** /**
* @return array<string, string> * @return array<string, string>
*/ */
public function getTags() public function getTags(): array
{ {
$command = $this->generateP4Command('labels'); $command = $this->generateP4Command('labels');
$this->executeCommand($command); $this->executeCommand($command);
@ -666,7 +666,7 @@ class Perforce
/** /**
* @return bool * @return bool
*/ */
public function checkStream() public function checkStream(): bool
{ {
$command = $this->generateP4Command('depots', false); $command = $this->generateP4Command('depots', false);
$this->executeCommand($command); $this->executeCommand($command);
@ -690,7 +690,7 @@ class Perforce
* @param string $reference * @param string $reference
* @return mixed|null * @return mixed|null
*/ */
protected function getChangeList(string $reference) protected function getChangeList(string $reference): mixed
{ {
$index = strpos($reference, '@'); $index = strpos($reference, '@');
if ($index === false) { if ($index === false) {
@ -713,7 +713,7 @@ class Perforce
* @param string $toReference * @param string $toReference
* @return mixed|null * @return mixed|null
*/ */
public function getCommitLogs(string $fromReference, string $toReference) public function getCommitLogs(string $fromReference, string $toReference): mixed
{ {
$fromChangeList = $this->getChangeList($fromReference); $fromChangeList = $this->getChangeList($fromReference);
if ($fromChangeList === null) { if ($fromChangeList === null) {
@ -734,7 +734,7 @@ class Perforce
/** /**
* @return Filesystem * @return Filesystem
*/ */
public function getFilesystem() public function getFilesystem(): Filesystem
{ {
if (null === $this->filesystem) { if (null === $this->filesystem) {
$this->filesystem = new Filesystem($this->process); $this->filesystem = new Filesystem($this->process);
@ -746,7 +746,7 @@ class Perforce
/** /**
* @return void * @return void
*/ */
public function setFilesystem(Filesystem $fs) public function setFilesystem(Filesystem $fs): void
{ {
$this->filesystem = $fs; $this->filesystem = $fs;
} }

View File

@ -68,7 +68,7 @@ class ProcessExecutor
* @param null|string $cwd the working directory * @param null|string $cwd the working directory
* @return int statuscode * @return int statuscode
*/ */
public function execute($command, &$output = null, ?string $cwd = null) public function execute($command, &$output = null, ?string $cwd = null): int
{ {
if (func_num_args() > 1) { if (func_num_args() > 1) {
return $this->doExecute($command, $cwd, false, $output); return $this->doExecute($command, $cwd, false, $output);
@ -84,7 +84,7 @@ class ProcessExecutor
* @param null|string $cwd the working directory * @param null|string $cwd the working directory
* @return int statuscode * @return int statuscode
*/ */
public function executeTty($command, ?string $cwd = null) public function executeTty($command, ?string $cwd = null): int
{ {
if (Platform::isTty()) { if (Platform::isTty()) {
return $this->doExecute($command, $cwd, true); return $this->doExecute($command, $cwd, true);
@ -121,7 +121,10 @@ class ProcessExecutor
} }
} }
$callback = is_callable($output) ? $output : array($this, 'outputHandler'); $callback = is_callable($output) ? $output : function (string $type, string $buffer): void {
$this->outputHandler($type, $buffer);
};
$process->run($callback); $process->run($callback);
if ($this->captureOutput && !is_callable($output)) { if ($this->captureOutput && !is_callable($output)) {
@ -140,7 +143,7 @@ class ProcessExecutor
* @param string $cwd the working directory * @param string $cwd the working directory
* @return PromiseInterface * @return PromiseInterface
*/ */
public function executeAsync($command, ?string $cwd = null) public function executeAsync($command, ?string $cwd = null): PromiseInterface
{ {
if (!$this->allowAsync) { if (!$this->allowAsync) {
throw new \LogicException('You must use the ProcessExecutor instance which is part of a Composer\Loop instance to be able to run async processes'); throw new \LogicException('You must use the ProcessExecutor instance which is part of a Composer\Loop instance to be able to run async processes');
@ -206,6 +209,25 @@ class ProcessExecutor
return $promise; return $promise;
} }
protected function outputHandler(string $type, string $buffer): void
{
if ($this->captureOutput) {
return;
}
if (null === $this->io) {
echo $buffer;
return;
}
if (Process::ERR === $type) {
$this->io->writeErrorRaw($buffer, false);
} else {
$this->io->writeRaw($buffer, false);
}
}
/** /**
* @param int $id * @param int $id
* @return void * @return void
@ -253,7 +275,7 @@ class ProcessExecutor
* @param ?int $index job id * @param ?int $index job id
* @return void * @return void
*/ */
public function wait($index = null) public function wait($index = null): void
{ {
while (true) { while (true) {
if (!$this->countActiveJobs($index)) { if (!$this->countActiveJobs($index)) {
@ -324,7 +346,7 @@ class ProcessExecutor
* @param null|string $output * @param null|string $output
* @return string[] * @return string[]
*/ */
public function splitLines(?string $output) public function splitLines(?string $output): array
{ {
$output = trim((string) $output); $output = trim((string) $output);
@ -336,42 +358,15 @@ class ProcessExecutor
* *
* @return string * @return string
*/ */
public function getErrorOutput() public function getErrorOutput(): string
{ {
return $this->errorOutput; return $this->errorOutput;
} }
/**
* @private
*
* @param Process::ERR|Process::OUT $type
* @param string $buffer
*
* @return void
*/
public function outputHandler($type, string $buffer)
{
if ($this->captureOutput) {
return;
}
if (null === $this->io) {
echo $buffer;
return;
}
if (Process::ERR === $type) {
$this->io->writeErrorRaw($buffer, false);
} else {
$this->io->writeRaw($buffer, false);
}
}
/** /**
* @return int the timeout in seconds * @return int the timeout in seconds
*/ */
public static function getTimeout() public static function getTimeout(): int
{ {
return static::$timeout; return static::$timeout;
} }
@ -380,7 +375,7 @@ class ProcessExecutor
* @param int $timeout the timeout in seconds * @param int $timeout the timeout in seconds
* @return void * @return void
*/ */
public static function setTimeout(int $timeout) public static function setTimeout(int $timeout): void
{ {
static::$timeout = $timeout; static::$timeout = $timeout;
} }
@ -392,7 +387,7 @@ class ProcessExecutor
* *
* @return string The escaped argument * @return string The escaped argument
*/ */
public static function escape($argument) public static function escape($argument): string
{ {
return self::escapeArgument($argument); return self::escapeArgument($argument);
} }

View File

@ -20,7 +20,7 @@ class InitCommandTest extends TestCase
public function testParseValidAuthorString(): void public function testParseValidAuthorString(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString('John Smith <john@example.com>'); $author = $this->callParseAuthorString($command, 'John Smith <john@example.com>');
$this->assertEquals('John Smith', $author['name']); $this->assertEquals('John Smith', $author['name']);
$this->assertEquals('john@example.com', $author['email']); $this->assertEquals('john@example.com', $author['email']);
} }
@ -28,7 +28,7 @@ class InitCommandTest extends TestCase
public function testParseValidAuthorStringWithoutEmail(): void public function testParseValidAuthorStringWithoutEmail(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString('John Smith'); $author = $this->callParseAuthorString($command, 'John Smith');
$this->assertEquals('John Smith', $author['name']); $this->assertEquals('John Smith', $author['name']);
$this->assertNull($author['email']); $this->assertNull($author['email']);
} }
@ -36,7 +36,7 @@ class InitCommandTest extends TestCase
public function testParseValidUtf8AuthorString(): void public function testParseValidUtf8AuthorString(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString('Matti Meikäläinen <matti@example.com>'); $author = $this->callParseAuthorString($command, 'Matti Meikäläinen <matti@example.com>');
$this->assertEquals('Matti Meikäläinen', $author['name']); $this->assertEquals('Matti Meikäläinen', $author['name']);
$this->assertEquals('matti@example.com', $author['email']); $this->assertEquals('matti@example.com', $author['email']);
} }
@ -46,7 +46,7 @@ class InitCommandTest extends TestCase
// \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark // \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark
$utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen"; $utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen";
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString($utf8_expected." <matti@example.com>"); $author = $this->callParseAuthorString($command, $utf8_expected." <matti@example.com>");
$this->assertEquals($utf8_expected, $author['name']); $this->assertEquals($utf8_expected, $author['name']);
$this->assertEquals('matti@example.com', $author['email']); $this->assertEquals('matti@example.com', $author['email']);
} }
@ -54,7 +54,7 @@ class InitCommandTest extends TestCase
public function testParseNumericAuthorString(): void public function testParseNumericAuthorString(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString('h4x0r <h4x@example.com>'); $author = $this->callParseAuthorString($command, 'h4x0r <h4x@example.com>');
$this->assertEquals('h4x0r', $author['name']); $this->assertEquals('h4x0r', $author['name']);
$this->assertEquals('h4x@example.com', $author['email']); $this->assertEquals('h4x@example.com', $author['email']);
} }
@ -66,7 +66,7 @@ class InitCommandTest extends TestCase
public function testParseValidAlias1AuthorString(): void public function testParseValidAlias1AuthorString(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString( $author = $this->callParseAuthorString($command,
'Johnathon "Johnny" Smith <john@example.com>' 'Johnathon "Johnny" Smith <john@example.com>'
); );
$this->assertEquals('Johnathon "Johnny" Smith', $author['name']); $this->assertEquals('Johnathon "Johnny" Smith', $author['name']);
@ -80,7 +80,7 @@ class InitCommandTest extends TestCase
public function testParseValidAlias2AuthorString(): void public function testParseValidAlias2AuthorString(): void
{ {
$command = new InitCommand; $command = new InitCommand;
$author = $command->parseAuthorString( $author = $this->callParseAuthorString($command,
'Johnathon (Johnny) Smith <john@example.com>' 'Johnathon (Johnny) Smith <john@example.com>'
); );
$this->assertEquals('Johnathon (Johnny) Smith', $author['name']); $this->assertEquals('Johnathon (Johnny) Smith', $author['name']);
@ -91,14 +91,14 @@ class InitCommandTest extends TestCase
{ {
$command = new InitCommand; $command = new InitCommand;
self::expectException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$command->parseAuthorString(''); $this->callParseAuthorString($command, '');
} }
public function testParseAuthorStringWithInvalidEmail(): void public function testParseAuthorStringWithInvalidEmail(): void
{ {
$command = new InitCommand; $command = new InitCommand;
self::expectException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$command->parseAuthorString('John Smith <john>'); $this->callParseAuthorString($command, 'John Smith <john>');
} }
public function testNamespaceFromValidPackageName(): void public function testNamespaceFromValidPackageName(): void
@ -121,4 +121,15 @@ class InitCommandTest extends TestCase
$namespace = $command->namespaceFromPackageName(''); $namespace = $command->namespaceFromPackageName('');
$this->assertNull($namespace); $this->assertNull($namespace);
} }
/**
* @return array{name: string, email: string|null}
*/
private function callParseAuthorString(InitCommand $command, string $string): array
{
$reflMethod = new \ReflectionMethod($command, 'parseAuthorString');
$reflMethod->setAccessible(true);
return $reflMethod->invoke($command, $string);
}
} }

View File

@ -223,7 +223,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -273,7 +274,8 @@ class DownloadManagerTest extends TestCase
$downloaderSuccess $downloaderSuccess
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -330,7 +332,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -366,7 +369,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -432,7 +436,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -469,7 +474,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -506,7 +512,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -567,7 +574,8 @@ class DownloadManagerTest extends TestCase
$zipDownloader $zipDownloader
->expects($this->once()) ->expects($this->once())
->method('update') ->method('update')
->with($initial, $target, 'vendor/bundles/FOS/UserBundle'); ->with($initial, $target, 'vendor/bundles/FOS/UserBundle')
->will($this->returnValue(\React\Promise\resolve()));
$zipDownloader $zipDownloader
->expects($this->any()) ->expects($this->any())
->method('getInstallationSource') ->method('getInstallationSource')
@ -605,7 +613,8 @@ class DownloadManagerTest extends TestCase
$xzDownloader $xzDownloader
->expects($this->once()) ->expects($this->once())
->method('remove') ->method('remove')
->with($initial, 'vendor/bundles/FOS/UserBundle'); ->with($initial, 'vendor/bundles/FOS/UserBundle')
->will($this->returnValue(\React\Promise\resolve()));
$xzDownloader $xzDownloader
->expects($this->any()) ->expects($this->any())
->method('getInstallationSource') ->method('getInstallationSource')
@ -615,7 +624,8 @@ class DownloadManagerTest extends TestCase
$zipDownloader $zipDownloader
->expects($this->once()) ->expects($this->once())
->method('install') ->method('install')
->with($target, 'vendor/bundles/FOS/UserBundle'); ->with($target, 'vendor/bundles/FOS/UserBundle')
->will($this->returnValue(\React\Promise\resolve()));
$zipDownloader $zipDownloader
->expects($this->any()) ->expects($this->any())
->method('getInstallationSource') ->method('getInstallationSource')
@ -775,7 +785,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -818,7 +829,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -864,7 +876,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -911,7 +924,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -958,7 +972,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -1005,7 +1020,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -1048,7 +1064,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
@ -1091,7 +1108,8 @@ class DownloadManagerTest extends TestCase
$downloader $downloader
->expects($this->once()) ->expects($this->once())
->method('download') ->method('download')
->with($package, 'target_dir'); ->with($package, 'target_dir')
->will($this->returnValue(\React\Promise\resolve()));
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))

View File

@ -335,7 +335,7 @@ class ZipDownloaderTest extends TestCase
class MockedZipDownloader extends ZipDownloader class MockedZipDownloader extends ZipDownloader
{ {
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true): ?PromiseInterface public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true): PromiseInterface
{ {
return \React\Promise\resolve(); return \React\Promise\resolve();
} }
@ -345,7 +345,7 @@ class MockedZipDownloader extends ZipDownloader
return \React\Promise\resolve(); return \React\Promise\resolve();
} }
public function extract(PackageInterface $package, $file, $path): ?PromiseInterface public function extract(PackageInterface $package, $file, $path): PromiseInterface
{ {
return parent::extract($package, $file, $path); return parent::extract($package, $file, $path);
} }

View File

@ -151,7 +151,8 @@ class LibraryInstallerTest extends TestCase
$this->dm $this->dm
->expects($this->once()) ->expects($this->once())
->method('install') ->method('install')
->with($package, $this->vendorDir.'/some/package'); ->with($package, $this->vendorDir.'/some/package')
->will($this->returnValue(\React\Promise\resolve()));
$this->repository $this->repository
->expects($this->once()) ->expects($this->once())
@ -190,7 +191,8 @@ class LibraryInstallerTest extends TestCase
$this->dm $this->dm
->expects($this->once()) ->expects($this->once())
->method('update') ->method('update')
->with($initial, $target, $this->vendorDir.'/vendor/package1/newtarget'); ->with($initial, $target, $this->vendorDir.'/vendor/package1/newtarget')
->will($this->returnValue(\React\Promise\resolve()));
$this->repository $this->repository
->expects($this->once()) ->expects($this->once())
@ -226,7 +228,8 @@ class LibraryInstallerTest extends TestCase
$this->dm $this->dm
->expects($this->once()) ->expects($this->once())
->method('remove') ->method('remove')
->with($package, $this->vendorDir.'/vendor/pkg'); ->with($package, $this->vendorDir.'/vendor/pkg')
->will($this->returnValue(\React\Promise\resolve()));
$this->repository $this->repository
->expects($this->once()) ->expects($this->once())

View File

@ -135,7 +135,9 @@ class ProcessExecutorMock extends ProcessExecutor
$this->captureOutput = func_num_args() > 3; $this->captureOutput = func_num_args() > 3;
$this->errorOutput = ''; $this->errorOutput = '';
$callback = is_callable($output) ? $output : array($this, 'outputHandler'); $callback = is_callable($output) ? $output : function (string $type, string $buffer): void {
$this->outputHandler($type, $buffer);
};
$commandString = is_array($command) ? implode(' ', $command) : $command; $commandString = is_array($command) ? implode(' ', $command) : $command;
$this->log[] = $commandString; $this->log[] = $commandString;

View File

@ -23,32 +23,21 @@ class ArrayDumperTest extends TestCase
* @var ArrayDumper * @var ArrayDumper
*/ */
private $dumper; private $dumper;
/**
* @var \Composer\Package\CompletePackageInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $package;
public function setUp(): void public function setUp(): void
{ {
$this->dumper = new ArrayDumper(); $this->dumper = new ArrayDumper();
$this->package = $this->getMockBuilder('Composer\Package\CompletePackageInterface')->getMock();
$this->packageExpects('getTransportOptions', array());
} }
public function testRequiredInformation(): void public function testRequiredInformation(): void
{ {
$this $config = $this->dumper->dump($this->getPackage());
->packageExpects('getPrettyName', 'foo')
->packageExpects('getPrettyVersion', '1.0')
->packageExpects('getVersion', '1.0.0.0')
;
$config = $this->dumper->dump($this->package);
$this->assertEquals( $this->assertEquals(
array( array(
'name' => 'foo', 'name' => 'dummy/pkg',
'version' => '1.0', 'version' => '1.0.0',
'version_normalized' => '1.0.0.0', 'version_normalized' => '1.0.0.0',
'type' => 'library',
), ),
$config $config
); );
@ -56,33 +45,27 @@ class ArrayDumperTest extends TestCase
public function testRootPackage(): void public function testRootPackage(): void
{ {
$this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock(); $package = $this->getRootPackage();
$package->setMinimumStability('dev');
$this $config = $this->dumper->dump($package);
->packageExpects('getMinimumStability', 'dev')
->packageExpects('getTransportOptions', array())
;
$config = $this->dumper->dump($this->package);
$this->assertSame('dev', $config['minimum-stability']); $this->assertSame('dev', $config['minimum-stability']);
} }
public function testDumpAbandoned(): void public function testDumpAbandoned(): void
{ {
$this->packageExpects('isAbandoned', true); $package = $this->getPackage();
$this->packageExpects('getReplacementPackage', true); $package->setAbandoned(true);
$config = $this->dumper->dump($package);
$config = $this->dumper->dump($this->package);
$this->assertTrue($config['abandoned']); $this->assertTrue($config['abandoned']);
} }
public function testDumpAbandonedReplacement(): void public function testDumpAbandonedReplacement(): void
{ {
$this->packageExpects('isAbandoned', true); $package = $this->getPackage();
$this->packageExpects('getReplacementPackage', 'foo/bar'); $package->setAbandoned('foo/bar');
$config = $this->dumper->dump($package);
$config = $this->dumper->dump($this->package);
$this->assertSame('foo/bar', $config['abandoned']); $this->assertSame('foo/bar', $config['abandoned']);
} }
@ -97,16 +80,12 @@ class ArrayDumperTest extends TestCase
*/ */
public function testKeys(string $key, $value, string $method = null, $expectedValue = null): void public function testKeys(string $key, $value, string $method = null, $expectedValue = null): void
{ {
$this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock(); $package = $this->getRootPackage();
$this->packageExpects('get'.ucfirst($method ?: $key), $value); // @phpstan-ignore-next-line
$this->packageExpects('isAbandoned', $value); $package->{'set'.ucfirst($method ?: $key)}($value);
if ($method !== 'transportOptions') { $config = $this->dumper->dump($package);
$this->packageExpects('getTransportOptions', array());
}
$config = $this->dumper->dump($this->package);
$this->assertSame($expectedValue ?: $value, $config[$key]); $this->assertSame($expectedValue ?: $value, $config[$key]);
} }
@ -177,13 +156,13 @@ class ArrayDumperTest extends TestCase
), ),
array( array(
'require', 'require',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array('foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')),
'requires', 'requires',
array('foo/bar' => '1.0.0'), array('foo/bar' => '1.0.0'),
), ),
array( array(
'require-dev', 'require-dev',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_DEV_REQUIRE, '1.0.0')), array('foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_DEV_REQUIRE, '1.0.0')),
'devRequires', 'devRequires',
array('foo/bar' => '1.0.0'), array('foo/bar' => '1.0.0'),
), ),
@ -202,13 +181,19 @@ class ArrayDumperTest extends TestCase
), ),
array( array(
'require', 'require',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array(
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
),
'requires', 'requires',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
), ),
array( array(
'require-dev', 'require-dev',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array(
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
),
'devRequires', 'devRequires',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
), ),
@ -220,19 +205,28 @@ class ArrayDumperTest extends TestCase
), ),
array( array(
'provide', 'provide',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array(
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
),
'provides', 'provides',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
), ),
array( array(
'replace', 'replace',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array(
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
),
'replaces', 'replaces',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
), ),
array( array(
'conflict', 'conflict',
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')), array(
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
),
'conflicts', 'conflicts',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
), ),
@ -243,18 +237,4 @@ class ArrayDumperTest extends TestCase
), ),
); );
} }
/**
* @param string $method
* @param mixed $value
*/
private function packageExpects(string $method, $value): ArrayDumperTest
{
$this->package
->expects($this->any())
->method($method)
->will($this->returnValue($value));
return $this;
}
} }

View File

@ -93,41 +93,8 @@ class LockerTest extends TestCase
$jsonContent = $this->getJsonContent() . ' '; $jsonContent = $this->getJsonContent() . ' ';
$locker = new Locker(new NullIO, $json, $inst, $jsonContent); $locker = new Locker(new NullIO, $json, $inst, $jsonContent);
$package1 = $this->createPackageMock(); $package1 = $this->getPackage('pkg1', '1.0.0-beta');
$package2 = $this->createPackageMock(); $package2 = $this->getPackage('pkg2', '0.1.10');
$package1
->expects($this->atLeastOnce())
->method('getPrettyName')
->will($this->returnValue('pkg1'));
$package1
->expects($this->atLeastOnce())
->method('getPrettyVersion')
->will($this->returnValue('1.0.0-beta'));
$package1
->expects($this->atLeastOnce())
->method('getVersion')
->will($this->returnValue('1.0.0.0-beta'));
$package2
->expects($this->atLeastOnce())
->method('getPrettyName')
->will($this->returnValue('pkg2'));
$package2
->expects($this->atLeastOnce())
->method('getPrettyVersion')
->will($this->returnValue('0.1.10'));
$package2
->expects($this->atLeastOnce())
->method('getVersion')
->will($this->returnValue('0.1.10.0'));
foreach (array($package1, $package2) as $package) {
$package
->expects($this->atLeastOnce())
->method('getTransportOptions')
->will($this->returnValue(array()));
}
$contentHash = md5(trim($jsonContent)); $contentHash = md5(trim($jsonContent));
@ -140,8 +107,8 @@ class LockerTest extends TestCase
'This file is @gener'.'ated automatically', ), 'This file is @gener'.'ated automatically', ),
'content-hash' => $contentHash, 'content-hash' => $contentHash,
'packages' => array( 'packages' => array(
array('name' => 'pkg1', 'version' => '1.0.0-beta'), array('name' => 'pkg1', 'version' => '1.0.0-beta', 'type' => 'library'),
array('name' => 'pkg2', 'version' => '0.1.10'), array('name' => 'pkg2', 'version' => '0.1.10', 'type' => 'library'),
), ),
'packages-dev' => array(), 'packages-dev' => array(),
'aliases' => array(), 'aliases' => array(),

View File

@ -83,6 +83,15 @@ class PluginInstallerTest extends TestCase
$dm = $this->getMockBuilder('Composer\Downloader\DownloadManager') $dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$dm->expects($this->any())
->method('install')
->will($this->returnValue(\React\Promise\resolve()));
$dm->expects($this->any())
->method('update')
->will($this->returnValue(\React\Promise\resolve()));
$dm->expects($this->any())
->method('remove')
->will($this->returnValue(\React\Promise\resolve()));
$this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock(); $this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();

View File

@ -193,6 +193,7 @@ class GitHubDriverTest extends TestCase
$data = $gitHubDriver->getComposerInformation($identifier); $data = $gitHubDriver->getComposerInformation($identifier);
$this->assertIsArray($data);
$this->assertArrayNotHasKey('abandoned', $data); $this->assertArrayNotHasKey('abandoned', $data);
} }
@ -230,6 +231,7 @@ class GitHubDriverTest extends TestCase
$data = $gitHubDriver->getComposerInformation($sha); $data = $gitHubDriver->getComposerInformation($sha);
$this->assertIsArray($data);
$this->assertTrue($data['abandoned']); $this->assertTrue($data['abandoned']);
} }

View File

@ -377,8 +377,7 @@ class AuthHelperTest extends TestCase
$configSource->expects($this->once()) $configSource->expects($this->once())
->method('addConfigSetting') ->method('addConfigSetting')
->with('http-basic.'.$origin, $auth) ->with('http-basic.'.$origin, $auth);
->willReturn($configSource);
$this->authHelper->storeAuth($origin, $storeAuth); $this->authHelper->storeAuth($origin, $storeAuth);
} }
@ -429,8 +428,7 @@ class AuthHelperTest extends TestCase
$configSource->expects($this->once()) $configSource->expects($this->once())
->method('addConfigSetting') ->method('addConfigSetting')
->with('http-basic.'.$origin, $auth) ->with('http-basic.'.$origin, $auth);
->willReturn($configSource);
$this->authHelper->storeAuth($origin, $storeAuth); $this->authHelper->storeAuth($origin, $storeAuth);
} }