diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index dc4166e058d9..8ed6ed0f46cc 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -52,7 +52,7 @@ class DiagnoseCommand extends BaseCommand /** * @return void */ - protected function configure() + protected function configure(): void { $this ->setName('diagnose') diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 896e45dca12e..4f3cebbd838f 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -456,11 +456,10 @@ function ($value) use ($autoload) { } /** - * @private * @param string $author * @return array{name: string, email: string|null} */ - public function parseAuthorString(string $author) + private function parseAuthorString(string $author) { if (Preg::isMatch('/^(?P[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?:\s+<(?P.+?)>)?$/u', $author, $match)) { $hasEmail = isset($match['email']) && '' !== $match['email']; @@ -485,7 +484,7 @@ public function parseAuthorString(string $author) * * @return array */ - protected function formatAuthors(string $author) + protected function formatAuthors(string $author): array { $author = $this->parseAuthorString($author); if (null === $author['email']) { @@ -504,7 +503,7 @@ protected function formatAuthors(string $author) * * @return string|null */ - public function namespaceFromPackageName(string $packageName) + public function namespaceFromPackageName(string $packageName): ?string { if (!$packageName || strpos($packageName, '/') === false) { return null; @@ -526,7 +525,7 @@ function ($part): string { /** * @return array */ - protected function getGitConfig() + protected function getGitConfig(): array { if (null !== $this->gitConfig) { return $this->gitConfig; @@ -567,7 +566,7 @@ protected function getGitConfig() * * @return bool */ - protected function hasVendorIgnore(string $ignoreFile, string $vendor = 'vendor') + protected function hasVendorIgnore(string $ignoreFile, string $vendor = 'vendor'): bool { if (!file_exists($ignoreFile)) { return false; @@ -591,7 +590,7 @@ protected function hasVendorIgnore(string $ignoreFile, string $vendor = 'vendor' * * @return void */ - protected function addVendorIgnore(string $ignoreFile, string $vendor = '/vendor/') + protected function addVendorIgnore(string $ignoreFile, string $vendor = '/vendor/'): void { $contents = ""; if (file_exists($ignoreFile)) { @@ -610,7 +609,7 @@ protected function addVendorIgnore(string $ignoreFile, string $vendor = '/vendor * * @return bool */ - protected function isValidEmail(string $email) + protected function isValidEmail(string $email): bool { // assume it's valid if we can't validate it if (!function_exists('filter_var')) { diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 5aa890f0267b..5a65ccec91eb 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -335,15 +335,6 @@ private function getPackagesByRequireKey(): array ); } - /** - * @private - * @return void - */ - public function markSolverComplete() - { - $this->dependencyResolutionCompleted = true; - } - /** * @param array $requirements * @param string $requireKey @@ -358,7 +349,9 @@ private function doUpdate(InputInterface $input, OutputInterface $output, IOInte $composer = $this->requireComposer(); $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')) { $rootPackage = $composer->getPackage(); @@ -480,7 +473,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi * @param bool $hardExit * @return void */ - public function revertComposerFile(bool $hardExit = true) + public function revertComposerFile(bool $hardExit = true): void { $io = $this->getIO(); diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 36fb376dd853..775d858e934e 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -602,7 +602,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * @return string[] */ - protected function getRootRequires() + protected function getRootRequires(): array { $rootPackage = $this->requireComposer()->getPackage(); @@ -677,7 +677,7 @@ protected function getPackage(InstalledRepository $installedRepo, RepositoryInte * * @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(); @@ -705,7 +705,7 @@ protected function printPackageInfo(CompletePackageInterface $package, array $ve * * @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->write('name : ' . $package->getPrettyName()); @@ -773,7 +773,7 @@ protected function printMeta(CompletePackageInterface $package, array $versions, * * @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 = Semver::rsort($versions); @@ -802,7 +802,7 @@ protected function printVersions(CompletePackageInterface $package, array $versi * * @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; $io = $this->getIO(); @@ -820,7 +820,7 @@ protected function printLinks(CompletePackageInterface $package, string $linkTyp * * @return void */ - protected function printLicenses(CompletePackageInterface $package) + protected function printLicenses(CompletePackageInterface $package): void { $spdxLicenses = new SpdxLicenses(); @@ -852,7 +852,7 @@ protected function printLicenses(CompletePackageInterface $package) * * @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( 'name' => $package->getPrettyName(), @@ -1030,7 +1030,7 @@ private function appendLink(array $json, CompletePackageInterface $package, stri * * @return void */ - protected function initStyles(OutputInterface $output) + protected function initStyles(OutputInterface $output): void { $this->colors = array( 'green', @@ -1052,7 +1052,7 @@ protected function initStyles(OutputInterface $output) * @param array> $arrayTree * @return void */ - protected function displayPackageTree(array $arrayTree) + protected function displayPackageTree(array $arrayTree): void { $io = $this->getIO(); foreach ($arrayTree as $package) { @@ -1101,7 +1101,7 @@ protected function generatePackageTree( PackageInterface $package, InstalledRepository $installedRepo, RepositoryInterface $remoteRepos - ) { + ): array { $requires = $package->getRequires(); ksort($requires); $children = array(); @@ -1149,7 +1149,7 @@ protected function displayTree( array $packagesInTree, string $previousTreeBar = '├', int $level = 1 - ) { + ): void { $previousTreeBar = str_replace('├', '│', $previousTreeBar); if (is_array($package) && isset($package['requires'])) { $requires = $package['requires']; @@ -1202,7 +1202,7 @@ protected function addTree( InstalledRepository $installedRepo, RepositoryInterface $remoteRepos, array $packagesInTree - ) { + ): array { $children = array(); list($package) = $this->getPackage( $installedRepo, diff --git a/src/Composer/Config/ConfigSourceInterface.php b/src/Composer/Config/ConfigSourceInterface.php index 206f8158c4b7..7cb590de67f7 100644 --- a/src/Composer/Config/ConfigSourceInterface.php +++ b/src/Composer/Config/ConfigSourceInterface.php @@ -29,7 +29,7 @@ interface ConfigSourceInterface * * @return void */ - public function addRepository(string $name, $config, bool $append = true); + public function addRepository(string $name, $config, bool $append = true): void; /** * Remove a repository @@ -38,7 +38,7 @@ public function addRepository(string $name, $config, bool $append = true); * * @return void */ - public function removeRepository(string $name); + public function removeRepository(string $name): void; /** * Add a config setting @@ -48,7 +48,7 @@ public function removeRepository(string $name); * * @return void */ - public function addConfigSetting(string $name, $value); + public function addConfigSetting(string $name, $value): void; /** * Remove a config setting @@ -57,7 +57,7 @@ public function addConfigSetting(string $name, $value); * * @return void */ - public function removeConfigSetting(string $name); + public function removeConfigSetting(string $name): void; /** * Add a property @@ -67,7 +67,7 @@ public function removeConfigSetting(string $name); * * @return void */ - public function addProperty(string $name, $value); + public function addProperty(string $name, $value): void; /** * Remove a property @@ -76,7 +76,7 @@ public function addProperty(string $name, $value); * * @return void */ - public function removeProperty(string $name); + public function removeProperty(string $name): void; /** * Add a package link @@ -87,7 +87,7 @@ public function removeProperty(string $name); * * @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 @@ -97,12 +97,12 @@ public function addLink(string $type, string $name, string $value); * * @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) * * @return string */ - public function getName(); + public function getName(): string; } diff --git a/src/Composer/Config/JsonConfigSource.php b/src/Composer/Config/JsonConfigSource.php index a70471997118..cb04bc6e9a4c 100644 --- a/src/Composer/Config/JsonConfigSource.php +++ b/src/Composer/Config/JsonConfigSource.php @@ -52,7 +52,7 @@ public function __construct(JsonFile $file, bool $authConfig = false) /** * @inheritDoc */ - public function getName() + public function getName(): string { return $this->file->getPath(); } @@ -60,7 +60,7 @@ public function getName() /** * @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 { // if converting from an array format to hashmap format, and there is a {"packagist.org":false} repo, we have @@ -89,7 +89,7 @@ public function addRepository($name, $config, $append = true) /** * @inheritDoc */ - public function removeRepository($name) + public function removeRepository(string $name): void { $this->manipulateJson('removeRepository', function (&$config, $repo): void { unset($config['repositories'][$repo]); @@ -99,7 +99,7 @@ public function removeRepository($name) /** * @inheritDoc */ - public function addConfigSetting($name, $value) + public function addConfigSetting(string $name, $value): void { $authConfig = $this->authConfig; $this->manipulateJson('addConfigSetting', function (&$config, $key, $val) use ($authConfig): void { @@ -119,7 +119,7 @@ public function addConfigSetting($name, $value) /** * @inheritDoc */ - public function removeConfigSetting($name) + public function removeConfigSetting(string $name): void { $authConfig = $this->authConfig; $this->manipulateJson('removeConfigSetting', function (&$config, $key) use ($authConfig): void { @@ -139,7 +139,7 @@ public function removeConfigSetting($name) /** * @inheritDoc */ - public function addProperty($name, $value) + public function addProperty(string $name, $value): void { $this->manipulateJson('addProperty', function (&$config, $key, $val): void { if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) { @@ -162,7 +162,7 @@ public function addProperty($name, $value) /** * @inheritDoc */ - public function removeProperty($name) + public function removeProperty(string $name): void { $this->manipulateJson('removeProperty', function (&$config, $key): void { if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) { @@ -185,7 +185,7 @@ public function removeProperty($name) /** * @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 { $config[$type][$name] = $value; @@ -195,7 +195,7 @@ public function addLink($type, $name, $value) /** * @inheritDoc */ - public function removeLink($type, $name) + public function removeLink(string $type, string $name): void { $this->manipulateJson('removeSubNode', function (&$config, $type, $name): void { unset($config[$type][$name]); diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 9560eef574d4..f2fac34fceed 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -423,9 +423,9 @@ private function hintCommonErrors(\Exception $exception): void * @param bool|null $disableScripts * @throws JsonValidationException * @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) { $disablePlugins = $this->disablePluginsByDefault; @@ -460,7 +460,7 @@ public function getComposer(bool $required = true, ?bool $disablePlugins = null, * * @return void */ - public function resetComposer() + public function resetComposer(): void { $this->composer = null; if (method_exists($this->getIO(), 'resetAuthentications')) { @@ -471,7 +471,7 @@ public function resetComposer() /** * @return IOInterface */ - public function getIO() + public function getIO(): IOInterface { return $this->io; } diff --git a/src/Composer/DependencyResolver/Operation/InstallOperation.php b/src/Composer/DependencyResolver/Operation/InstallOperation.php index 40d0e698d752..7f66d17e9c4b 100644 --- a/src/Composer/DependencyResolver/Operation/InstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/InstallOperation.php @@ -38,7 +38,7 @@ public function __construct(PackageInterface $package) * * @return PackageInterface */ - public function getPackage() + public function getPackage(): PackageInterface { return $this->package; } @@ -46,7 +46,7 @@ public function getPackage() /** * @inheritDoc */ - public function show($lock) + public function show($lock): string { return self::format($this->package, $lock); } @@ -55,7 +55,7 @@ public function show($lock) * @param bool $lock * @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 ').''.$package->getPrettyName().' ('.$package->getFullPrettyVersion().')'; } diff --git a/src/Composer/DependencyResolver/Operation/SolverOperation.php b/src/Composer/DependencyResolver/Operation/SolverOperation.php index ad8855d2c4f3..5aa0957a75d0 100644 --- a/src/Composer/DependencyResolver/Operation/SolverOperation.php +++ b/src/Composer/DependencyResolver/Operation/SolverOperation.php @@ -26,7 +26,7 @@ abstract class SolverOperation implements OperationInterface * * @return string */ - public function getOperationType() + public function getOperationType(): string { return static::TYPE; } diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index b44d280b59bd..fc19004143bc 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -33,9 +33,9 @@ abstract class ArchiveDownloader extends FileDownloader 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()]); @@ -43,9 +43,9 @@ public function prepare(string $type, PackageInterface $package, string $path, P } /** - * @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; @@ -62,7 +62,7 @@ public function cleanup(string $type, PackageInterface $package, string $path, P * @throws \RuntimeException * @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) { $this->io->writeError(" - " . InstallOperation::format($package) . $this->getInstallOperationAppendix($package, $path)); @@ -113,10 +113,6 @@ public function install(PackageInterface $package, string $path, bool $output = throw $e; } - if (!$promise instanceof PromiseInterface) { - $promise = \React\Promise\resolve(); - } - return $promise->then(function () use ($package, $filesystem, $fileName, $temporaryDir, $path): \React\Promise\PromiseInterface { $filesystem->unlink($fileName); @@ -215,7 +211,7 @@ public function install(PackageInterface $package, string $path, bool $output = /** * @inheritDoc */ - protected function getInstallOperationAppendix(PackageInterface $package, string $path) + protected function getInstallOperationAppendix(PackageInterface $package, string $path): string { return ': Extracting archive'; } @@ -227,7 +223,6 @@ protected function getInstallOperationAppendix(PackageInterface $package, string * @param string $path Directory * * @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; } diff --git a/src/Composer/Downloader/ChangeReportInterface.php b/src/Composer/Downloader/ChangeReportInterface.php index 60d6efe74ec5..a41cce8939ef 100644 --- a/src/Composer/Downloader/ChangeReportInterface.php +++ b/src/Composer/Downloader/ChangeReportInterface.php @@ -28,5 +28,5 @@ interface ChangeReportInterface * @param string $path package directory * @return string|null changes or null */ - public function getLocalChanges(PackageInterface $package, string $path); + public function getLocalChanges(PackageInterface $package, string $path): ?string; } diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index da786378a469..f34a73d379cf 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -59,7 +59,7 @@ public function __construct(IOInterface $io, bool $preferSource = false, Filesys * @param bool $preferSource prefer downloading from source * @return DownloadManager */ - public function setPreferSource(bool $preferSource): DownloadManager + public function setPreferSource(bool $preferSource): self { $this->preferSource = $preferSource; @@ -72,7 +72,7 @@ public function setPreferSource(bool $preferSource): DownloadManager * @param bool $preferDist prefer downloading from dist * @return DownloadManager */ - public function setPreferDist(bool $preferDist): DownloadManager + public function setPreferDist(bool $preferDist): self { $this->preferDist = $preferDist; @@ -86,7 +86,7 @@ public function setPreferDist(bool $preferDist): DownloadManager * * @return DownloadManager */ - public function setPreferences(array $preferences): DownloadManager + public function setPreferences(array $preferences): self { $this->packagePreferences = $preferences; @@ -100,7 +100,7 @@ public function setPreferences(array $preferences): DownloadManager * @param DownloaderInterface $downloader downloader instance * @return DownloadManager */ - public function setDownloader(string $type, DownloaderInterface $downloader): DownloadManager + public function setDownloader(string $type, DownloaderInterface $downloader): self { $type = strtolower($type); $this->downloaders[$type] = $downloader; @@ -229,9 +229,6 @@ public function download(PackageInterface $package, string $targetDir, PackageIn } catch (\Exception $e) { return $handleError($e); } - if (!$result instanceof PromiseInterface) { - return \React\Promise\resolve($result); - } $res = $result->then(function ($res) { return $res; @@ -251,9 +248,9 @@ public function download(PackageInterface $package, string $targetDir, PackageIn * @param string $targetDir target dir * @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); $downloader = $this->getDownloaderForPackage($package); @@ -272,9 +269,9 @@ public function prepare(string $type, PackageInterface $package, string $targetD * * @throws \InvalidArgumentException if package have no urls to download from * @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); $downloader = $this->getDownloaderForPackage($package); @@ -293,9 +290,9 @@ public function install(PackageInterface $package, string $targetDir): ?PromiseI * @param string $targetDir target dir * * @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); $downloader = $this->getDownloaderForPackage($target); @@ -330,18 +327,10 @@ public function update(PackageInterface $initial, PackageInterface $target, stri // 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 $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 $this->install($target, $targetDir); + return $promise->then(function ($res) use ($target, $targetDir): PromiseInterface { + return $this->install($target, $targetDir); + }); } /** @@ -350,9 +339,9 @@ public function update(PackageInterface $initial, PackageInterface $target, stri * @param PackageInterface $package package instance * @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); $downloader = $this->getDownloaderForPackage($package); @@ -371,9 +360,9 @@ public function remove(PackageInterface $package, string $targetDir): ?PromiseIn * @param string $targetDir target dir * @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); $downloader = $this->getDownloaderForPackage($package); diff --git a/src/Composer/Downloader/DownloaderInterface.php b/src/Composer/Downloader/DownloaderInterface.php index 1796754a3e92..0b540d4b65b6 100644 --- a/src/Composer/Downloader/DownloaderInterface.php +++ b/src/Composer/Downloader/DownloaderInterface.php @@ -28,15 +28,15 @@ interface DownloaderInterface * * @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 * * @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 @@ -50,18 +50,18 @@ public function download(PackageInterface $package, string $path, PackageInterfa * @param PackageInterface $package package instance * @param string $path download path * @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. * * @param PackageInterface $package package instance * @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. @@ -69,18 +69,18 @@ public function install(PackageInterface $package, string $path); * @param PackageInterface $initial initial package * @param PackageInterface $target updated package * @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. * * @param PackageInterface $package package instance * @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 @@ -93,7 +93,7 @@ public function remove(PackageInterface $package, string $path); * @param PackageInterface $package package instance * @param string $path download path * @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; } diff --git a/src/Composer/Downloader/DvcsDownloaderInterface.php b/src/Composer/Downloader/DvcsDownloaderInterface.php index 8f70472b7a64..45c9b86c5ce5 100644 --- a/src/Composer/Downloader/DvcsDownloaderInterface.php +++ b/src/Composer/Downloader/DvcsDownloaderInterface.php @@ -28,5 +28,5 @@ interface DvcsDownloaderInterface * @param string $path package directory * @return string|null changes or null */ - public function getUnpushedChanges(PackageInterface $package, string $path); + public function getUnpushedChanges(PackageInterface $package, string $path): ?string; } diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index c871ee47f9b5..c1858d9b8985 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -66,11 +66,9 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface public static $downloadMetadata = array(); /** - * @private this is only public for php 5.3 support in closures - * * @var array Map of package name to cache key */ - public $lastCacheWrites = array(); + private $lastCacheWrites = array(); /** @var array Map of package name to list of paths */ private $additionalCleanupPaths = array(); @@ -103,7 +101,7 @@ public function __construct(IOInterface $io, Config $config, HttpDownloader $htt /** * @inheritDoc */ - public function getInstallationSource() + public function getInstallationSource(): string { return 'dist'; } @@ -113,7 +111,7 @@ public function getInstallationSource() * * @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()) { throw new \InvalidArgumentException('The given package is missing url information'); @@ -296,7 +294,7 @@ public function download(PackageInterface $package, string $path, PackageInterfa /** * @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(); } @@ -304,7 +302,7 @@ public function prepare(string $type, PackageInterface $package, string $path, P /** * @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); if (file_exists($fileName)) { @@ -337,7 +335,7 @@ public function cleanup(string $type, PackageInterface $package, string $path, P * * @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) { $this->io->writeError(" - " . InstallOperation::format($package)); @@ -363,7 +361,7 @@ public function install(PackageInterface $package, string $path, bool $output = /** * @return void */ - protected function clearLastCacheWrite(PackageInterface $package) + protected function clearLastCacheWrite(PackageInterface $package): void { if ($this->cache && isset($this->lastCacheWrites[$package->getName()])) { $this->cache->remove($this->lastCacheWrites[$package->getName()]); @@ -376,7 +374,7 @@ protected function clearLastCacheWrite(PackageInterface $package) * * @return void */ - protected function addCleanupPath(PackageInterface $package, string $path) + protected function addCleanupPath(PackageInterface $package, string $path): void { $this->additionalCleanupPaths[$package->getName()][] = $path; } @@ -386,7 +384,7 @@ protected function addCleanupPath(PackageInterface $package, string $path) * * @return void */ - protected function removeCleanupPath(PackageInterface $package, string $path) + protected function removeCleanupPath(PackageInterface $package, string $path): void { if (isset($this->additionalCleanupPaths[$package->getName()])) { $idx = array_search($path, $this->additionalCleanupPaths[$package->getName()]); @@ -399,22 +397,14 @@ protected function removeCleanupPath(PackageInterface $package, string $path) /** * @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)); $promise = $this->remove($initial, $path, false); - if (!$promise instanceof PromiseInterface) { - $promise = \React\Promise\resolve(); - } return $promise->then(function () use ($target, $path): PromiseInterface { - $promise = $this->install($target, $path, false); - if ($promise instanceof PromiseInterface) { - return $promise; - } - - return \React\Promise\resolve(); + return $this->install($target, $path, false); }); } @@ -423,7 +413,7 @@ public function update(PackageInterface $initial, PackageInterface $target, stri * * @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) { $this->io->writeError(" - " . UninstallOperation::format($package)); @@ -444,7 +434,7 @@ public function remove(PackageInterface $package, string $path, bool $output = t * @param string $path download path * @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), '.'); } @@ -456,7 +446,7 @@ protected function getFileName(PackageInterface $package, string $path) * @param string $path download path * @return string */ - protected function getInstallOperationAppendix(PackageInterface $package, string $path) + protected function getInstallOperationAppendix(PackageInterface $package, string $path): string { return ''; } @@ -469,7 +459,7 @@ protected function getInstallOperationAppendix(PackageInterface $package, string * @throws \RuntimeException If any problem with the 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:')) { throw new \RuntimeException('You must enable the openssl extension to download files via https'); @@ -486,7 +476,7 @@ protected function processUrl(PackageInterface $package, string $url) * @inheritDoc * @throws \RuntimeException */ - public function getLocalChanges(PackageInterface $package, string $targetDir) + public function getLocalChanges(PackageInterface $package, string $targetDir): ?string { $prevIO = $this->io; diff --git a/src/Composer/Downloader/FossilDownloader.php b/src/Composer/Downloader/FossilDownloader.php index 57afb1752c08..13bd3d25b7c6 100644 --- a/src/Composer/Downloader/FossilDownloader.php +++ b/src/Composer/Downloader/FossilDownloader.php @@ -25,7 +25,7 @@ class FossilDownloader extends VcsDownloader /** * @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(); } @@ -33,7 +33,7 @@ protected function doDownload(PackageInterface $package, string $path, string $u /** * @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 $this->config->prohibitUrlByConfig($url, $this->io); @@ -61,7 +61,7 @@ protected function doInstall(PackageInterface $package, string $path, string $ur /** * @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 $this->config->prohibitUrlByConfig($url, $this->io); diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 78775e6c3c84..a842a6ea33a2 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -58,7 +58,7 @@ public function __construct(IOInterface $io, Config $config, ProcessExecutor $pr /** * @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(); @@ -83,7 +83,7 @@ protected function doDownload(PackageInterface $package, string $path, string $u /** * @inheritDoc */ - protected function doInstall(PackageInterface $package, string $path, string $url) + protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface { GitUtil::cleanEnv(); $path = $this->normalizePath($path); @@ -148,7 +148,7 @@ protected function doInstall(PackageInterface $package, string $path, string $ur /** * @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(); $path = $this->normalizePath($path); @@ -213,7 +213,7 @@ protected function doUpdate(PackageInterface $initial, PackageInterface $target, /** * @inheritDoc */ - public function getLocalChanges(PackageInterface $package, string $path) + public function getLocalChanges(PackageInterface $package, string $path): ?string { GitUtil::cleanEnv(); if (!$this->hasMetadataRepository($path)) { @@ -231,7 +231,7 @@ public function getLocalChanges(PackageInterface $package, string $path) /** * @return null|string */ - public function getUnpushedChanges(PackageInterface $package, string $path) + public function getUnpushedChanges(PackageInterface $package, string $path): ?string { GitUtil::cleanEnv(); $path = $this->normalizePath($path); @@ -328,7 +328,7 @@ public function getUnpushedChanges(PackageInterface $package, string $path) /** * @inheritDoc */ - protected function cleanChanges(PackageInterface $package, string $path, bool $update) + protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface { GitUtil::cleanEnv(); $path = $this->normalizePath($path); @@ -415,7 +415,7 @@ protected function cleanChanges(PackageInterface $package, string $path, bool $u /** * @inheritDoc */ - protected function reapplyChanges(string $path) + protected function reapplyChanges(string $path): void { $path = $this->normalizePath($path); if (!empty($this->hasStashedChanges[$path])) { @@ -438,7 +438,7 @@ protected function reapplyChanges(string $path) * @throws \RuntimeException * @return null|string if a string is returned, it is the commit reference that was checked out if the original could not be found */ - protected function updateToCommit(PackageInterface $package, 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 ' : ''; @@ -505,7 +505,7 @@ protected function updateToCommit(PackageInterface $package, string $path, strin * * @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->setPushUrl($path, $url); @@ -517,7 +517,7 @@ protected function updateOriginUrl(string $path, string $url) * * @return void */ - protected function setPushUrl(string $path, string $url) + protected function setPushUrl(string $path, string $url): void { // set push url for github projects if (Preg::isMatch('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) { @@ -534,7 +534,7 @@ protected function setPushUrl(string $path, string $url) /** * @inheritDoc */ - protected function getCommitLogs(string $fromReference, string $toReference, string $path) + protected function getCommitLogs(string $fromReference, string $toReference, string $path): string { $path = $this->normalizePath($path); $command = sprintf('git log %s..%s --pretty=format:"%%h - %%an: %%s"'.GitUtil::getNoShowSignatureFlag($this->process), ProcessExecutor::escape($fromReference), ProcessExecutor::escape($toReference)); @@ -553,7 +553,7 @@ protected function getCommitLogs(string $fromReference, string $toReference, str * * @throws \RuntimeException */ - protected function discardChanges(string $path) + protected function discardChanges(string $path): PromiseInterface { $path = $this->normalizePath($path); if (0 !== $this->process->execute('git clean -df && git reset --hard', $output, $path)) { @@ -572,7 +572,7 @@ protected function discardChanges(string $path) * * @throws \RuntimeException */ - protected function stashChanges(string $path) + protected function stashChanges(string $path): PromiseInterface { $path = $this->normalizePath($path); if (0 !== $this->process->execute('git stash --include-untracked', $output, $path)) { @@ -591,7 +591,7 @@ protected function stashChanges(string $path) * * @throws \RuntimeException */ - protected function viewDiff(string $path) + protected function viewDiff(string $path): void { $path = $this->normalizePath($path); if (0 !== $this->process->execute('git diff HEAD', $output, $path)) { @@ -606,7 +606,7 @@ protected function viewDiff(string $path) * * @return string */ - protected function normalizePath(string $path) + protected function normalizePath(string $path): string { if (Platform::isWindows() && strlen($path) > 0) { $basePath = $path; @@ -630,7 +630,7 @@ protected function normalizePath(string $path) /** * @inheritDoc */ - protected function hasMetadataRepository(string $path) + protected function hasMetadataRepository(string $path): bool { $path = $this->normalizePath($path); @@ -641,7 +641,7 @@ protected function hasMetadataRepository(string $path) * @param string $reference * @return string */ - protected function getShortHash(string $reference) + protected function getShortHash(string $reference): string { if (!$this->io->isVerbose() && Preg::isMatch('{^[0-9a-f]{40}$}', $reference)) { return substr($reference, 0, 10); diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php index b66aeb048c20..8949037ec7f5 100644 --- a/src/Composer/Downloader/GzipDownloader.php +++ b/src/Composer/Downloader/GzipDownloader.php @@ -24,7 +24,7 @@ */ 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); $targetFilepath = $path . DIRECTORY_SEPARATOR . $filename; diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index a9caf53a8a23..0537103b1073 100644 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -25,7 +25,7 @@ class HgDownloader extends VcsDownloader /** * @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)) { throw new \RuntimeException('hg was not found in your PATH, skipping source download'); @@ -37,7 +37,7 @@ protected function doDownload(PackageInterface $package, string $path, string $u /** * @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); @@ -59,7 +59,7 @@ protected function doInstall(PackageInterface $package, string $path, string $ur /** * @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); diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index c58e7d67aaa5..c85cbef0f944 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -39,7 +39,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter /** * @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); $url = $package->getDistUrl(); @@ -75,7 +75,7 @@ public function download(PackageInterface $package, string $path, PackageInterfa /** * @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); $url = $package->getDistUrl(); @@ -161,7 +161,7 @@ public function install(PackageInterface $package, string $path, bool $output = /** * @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); /** @@ -250,7 +250,7 @@ protected function getInstallOperationAppendix(PackageInterface $package, string * * @phpstan-return array{self::STRATEGY_*, non-empty-list} */ - private function computeAllowedStrategies(array $transportOptions) + private function computeAllowedStrategies(array $transportOptions): array { // When symlink transport option is null, both symlink and mirror are allowed $currentStrategy = self::STRATEGY_SYMLINK; diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 1f888b6b48ca..559d6ba4a67e 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -28,7 +28,7 @@ class PerforceDownloader extends VcsDownloader /** * @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(); } @@ -36,7 +36,7 @@ protected function doDownload(PackageInterface $package, string $path, string $u /** * @inheritDoc */ - public function doInstall(PackageInterface $package, string $path, string $url): ?PromiseInterface + public function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface { $ref = $package->getSourceReference(); $label = $this->getLabelFromSourceReference((string) $ref); @@ -101,7 +101,7 @@ private function getRepoConfig(VcsRepository $repository): array /** * @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); } diff --git a/src/Composer/Downloader/PharDownloader.php b/src/Composer/Downloader/PharDownloader.php index b4a1d9c75018..76517fcd74a5 100644 --- a/src/Composer/Downloader/PharDownloader.php +++ b/src/Composer/Downloader/PharDownloader.php @@ -25,7 +25,7 @@ class PharDownloader extends ArchiveDownloader /** * @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 $archive = new \Phar($file); diff --git a/src/Composer/Downloader/RarDownloader.php b/src/Composer/Downloader/RarDownloader.php index af467ef5e052..ef697d797757 100644 --- a/src/Composer/Downloader/RarDownloader.php +++ b/src/Composer/Downloader/RarDownloader.php @@ -28,7 +28,7 @@ */ 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; diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index f3418735bef7..056add89c842 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -31,7 +31,7 @@ class SvnDownloader extends VcsDownloader /** * @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(); $util = new SvnUtil($url, $this->io, $this->config, $this->process); @@ -45,7 +45,7 @@ protected function doDownload(PackageInterface $package, string $path, string $u /** * @inheritDoc */ - protected function doInstall(PackageInterface $package, string $path, string $url) + protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface { SvnUtil::cleanEnv(); $ref = $package->getSourceReference(); @@ -67,7 +67,7 @@ protected function doInstall(PackageInterface $package, string $path, string $ur /** * @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(); $ref = $target->getSourceReference(); @@ -91,7 +91,7 @@ protected function doUpdate(PackageInterface $initial, PackageInterface $target, /** * @inheritDoc */ - public function getLocalChanges(PackageInterface $package, string $path) + public function getLocalChanges(PackageInterface $package, string $path): ?string { if (!$this->hasMetadataRepository($path)) { return null; @@ -114,7 +114,7 @@ public function getLocalChanges(PackageInterface $package, string $path) * @throws \RuntimeException * @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->setCacheCredentials($this->cacheCredentials); @@ -130,7 +130,7 @@ protected function execute(PackageInterface $package, string $baseUrl, string $c /** * @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)) { return \React\Promise\resolve(); @@ -191,7 +191,7 @@ protected function cleanChanges(PackageInterface $package, string $path, bool $u /** * @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)) { // retrieve the svn base url from the checkout folder @@ -236,7 +236,7 @@ protected function getCommitLogs(string $fromReference, string $toReference, str * * @return PromiseInterface */ - protected function discardChanges(string $path) + protected function discardChanges(string $path): PromiseInterface { if (0 !== $this->process->execute('svn revert -R .', $output, $path)) { throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput()); @@ -248,7 +248,7 @@ protected function discardChanges(string $path) /** * @inheritDoc */ - protected function hasMetadataRepository(string $path) + protected function hasMetadataRepository(string $path): bool { return is_dir($path.'/.svn'); } diff --git a/src/Composer/Downloader/TarDownloader.php b/src/Composer/Downloader/TarDownloader.php index 5d88b8dfad54..92998aac65fc 100644 --- a/src/Composer/Downloader/TarDownloader.php +++ b/src/Composer/Downloader/TarDownloader.php @@ -13,6 +13,7 @@ namespace Composer\Downloader; use Composer\Package\PackageInterface; +use React\Promise\PromiseInterface; /** * Downloader for tar files: tar, tar.gz or tar.bz2 @@ -24,7 +25,7 @@ class TarDownloader extends ArchiveDownloader /** * @inheritDoc */ - protected function extract(PackageInterface $package, string $file, string $path) + protected function extract(PackageInterface $package, string $file, string $path): PromiseInterface { // Can throw an UnexpectedValueException $archive = new \PharData($file); diff --git a/src/Composer/Downloader/VcsCapableDownloaderInterface.php b/src/Composer/Downloader/VcsCapableDownloaderInterface.php index 43d07c6c5733..38d12c689e0e 100644 --- a/src/Composer/Downloader/VcsCapableDownloaderInterface.php +++ b/src/Composer/Downloader/VcsCapableDownloaderInterface.php @@ -28,5 +28,5 @@ interface VcsCapableDownloaderInterface * @param string $path package directory * @return string|null reference or null */ - public function getVcsReference(PackageInterface $package, string $path); + public function getVcsReference(PackageInterface $package, string $path): ?string; } diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index a97d517e2752..12f5140f57e7 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -52,7 +52,7 @@ public function __construct(IOInterface $io, Config $config, ProcessExecutor $pr /** * @inheritDoc */ - public function getInstallationSource() + public function getInstallationSource(): string { return 'source'; } @@ -60,7 +60,7 @@ public function getInstallationSource() /** * @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()) { throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); @@ -93,7 +93,7 @@ public function download(PackageInterface $package, string $path, PackageInterfa /** * @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') { $this->cleanChanges($prevPackage, $path, true); @@ -110,7 +110,7 @@ public function prepare(string $type, PackageInterface $package, string $path, P /** * @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()])) { $this->reapplyChanges($path); @@ -123,7 +123,7 @@ public function cleanup(string $type, PackageInterface $package, string $path, P /** * @inheritDoc */ - public function install(PackageInterface $package, string $path) + public function install(PackageInterface $package, string $path): PromiseInterface { if (!$package->getSourceReference()) { throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); @@ -158,7 +158,7 @@ public function install(PackageInterface $package, string $path) /** * @inheritDoc */ - public function update(PackageInterface $initial, PackageInterface $target, string $path) + public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface { if (!$target->getSourceReference()) { throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information'); @@ -222,7 +222,7 @@ public function update(PackageInterface $initial, PackageInterface $target, stri /** * @inheritDoc */ - public function remove(PackageInterface $package, string $path) + public function remove(PackageInterface $package, string $path): PromiseInterface { $this->io->writeError(" - " . UninstallOperation::format($package)); @@ -238,7 +238,7 @@ public function remove(PackageInterface $package, string $path) /** * @inheritDoc */ - public function getVcsReference(PackageInterface $package, string $path) + public function getVcsReference(PackageInterface $package, string $path): ?string { $parser = new VersionParser; $guesser = new VersionGuesser($this->config, $this->process, $parser); @@ -264,7 +264,7 @@ public function getVcsReference(PackageInterface $package, string $path) * * @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 if (null !== $this->getLocalChanges($package, $path)) { @@ -283,7 +283,7 @@ protected function cleanChanges(PackageInterface $package, string $path, bool $u * * @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 @@ protected function reapplyChanges(string $path) * @param string $url package url * @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. @@ -306,9 +306,9 @@ abstract protected function doDownload(PackageInterface $package, string $path, * @param string $path download path * @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. @@ -318,9 +318,9 @@ abstract protected function doInstall(PackageInterface $package, string $path, s * @param string $path download path * @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 @@ -330,7 +330,7 @@ abstract protected function doUpdate(PackageInterface $initial, PackageInterface * @param string $path the package path * @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 @@ -339,7 +339,7 @@ abstract protected function getCommitLogs(string $fromReference, string $toRefer * @param string $path * @return bool */ - abstract protected function hasMetadataRepository(string $path); + abstract protected function hasMetadataRepository(string $path): bool; /** * @param string[] $urls diff --git a/src/Composer/Downloader/XzDownloader.php b/src/Composer/Downloader/XzDownloader.php index 33f3c03d6d38..50325603e480 100644 --- a/src/Composer/Downloader/XzDownloader.php +++ b/src/Composer/Downloader/XzDownloader.php @@ -24,7 +24,7 @@ */ 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); diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index e18fd0d80998..e532bdcdd2e7 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -39,7 +39,7 @@ class ZipDownloader extends ArchiveDownloader /** * @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) { self::$unzipCommands = array(); @@ -206,9 +206,9 @@ private function extractWithZipArchive(PackageInterface $package, string $file, * * @param string $file File to extract * @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); } diff --git a/src/Composer/EventDispatcher/Event.php b/src/Composer/EventDispatcher/Event.php index c7af569d2c80..a3f2294ef057 100644 --- a/src/Composer/EventDispatcher/Event.php +++ b/src/Composer/EventDispatcher/Event.php @@ -58,7 +58,7 @@ public function __construct(string $name, array $args = array(), array $flags = * * @return string The event name */ - public function getName() + public function getName(): string { return $this->name; } @@ -68,7 +68,7 @@ public function getName() * * @return string[] The event arguments */ - public function getArguments() + public function getArguments(): array { return $this->args; } @@ -78,7 +78,7 @@ public function getArguments() * * @return mixed[] The event flags */ - public function getFlags() + public function getFlags(): array { return $this->flags; } @@ -88,7 +88,7 @@ public function getFlags() * * @return bool Whether propagation has been stopped */ - public function isPropagationStopped() + public function isPropagationStopped(): bool { return $this->propagationStopped; } @@ -98,7 +98,7 @@ public function isPropagationStopped() * * @return void */ - public function stopPropagation() + public function stopPropagation(): void { $this->propagationStopped = true; } diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 8cfc8b1945e3..941fc252041e 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -96,7 +96,7 @@ public function setRunScripts(bool $runScripts = true) * @return int return code of the executed script if any, for php scripts a false return * value is changed to 1, anything else to 0 */ - public function dispatch(string $eventName, Event $event = null) + public function dispatch(string $eventName, Event $event = null): int { if (null === $event) { $event = new Event($eventName); @@ -115,7 +115,7 @@ public function dispatch(string $eventName, Event $event = null) * @return int return code of the executed script if any, for php scripts a false return * value is changed to 1, anything else to 0 */ - public function dispatchScript(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')); @@ -134,7 +134,7 @@ public function dispatchScript(string $eventName, bool $devMode = false, array $ * @return int return code of the executed script if any, for php scripts a false return * value is changed to 1, anything else to 0 */ - public function dispatchPackageEvent(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')); @@ -152,7 +152,7 @@ public function dispatchPackageEvent(string $eventName, bool $devMode, Repositor * @return int return code of the executed script if any, for php scripts a false return * value is changed to 1, anything else to 0 */ - public function dispatchInstallerEvent(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')); @@ -342,7 +342,7 @@ protected function doDispatch(Event $event) * * @return int */ - protected function executeTty(string $exec) + protected function executeTty(string $exec): int { if ($this->io->isInteractive()) { return $this->process->executeTty($exec); @@ -354,7 +354,7 @@ protected function executeTty(string $exec) /** * @return string */ - protected function getPhpExecCommand() + protected function getPhpExecCommand(): string { $finder = new PhpExecutableFinder(); $phpPath = $finder->find(false); @@ -397,7 +397,7 @@ protected function executeEventPhpScript(string $className, string $methodName, * * @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; } @@ -407,7 +407,7 @@ public function addListener(string $eventName, callable $listener, int $priority * * @return void */ - public function removeListener($listener) + public function removeListener($listener): void { foreach ($this->listeners as $eventName => $priorities) { foreach ($priorities as $priority => $listeners) { @@ -429,7 +429,7 @@ public function removeListener($listener) * * @return void */ - public function addSubscriber(EventSubscriberInterface $subscriber) + public function addSubscriber(EventSubscriberInterface $subscriber): void { foreach ($subscriber->getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { @@ -450,7 +450,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber) * @param Event $event * @return array All listeners: callables and scripts */ - protected function getListeners(Event $event) + protected function getListeners(Event $event): array { $scriptListeners = $this->runScripts ? $this->getScriptListeners($event) : array(); @@ -471,7 +471,7 @@ protected function getListeners(Event $event) * @param Event $event * @return bool */ - public function hasEventListeners(Event $event) + public function hasEventListeners(Event $event): bool { $listeners = $this->getListeners($event); @@ -484,7 +484,7 @@ public function hasEventListeners(Event $event) * @param Event $event Event object * @return string[] Listeners */ - protected function getScriptListeners(Event $event) + protected function getScriptListeners(Event $event): array { $package = $this->composer->getPackage(); $scripts = $package->getScripts(); @@ -519,7 +519,7 @@ protected function getScriptListeners(Event $event) * @param string $callable * @return bool */ - protected function isPhpScript(string $callable) + protected function isPhpScript(string $callable): bool { return false === strpos($callable, ' ') && false !== strpos($callable, '::'); } @@ -530,7 +530,7 @@ protected function isPhpScript(string $callable) * @param string $callable * @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; } @@ -542,7 +542,7 @@ protected function isComposerScript(string $callable) * @throws \RuntimeException * @return int */ - protected function pushEvent(Event $event) + protected function pushEvent(Event $event): int { $eventName = $event->getName(); if (in_array($eventName, $this->eventStack)) { @@ -557,7 +557,7 @@ protected function pushEvent(Event $event) * * @return string|null */ - protected function popEvent() + protected function popEvent(): ?string { return array_pop($this->eventStack); } diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 7d3150d60bec..8200080b3163 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -63,7 +63,7 @@ public function __construct(Loop $loop, IOInterface $io, EventDispatcher $eventD /** * @return void */ - public function reset() + public function reset(): void { $this->notifiablePackages = array(); FileDownloader::$downloadMetadata = array(); @@ -76,7 +76,7 @@ public function reset() * * @return void */ - public function addInstaller(InstallerInterface $installer) + public function addInstaller(InstallerInterface $installer): void { array_unshift($this->installers, $installer); $this->cache = array(); @@ -89,7 +89,7 @@ public function addInstaller(InstallerInterface $installer) * * @return void */ - public function removeInstaller(InstallerInterface $installer) + public function removeInstaller(InstallerInterface $installer): void { if (false !== ($key = array_search($installer, $this->installers, true))) { array_splice($this->installers, $key, 1); @@ -106,7 +106,7 @@ public function removeInstaller(InstallerInterface $installer) * * @return void */ - public function disablePlugins() + public function disablePlugins(): void { foreach ($this->installers as $i => $installer) { if (!$installer instanceof PluginInstaller) { @@ -125,7 +125,7 @@ public function disablePlugins() * @throws \InvalidArgumentException if installer for provided type is not registered * @return InstallerInterface */ - public function getInstaller(string $type) + public function getInstaller(string $type): InstallerInterface { $type = strtolower($type); @@ -150,7 +150,7 @@ public function getInstaller(string $type) * * @return bool */ - public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) + public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool { if ($package instanceof AliasPackage) { return $repo->hasPackage($package) && $this->isPackageInstalled($repo, $package->getAliasOf()); @@ -167,7 +167,7 @@ public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageIn * * @return void */ - public function ensureBinariesPresence(PackageInterface $package) + public function ensureBinariesPresence(PackageInterface $package): void { try { $installer = $this->getInstaller($package->getType()); @@ -192,7 +192,7 @@ public function ensureBinariesPresence(PackageInterface $package) * * @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[] */ $cleanupPromises = array(); @@ -511,7 +511,7 @@ private function waitOnPromises(array $promises): void * * @return PromiseInterface|null */ - public function install(InstalledRepositoryInterface $repo, InstallOperation $operation) + public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface { $package = $operation->getPackage(); $installer = $this->getInstaller($package->getType()); @@ -529,7 +529,7 @@ public function install(InstalledRepositoryInterface $repo, InstallOperation $op * * @return PromiseInterface|null */ - public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation) + public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface { $initial = $operation->getInitialPackage(); $target = $operation->getTargetPackage(); @@ -569,7 +569,7 @@ public function update(InstalledRepositoryInterface $repo, UpdateOperation $oper * * @return PromiseInterface|null */ - public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation) + public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface { $package = $operation->getPackage(); $installer = $this->getInstaller($package->getType()); @@ -585,7 +585,7 @@ public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation * * @return void */ - public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation) + public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation): void { $package = $operation->getPackage(); @@ -602,7 +602,7 @@ public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAlias * * @return void */ - public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation) + public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation): void { $package = $operation->getPackage(); @@ -615,7 +615,7 @@ public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAli * @param PackageInterface $package * @return string path */ - public function getInstallPath(PackageInterface $package) + public function getInstallPath(PackageInterface $package): string { $installer = $this->getInstaller($package->getType()); @@ -627,7 +627,7 @@ public function getInstallPath(PackageInterface $package) * * @return void */ - public function setOutputProgress(bool $outputProgress) + public function setOutputProgress(bool $outputProgress): void { $this->outputProgress = $outputProgress; } @@ -635,7 +635,7 @@ public function setOutputProgress(bool $outputProgress) /** * @return void */ - public function notifyInstalls(IOInterface $io) + public function notifyInstalls(IOInterface $io): void { $promises = array(); diff --git a/src/Composer/Installer/InstallerEvent.php b/src/Composer/Installer/InstallerEvent.php index 88dc7b737526..cafd0dc1b31a 100644 --- a/src/Composer/Installer/InstallerEvent.php +++ b/src/Composer/Installer/InstallerEvent.php @@ -68,7 +68,7 @@ public function __construct(string $eventName, Composer $composer, IOInterface $ /** * @return Composer */ - public function getComposer() + public function getComposer(): Composer { return $this->composer; } @@ -76,7 +76,7 @@ public function getComposer() /** * @return IOInterface */ - public function getIO() + public function getIO(): IOInterface { return $this->io; } @@ -84,7 +84,7 @@ public function getIO() /** * @return bool */ - public function isDevMode() + public function isDevMode(): bool { return $this->devMode; } @@ -92,7 +92,7 @@ public function isDevMode() /** * @return bool */ - public function isExecutingOperations() + public function isExecutingOperations(): bool { return $this->executeOperations; } @@ -100,7 +100,7 @@ public function isExecutingOperations() /** * @return Transaction|null */ - public function getTransaction() + public function getTransaction(): ?Transaction { return $this->transaction; } diff --git a/src/Composer/Installer/PackageEvent.php b/src/Composer/Installer/PackageEvent.php index 177869fb9dde..55029fb9319f 100644 --- a/src/Composer/Installer/PackageEvent.php +++ b/src/Composer/Installer/PackageEvent.php @@ -81,7 +81,7 @@ public function __construct(string $eventName, Composer $composer, IOInterface $ /** * @return Composer */ - public function getComposer() + public function getComposer(): Composer { return $this->composer; } @@ -89,7 +89,7 @@ public function getComposer() /** * @return IOInterface */ - public function getIO() + public function getIO(): IOInterface { return $this->io; } @@ -97,7 +97,7 @@ public function getIO() /** * @return bool */ - public function isDevMode() + public function isDevMode(): bool { return $this->devMode; } @@ -105,7 +105,7 @@ public function isDevMode() /** * @return RepositoryInterface */ - public function getLocalRepo() + public function getLocalRepo(): RepositoryInterface { return $this->localRepo; } @@ -113,7 +113,7 @@ public function getLocalRepo() /** * @return OperationInterface[] */ - public function getOperations() + public function getOperations(): array { return $this->operations; } @@ -123,7 +123,7 @@ public function getOperations() * * @return OperationInterface */ - public function getOperation() + public function getOperation(): OperationInterface { return $this->operation; } diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index b16af75ac01c..3ec407f8a7e5 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -69,7 +69,7 @@ public function __construct(string $path, HttpDownloader $httpDownloader = null, /** * @return string */ - public function getPath() + public function getPath(): string { return $this->path; } @@ -79,7 +79,7 @@ public function getPath() * * @return bool */ - public function exists() + public function exists(): bool { return is_file($this->path); } @@ -188,7 +188,7 @@ private function filePutContentsIfModified(string $path, string $content) * @throws ParsingException * @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); $data = json_decode($content); @@ -309,7 +309,7 @@ public static function parseJson(?string $json, string $file = null) * @throws ParsingException * @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(); $result = $parser->lint($json); diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 68de5dd4a08d..4a8781c648ef 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -58,7 +58,7 @@ public function __construct(string $contents) /** * @return string */ - public function getContents() + public function getContents(): string { return $this->contents . $this->newline; } @@ -70,7 +70,7 @@ public function getContents() * @param bool $sortPackages * @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); @@ -170,7 +170,7 @@ private function sortPackages(array &$packages = array()): void * @param bool $append * @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); } @@ -179,7 +179,7 @@ public function addRepository(string $name, $config, bool $append = true) * @param string $name * @return bool */ - public function removeRepository(string $name) + public function removeRepository(string $name): bool { return $this->removeSubNode('repositories', $name); } @@ -189,7 +189,7 @@ public function removeRepository(string $name) * @param mixed $value * @return bool */ - public function addConfigSetting(string $name, $value) + public function addConfigSetting(string $name, $value): bool { return $this->addSubNode('config', $name, $value); } @@ -198,7 +198,7 @@ public function addConfigSetting(string $name, $value) * @param string $name * @return bool */ - public function removeConfigSetting(string $name) + public function removeConfigSetting(string $name): bool { return $this->removeSubNode('config', $name); } @@ -208,7 +208,7 @@ public function removeConfigSetting(string $name) * @param mixed $value * @return bool */ - public function addProperty(string $name, $value) + public function addProperty(string $name, $value): bool { if (strpos($name, 'suggest.') === 0) { return $this->addSubNode('suggest', substr($name, 8), $value); @@ -229,7 +229,7 @@ public function addProperty(string $name, $value) * @param string $name * @return bool */ - public function removeProperty(string $name) + public function removeProperty(string $name): bool { if (strpos($name, 'suggest.') === 0) { return $this->removeSubNode('suggest', substr($name, 8)); @@ -253,7 +253,7 @@ public function removeProperty(string $name) * @param bool $append * @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); @@ -363,7 +363,7 @@ public function addSubNode(string $mainNode, string $name, $value, bool $append * @param string $name * @return bool */ - public function removeSubNode(string $mainNode, string $name) + public function removeSubNode(string $mainNode, string $name): bool { $decoded = JsonFile::parseJson($this->contents); @@ -468,7 +468,7 @@ public function removeSubNode(string $mainNode, string $name) * @param mixed $content * @return bool */ - public function addMainKey(string $key, $content) + public function addMainKey(string $key, $content): bool { $decoded = JsonFile::parseJson($this->contents); $content = $this->format($content); @@ -512,7 +512,7 @@ public function addMainKey(string $key, $content) * @param string $key * @return bool */ - public function removeMainKey(string $key) + public function removeMainKey(string $key): bool { $decoded = JsonFile::parseJson($this->contents); @@ -549,7 +549,7 @@ public function removeMainKey(string $key) * @param string $key * @return bool */ - public function removeMainKeyIfEmpty(string $key) + public function removeMainKeyIfEmpty(string $key): bool { $decoded = JsonFile::parseJson($this->contents); @@ -569,7 +569,7 @@ public function removeMainKeyIfEmpty(string $key) * @param int $depth * @return string */ - public function format($data, int $depth = 0) + public function format($data, int $depth = 0): string { if (is_array($data)) { reset($data); @@ -597,7 +597,7 @@ public function format($data, int $depth = 0) /** * @return void */ - protected function detectIndenting() + protected function detectIndenting(): void { if (Preg::isMatch('{^([ \t]+)"}m', $this->contents, $match)) { $this->indent = $match[1]; diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 3d82debb6e09..332c1fe05ac5 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -159,14 +159,10 @@ public function getDevRequires(): array * 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 - * - * @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 @@ public function hasSelfVersionRequires(): bool return $this->hasSelfVersionRequires; } - public function __toString() + public function __toString(): string { return parent::__toString().' ('.($this->rootPackageAlias ? 'root ' : ''). 'alias of '.$this->aliasOf->getVersion().')'; } diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index f29bee056fbe..35be9e75ada5 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -78,7 +78,7 @@ public function __construct(string $name) /** * @inheritDoc */ - public function getName() + public function getName(): string { return $this->name; } @@ -86,7 +86,7 @@ public function getName() /** * @inheritDoc */ - public function getPrettyName() + public function getPrettyName(): string { return $this->prettyName; } @@ -94,7 +94,7 @@ public function getPrettyName() /** * @inheritDoc */ - public function getNames($provides = true) + public function getNames($provides = true): array { $names = array( $this->getName() => true, @@ -116,7 +116,7 @@ public function getNames($provides = true) /** * @inheritDoc */ - public function setId($id) + public function setId(int $id): void { $this->id = $id; } @@ -124,7 +124,7 @@ public function setId($id) /** * @inheritDoc */ - public function getId() + public function getId(): int { return $this->id; } @@ -132,7 +132,7 @@ public function getId() /** * @inheritDoc */ - public function setRepository(RepositoryInterface $repository) + public function setRepository(RepositoryInterface $repository): void { if ($this->repository && $repository !== $this->repository) { throw new \LogicException('A package can only be added to one repository'); @@ -143,7 +143,7 @@ public function setRepository(RepositoryInterface $repository) /** * @inheritDoc */ - public function getRepository() + public function getRepository(): ?RepositoryInterface { return $this->repository; } @@ -153,7 +153,7 @@ public function getRepository() * * @return bool */ - public function isPlatform() + public function isPlatform(): bool { return $this->getRepository() instanceof PlatformRepository; } @@ -163,7 +163,7 @@ public function isPlatform() * * @return string */ - public function getUniqueName() + public function getUniqueName(): string { return $this->getName().'-'.$this->getVersion(); } @@ -171,7 +171,7 @@ public function getUniqueName() /** * @return bool */ - public function equals(PackageInterface $package) + public function equals(PackageInterface $package): bool { $self = $this; if ($this instanceof AliasPackage) { @@ -189,12 +189,12 @@ public function equals(PackageInterface $package) * * @return string */ - public function __toString() + public function __toString(): string { return $this->getUniqueName(); } - public function getPrettyString() + public function getPrettyString(): string { return $this->getPrettyName().' '.$this->getPrettyVersion(); } @@ -202,7 +202,7 @@ public function getPrettyString() /** * @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 && (!$this->isDev() || !\in_array($this->getSourceType(), array('hg', 'git'))) @@ -239,7 +239,7 @@ public function getFullPrettyVersion($truncate = true, $displayMode = PackageInt * * @phpstan-return self::STABILITY_* */ - public function getStabilityPriority() + public function getStabilityPriority(): int { return self::$stabilities[$this->getStability()]; } @@ -257,7 +257,7 @@ public function __clone() * @param non-empty-string $wrap Wrap the cleaned string by the given 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)); @@ -271,7 +271,7 @@ public static function packageNameToRegexp(string $allowPattern, string $wrap = * @param non-empty-string $wrap * @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( function ($packageName): string { diff --git a/src/Composer/Package/CompletePackage.php b/src/Composer/Package/CompletePackage.php index 1234ddf0c912..666f3b0c749f 100644 --- a/src/Composer/Package/CompletePackage.php +++ b/src/Composer/Package/CompletePackage.php @@ -47,7 +47,7 @@ class CompletePackage extends Package implements CompletePackageInterface /** * @inheritDoc */ - public function setScripts(array $scripts) + public function setScripts(array $scripts): void { $this->scripts = $scripts; } @@ -55,7 +55,7 @@ public function setScripts(array $scripts) /** * @inheritDoc */ - public function getScripts() + public function getScripts(): array { return $this->scripts; } @@ -63,7 +63,7 @@ public function getScripts() /** * @inheritDoc */ - public function setRepositories(array $repositories) + public function setRepositories(array $repositories): void { $this->repositories = $repositories; } @@ -71,7 +71,7 @@ public function setRepositories(array $repositories) /** * @inheritDoc */ - public function getRepositories() + public function getRepositories(): array { return $this->repositories; } @@ -79,7 +79,7 @@ public function getRepositories() /** * @inheritDoc */ - public function setLicense(array $license) + public function setLicense(array $license): void { $this->license = $license; } @@ -87,7 +87,7 @@ public function setLicense(array $license) /** * @inheritDoc */ - public function getLicense() + public function getLicense(): array { return $this->license; } @@ -95,7 +95,7 @@ public function getLicense() /** * @inheritDoc */ - public function setKeywords(array $keywords) + public function setKeywords(array $keywords): void { $this->keywords = $keywords; } @@ -103,7 +103,7 @@ public function setKeywords(array $keywords) /** * @inheritDoc */ - public function getKeywords() + public function getKeywords(): array { return $this->keywords; } @@ -111,7 +111,7 @@ public function getKeywords() /** * @inheritDoc */ - public function setAuthors(array $authors) + public function setAuthors(array $authors): void { $this->authors = $authors; } @@ -119,7 +119,7 @@ public function setAuthors(array $authors) /** * @inheritDoc */ - public function getAuthors() + public function getAuthors(): array { return $this->authors; } @@ -127,7 +127,7 @@ public function getAuthors() /** * @inheritDoc */ - public function setDescription(?string $description) + public function setDescription(?string $description): void { $this->description = $description; } @@ -135,7 +135,7 @@ public function setDescription(?string $description) /** * @inheritDoc */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } @@ -143,7 +143,7 @@ public function getDescription() /** * @inheritDoc */ - public function setHomepage(?string $homepage) + public function setHomepage(?string $homepage): void { $this->homepage = $homepage; } @@ -151,7 +151,7 @@ public function setHomepage(?string $homepage) /** * @inheritDoc */ - public function getHomepage() + public function getHomepage(): ?string { return $this->homepage; } @@ -159,7 +159,7 @@ public function getHomepage() /** * @inheritDoc */ - public function setSupport(array $support) + public function setSupport(array $support): void { $this->support = $support; } @@ -167,7 +167,7 @@ public function setSupport(array $support) /** * @inheritDoc */ - public function getSupport() + public function getSupport(): array { return $this->support; } @@ -175,7 +175,7 @@ public function getSupport() /** * @inheritDoc */ - public function setFunding(array $funding) + public function setFunding(array $funding): void { $this->funding = $funding; } @@ -183,7 +183,7 @@ public function setFunding(array $funding) /** * @inheritDoc */ - public function getFunding() + public function getFunding(): array { return $this->funding; } @@ -191,7 +191,7 @@ public function getFunding() /** * @inheritDoc */ - public function isAbandoned() + public function isAbandoned(): bool { return (bool) $this->abandoned; } @@ -199,7 +199,7 @@ public function isAbandoned() /** * @inheritDoc */ - public function setAbandoned($abandoned) + public function setAbandoned($abandoned): void { $this->abandoned = $abandoned; } @@ -207,7 +207,7 @@ public function setAbandoned($abandoned) /** * @inheritDoc */ - public function getReplacementPackage() + public function getReplacementPackage(): ?string { return \is_string($this->abandoned) ? $this->abandoned : null; } @@ -215,7 +215,7 @@ public function getReplacementPackage() /** * @inheritDoc */ - public function setArchiveName(?string $name) + public function setArchiveName(?string $name): void { $this->archiveName = $name; } @@ -223,7 +223,7 @@ public function setArchiveName(?string $name) /** * @inheritDoc */ - public function getArchiveName() + public function getArchiveName(): ?string { return $this->archiveName; } @@ -231,7 +231,7 @@ public function getArchiveName() /** * @inheritDoc */ - public function setArchiveExcludes(array $excludes) + public function setArchiveExcludes(array $excludes): void { $this->archiveExcludes = $excludes; } @@ -239,7 +239,7 @@ public function setArchiveExcludes(array $excludes) /** * @inheritDoc */ - public function getArchiveExcludes() + public function getArchiveExcludes(): array { return $this->archiveExcludes; } diff --git a/src/Composer/Package/CompletePackageInterface.php b/src/Composer/Package/CompletePackageInterface.php index e65cc0c4c694..35db9e3cb2fc 100644 --- a/src/Composer/Package/CompletePackageInterface.php +++ b/src/Composer/Package/CompletePackageInterface.php @@ -15,6 +15,8 @@ /** * 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 */ interface CompletePackageInterface extends PackageInterface @@ -24,20 +26,20 @@ interface CompletePackageInterface extends PackageInterface * * @return array Map of script name to array of handlers */ - public function getScripts(); + public function getScripts(): array; /** * @param array $scripts * @return void */ - public function setScripts(array $scripts); + public function setScripts(array $scripts): void; /** * Returns an array of repositories * * @return mixed[] Repositories */ - public function getRepositories(); + public function getRepositories(): array; /** * Set the repositories @@ -45,14 +47,14 @@ public function getRepositories(); * @param mixed[] $repositories * @return void */ - public function setRepositories(array $repositories); + public function setRepositories(array $repositories): void; /** * Returns the package license, e.g. MIT, BSD, GPL * * @return string[] The package licenses */ - public function getLicense(); + public function getLicense(): array; /** * Set the license @@ -60,14 +62,14 @@ public function getLicense(); * @param string[] $license * @return void */ - public function setLicense(array $license); + public function setLicense(array $license): void; /** * Returns an array of keywords relating to the package * * @return string[] */ - public function getKeywords(); + public function getKeywords(): array; /** * Set the keywords @@ -75,14 +77,14 @@ public function getKeywords(); * @param string[] $keywords * @return void */ - public function setKeywords(array $keywords); + public function setKeywords(array $keywords): void; /** * Returns the package description * * @return ?string */ - public function getDescription(); + public function getDescription(): ?string; /** * Set the description @@ -90,14 +92,14 @@ public function getDescription(); * @param string $description * @return void */ - public function setDescription(string $description); + public function setDescription(string $description): void; /** * Returns the package homepage * * @return ?string */ - public function getHomepage(); + public function getHomepage(): ?string; /** * Set the homepage @@ -105,7 +107,7 @@ public function getHomepage(); * @param string $homepage * @return void */ - public function setHomepage(string $homepage); + public function setHomepage(string $homepage): void; /** * Returns an array of authors of the package @@ -114,7 +116,7 @@ public function setHomepage(string $homepage); * * @return array */ - public function getAuthors(); + public function getAuthors(): array; /** * Set the authors @@ -122,14 +124,14 @@ public function getAuthors(); * @param array $authors * @return void */ - public function setAuthors(array $authors); + public function setAuthors(array $authors): void; /** * Returns the support information * * @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 @@ -137,7 +139,7 @@ public function getSupport(); * @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} $support * @return void */ - public function setSupport(array $support); + public function setSupport(array $support): void; /** * Returns an array of funding options for the package @@ -146,7 +148,7 @@ public function setSupport(array $support); * * @return array */ - public function getFunding(); + public function getFunding(): array; /** * Set the funding @@ -154,34 +156,34 @@ public function getFunding(); * @param array $funding * @return void */ - public function setFunding(array $funding); + public function setFunding(array $funding): void; /** * Returns if the package is abandoned or not * * @return bool */ - public function isAbandoned(); + public function isAbandoned(): bool; /** * If the package is abandoned and has a suggested replacement, this method returns it * * @return string|null */ - public function getReplacementPackage(); + public function getReplacementPackage(): ?string; /** * @param bool|string $abandoned * @return void */ - public function setAbandoned($abandoned); + public function setAbandoned($abandoned): void; /** * Returns default base filename for archive * * @return ?string */ - public function getArchiveName(); + public function getArchiveName(): ?string; /** * Sets default base filename for archive @@ -189,14 +191,14 @@ public function getArchiveName(); * @param string $name * @return void */ - public function setArchiveName(string $name); + public function setArchiveName(string $name): void; /** * Returns a list of patterns to exclude from package archives * * @return string[] */ - public function getArchiveExcludes(); + public function getArchiveExcludes(): array; /** * Sets a list of patterns to be excluded from archives @@ -204,5 +206,5 @@ public function getArchiveExcludes(); * @param string[] $excludes * @return void */ - public function setArchiveExcludes(array $excludes); + public function setArchiveExcludes(array $excludes): void; } diff --git a/src/Composer/Package/Link.php b/src/Composer/Package/Link.php index a7628a720ef8..481988c154f1 100644 --- a/src/Composer/Package/Link.php +++ b/src/Composer/Package/Link.php @@ -21,22 +21,22 @@ */ class Link { - const TYPE_REQUIRE = 'requires'; - const TYPE_DEV_REQUIRE = 'devRequires'; - const TYPE_PROVIDE = 'provides'; - const TYPE_CONFLICT = 'conflicts'; - const TYPE_REPLACE = 'replaces'; + public const TYPE_REQUIRE = 'requires'; + public const TYPE_DEV_REQUIRE = 'devRequires'; + public const TYPE_PROVIDE = 'provides'; + public const TYPE_CONFLICT = 'conflicts'; + public const TYPE_REPLACE = 'replaces'; /** * Special type * @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 * @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 diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index ed5d52ee8f6b..90dc0688fdb6 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -120,7 +120,7 @@ public function __construct(string $name, string $version, string $prettyVersion /** * @inheritDoc */ - public function isDev() + public function isDev(): bool { return $this->dev; } @@ -130,7 +130,7 @@ public function isDev() * * @return void */ - public function setType(string $type) + public function setType(string $type): void { $this->type = $type; } @@ -138,7 +138,7 @@ public function setType(string $type) /** * @inheritDoc */ - public function getType() + public function getType(): string { return $this->type ?: 'library'; } @@ -146,7 +146,7 @@ public function getType() /** * @inheritDoc */ - public function getStability() + public function getStability(): string { return $this->stability; } @@ -154,7 +154,7 @@ public function getStability() /** * @return void */ - public function setTargetDir(?string $targetDir) + public function setTargetDir(?string $targetDir): void { $this->targetDir = $targetDir; } @@ -162,7 +162,7 @@ public function setTargetDir(?string $targetDir) /** * @inheritDoc */ - public function getTargetDir() + public function getTargetDir(): ?string { if (null === $this->targetDir) { return null; @@ -176,7 +176,7 @@ public function getTargetDir() * * @return void */ - public function setExtra(array $extra) + public function setExtra(array $extra): void { $this->extra = $extra; } @@ -184,7 +184,7 @@ public function setExtra(array $extra) /** * @inheritDoc */ - public function getExtra() + public function getExtra(): array { return $this->extra; } @@ -194,7 +194,7 @@ public function getExtra() * * @return void */ - public function setBinaries(array $binaries) + public function setBinaries(array $binaries): void { $this->binaries = $binaries; } @@ -202,7 +202,7 @@ public function setBinaries(array $binaries) /** * @inheritDoc */ - public function getBinaries() + public function getBinaries(): array { return $this->binaries; } @@ -212,7 +212,7 @@ public function getBinaries() * * @return void */ - public function setInstallationSource(?string $type) + public function setInstallationSource(?string $type): void { $this->installationSource = $type; } @@ -220,7 +220,7 @@ public function setInstallationSource(?string $type) /** * @inheritDoc */ - public function getInstallationSource() + public function getInstallationSource(): ?string { return $this->installationSource; } @@ -228,7 +228,7 @@ public function getInstallationSource() /** * @return void */ - public function setSourceType(?string $type) + public function setSourceType(?string $type): void { $this->sourceType = $type; } @@ -236,7 +236,7 @@ public function setSourceType(?string $type) /** * @inheritDoc */ - public function getSourceType() + public function getSourceType(): ?string { return $this->sourceType; } @@ -244,7 +244,7 @@ public function getSourceType() /** * @return void */ - public function setSourceUrl(?string $url) + public function setSourceUrl(?string $url): void { $this->sourceUrl = $url; } @@ -252,7 +252,7 @@ public function setSourceUrl(?string $url) /** * @inheritDoc */ - public function getSourceUrl() + public function getSourceUrl(): ?string { return $this->sourceUrl; } @@ -260,7 +260,7 @@ public function getSourceUrl() /** * @return void */ - public function setSourceReference(?string $reference) + public function setSourceReference(?string $reference): void { $this->sourceReference = $reference; } @@ -268,7 +268,7 @@ public function setSourceReference(?string $reference) /** * @inheritDoc */ - public function getSourceReference() + public function getSourceReference(): ?string { return $this->sourceReference; } @@ -276,7 +276,7 @@ public function getSourceReference() /** * @return void */ - public function setSourceMirrors(?array $mirrors) + public function setSourceMirrors(?array $mirrors): void { $this->sourceMirrors = $mirrors; } @@ -284,7 +284,7 @@ public function setSourceMirrors(?array $mirrors) /** * @inheritDoc */ - public function getSourceMirrors() + public function getSourceMirrors(): ?array { return $this->sourceMirrors; } @@ -292,7 +292,7 @@ public function getSourceMirrors() /** * @inheritDoc */ - public function getSourceUrls() + public function getSourceUrls(): array { return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType, 'source'); } @@ -302,7 +302,7 @@ public function getSourceUrls() * * @return void */ - public function setDistType(?string $type) + public function setDistType(?string $type): void { $this->distType = $type; } @@ -310,7 +310,7 @@ public function setDistType(?string $type) /** * @inheritDoc */ - public function getDistType() + public function getDistType(): ?string { return $this->distType; } @@ -320,7 +320,7 @@ public function getDistType() * * @return void */ - public function setDistUrl(?string $url) + public function setDistUrl(?string $url): void { $this->distUrl = $url; } @@ -328,7 +328,7 @@ public function setDistUrl(?string $url) /** * @inheritDoc */ - public function getDistUrl() + public function getDistUrl(): ?string { return $this->distUrl; } @@ -338,7 +338,7 @@ public function getDistUrl() * * @return void */ - public function setDistReference(?string $reference) + public function setDistReference(?string $reference): void { $this->distReference = $reference; } @@ -346,7 +346,7 @@ public function setDistReference(?string $reference) /** * @inheritDoc */ - public function getDistReference() + public function getDistReference(): ?string { return $this->distReference; } @@ -356,7 +356,7 @@ public function getDistReference() * * @return void */ - public function setDistSha1Checksum(?string $sha1checksum) + public function setDistSha1Checksum(?string $sha1checksum): void { $this->distSha1Checksum = $sha1checksum; } @@ -364,7 +364,7 @@ public function setDistSha1Checksum(?string $sha1checksum) /** * @inheritDoc */ - public function getDistSha1Checksum() + public function getDistSha1Checksum(): ?string { return $this->distSha1Checksum; } @@ -372,7 +372,7 @@ public function getDistSha1Checksum() /** * @return void */ - public function setDistMirrors(?array $mirrors) + public function setDistMirrors(?array $mirrors): void { $this->distMirrors = $mirrors; } @@ -380,7 +380,7 @@ public function setDistMirrors(?array $mirrors) /** * @inheritDoc */ - public function getDistMirrors() + public function getDistMirrors(): ?array { return $this->distMirrors; } @@ -388,7 +388,7 @@ public function getDistMirrors() /** * @inheritDoc */ - public function getDistUrls() + public function getDistUrls(): array { return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType, 'dist'); } @@ -396,7 +396,7 @@ public function getDistUrls() /** * @inheritDoc */ - public function getTransportOptions() + public function getTransportOptions(): array { return $this->transportOptions; } @@ -404,7 +404,7 @@ public function getTransportOptions() /** * @inheritDoc */ - public function setTransportOptions(array $options) + public function setTransportOptions(array $options): void { $this->transportOptions = $options; } @@ -412,7 +412,7 @@ public function setTransportOptions(array $options) /** * @inheritDoc */ - public function getVersion() + public function getVersion(): string { return $this->version; } @@ -420,7 +420,7 @@ public function getVersion() /** * @inheritDoc */ - public function getPrettyVersion() + public function getPrettyVersion(): string { return $this->prettyVersion; } @@ -428,7 +428,7 @@ public function getPrettyVersion() /** * @return void */ - public function setReleaseDate(?\DateTimeInterface $releaseDate) + public function setReleaseDate(?\DateTimeInterface $releaseDate): void { $this->releaseDate = $releaseDate; } @@ -436,7 +436,7 @@ public function setReleaseDate(?\DateTimeInterface $releaseDate) /** * @inheritDoc */ - public function getReleaseDate() + public function getReleaseDate(): ?\DateTimeInterface { return $this->releaseDate; } @@ -448,7 +448,7 @@ public function getReleaseDate() * * @return void */ - public function setRequires(array $requires) + public function setRequires(array $requires): void { if (isset($requires[0])) { // @phpstan-ignore-line $requires = $this->convertLinksToMap($requires, 'setRequires'); @@ -460,7 +460,7 @@ public function setRequires(array $requires) /** * @inheritDoc */ - public function getRequires() + public function getRequires(): array { return $this->requires; } @@ -472,7 +472,7 @@ public function getRequires() * * @return void */ - public function setConflicts(array $conflicts) + public function setConflicts(array $conflicts): void { if (isset($conflicts[0])) { // @phpstan-ignore-line $conflicts = $this->convertLinksToMap($conflicts, 'setConflicts'); @@ -485,7 +485,7 @@ public function setConflicts(array $conflicts) * @inheritDoc * @return array */ - public function getConflicts() + public function getConflicts(): array { return $this->conflicts; } @@ -497,7 +497,7 @@ public function getConflicts() * * @return void */ - public function setProvides(array $provides) + public function setProvides(array $provides): void { if (isset($provides[0])) { // @phpstan-ignore-line $provides = $this->convertLinksToMap($provides, 'setProvides'); @@ -510,7 +510,7 @@ public function setProvides(array $provides) * @inheritDoc * @return array */ - public function getProvides() + public function getProvides(): array { return $this->provides; } @@ -522,7 +522,7 @@ public function getProvides() * * @return void */ - public function setReplaces(array $replaces) + public function setReplaces(array $replaces): void { if (isset($replaces[0])) { // @phpstan-ignore-line $replaces = $this->convertLinksToMap($replaces, 'setReplaces'); @@ -535,7 +535,7 @@ public function setReplaces(array $replaces) * @inheritDoc * @return array */ - public function getReplaces() + public function getReplaces(): array { return $this->replaces; } @@ -547,7 +547,7 @@ public function getReplaces() * * @return void */ - public function setDevRequires(array $devRequires) + public function setDevRequires(array $devRequires): void { if (isset($devRequires[0])) { // @phpstan-ignore-line $devRequires = $this->convertLinksToMap($devRequires, 'setDevRequires'); @@ -559,7 +559,7 @@ public function setDevRequires(array $devRequires) /** * @inheritDoc */ - public function getDevRequires() + public function getDevRequires(): array { return $this->devRequires; } @@ -571,7 +571,7 @@ public function getDevRequires() * * @return void */ - public function setSuggests(array $suggests) + public function setSuggests(array $suggests): void { $this->suggests = $suggests; } @@ -579,7 +579,7 @@ public function setSuggests(array $suggests) /** * @inheritDoc */ - public function getSuggests() + public function getSuggests(): array { return $this->suggests; } @@ -593,7 +593,7 @@ public function getSuggests() * * @phpstan-param AutoloadRules $autoload */ - public function setAutoload(array $autoload) + public function setAutoload(array $autoload): void { $this->autoload = $autoload; } @@ -601,7 +601,7 @@ public function setAutoload(array $autoload) /** * @inheritDoc */ - public function getAutoload() + public function getAutoload(): array { return $this->autoload; } @@ -615,7 +615,7 @@ public function getAutoload() * * @phpstan-param DevAutoloadRules $devAutoload */ - public function setDevAutoload(array $devAutoload) + public function setDevAutoload(array $devAutoload): void { $this->devAutoload = $devAutoload; } @@ -623,7 +623,7 @@ public function setDevAutoload(array $devAutoload) /** * @inheritDoc */ - public function getDevAutoload() + public function getDevAutoload(): array { return $this->devAutoload; } @@ -635,7 +635,7 @@ public function getDevAutoload() * * @return void */ - public function setIncludePaths(array $includePaths) + public function setIncludePaths(array $includePaths): void { $this->includePaths = $includePaths; } @@ -643,7 +643,7 @@ public function setIncludePaths(array $includePaths) /** * @inheritDoc */ - public function getIncludePaths() + public function getIncludePaths(): array { return $this->includePaths; } @@ -655,7 +655,7 @@ public function getIncludePaths() * * @return void */ - public function setNotificationUrl(string $notificationUrl) + public function setNotificationUrl(string $notificationUrl): void { $this->notificationUrl = $notificationUrl; } @@ -663,7 +663,7 @@ public function setNotificationUrl(string $notificationUrl) /** * @inheritDoc */ - public function getNotificationUrl() + public function getNotificationUrl(): ?string { return $this->notificationUrl; } @@ -673,7 +673,7 @@ public function getNotificationUrl() * * @return void */ - public function setIsDefaultBranch(bool $defaultBranch) + public function setIsDefaultBranch(bool $defaultBranch): void { $this->isDefaultBranch = $defaultBranch; } @@ -681,7 +681,7 @@ public function setIsDefaultBranch(bool $defaultBranch) /** * @inheritDoc */ - public function isDefaultBranch() + public function isDefaultBranch(): bool { return $this->isDefaultBranch; } @@ -689,7 +689,7 @@ public function isDefaultBranch() /** * @inheritDoc */ - public function setSourceDistReferences(string $reference) + public function setSourceDistReferences(string $reference): void { $this->setSourceReference($reference); @@ -715,7 +715,7 @@ public function setSourceDistReferences(string $reference) * * @return void */ - public function replaceVersion(string $version, string $prettyVersion) + public function replaceVersion(string $version, string $prettyVersion): void { $this->version = $version; $this->prettyVersion = $prettyVersion; @@ -735,7 +735,7 @@ public function replaceVersion(string $version, string $prettyVersion) * * @phpstan-param list|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) { return array(); diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 50512bfe513e..31a0e78fb8f9 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -17,6 +17,8 @@ /** * 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 * * @phpstan-type AutoloadRules array{psr-0?: array, psr-4?: array, classmap?: list, files?: list, exclude-from-classmap?: list} @@ -33,14 +35,14 @@ interface PackageInterface * * @return string package name */ - public function getName(); + public function getName(): string; /** * Returns the package's pretty (i.e. with proper case) name * * @return string package name */ - public function getPrettyName(); + public function getPrettyName(): string; /** * Returns a set of names that could refer to this package @@ -52,7 +54,7 @@ public function getPrettyName(); * * @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. @@ -61,42 +63,42 @@ public function getNames(bool $provides = true); * * @return void */ - public function setId(int $id); + public function setId(int $id): void; /** * Retrieves the package's id set through setId * * @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 * * @return bool */ - public function isDev(); + public function isDev(): bool; /** * Returns the package type, e.g. library * * @return string The package type */ - public function getType(); + public function getType(): string; /** * Returns the package targetDir property * * @return ?string The package targetDir */ - public function getTargetDir(); + public function getTargetDir(): ?string; /** * Returns 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). @@ -106,7 +108,7 @@ public function getExtra(); * * @return void */ - public function setInstallationSource(?string $type); + public function setInstallationSource(?string $type): void; /** * Returns source from which this package was installed (source/dist). @@ -114,110 +116,110 @@ public function setInstallationSource(?string $type); * @return ?string source/dist * @phpstan-return 'source'|'dist'|null */ - public function getInstallationSource(); + public function getInstallationSource(): ?string; /** * Returns the repository type of this package, e.g. git, svn * * @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 * * @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 * * @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 * * @return ?string The repository reference */ - public function getSourceReference(); + public function getSourceReference(): ?string; /** * Returns the source mirrors of this package * * @return ?array */ - public function getSourceMirrors(); + public function getSourceMirrors(): ?array; /** * @param null|array $mirrors * @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 * * @return ?string The repository type */ - public function getDistType(); + public function getDistType(): ?string; /** * Returns the url of the distribution archive of this version * * @return ?string */ - public function getDistUrl(); + public function getDistUrl(): ?string; /** * Returns the urls of the distribution archive of this version, including mirrors * * @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 * * @return ?string */ - public function getDistReference(); + public function getDistReference(): ?string; /** * Returns the sha1 checksum for the distribution archive of this version * * @return ?string */ - public function getDistSha1Checksum(); + public function getDistSha1Checksum(): ?string; /** * Returns the dist mirrors of this package * * @return ?array */ - public function getDistMirrors(); + public function getDistMirrors(): ?array; /** * @param null|array $mirrors * @return void */ - public function setDistMirrors(?array $mirrors); + public function setDistMirrors(?array $mirrors): void; /** * Returns the version of this package * * @return string version */ - public function getVersion(); + public function getVersion(): string; /** * Returns the pretty (i.e. non-normalized) version string of this package * * @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 @@ -230,14 +232,14 @@ public function getPrettyVersion(); * * @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 * * @return ?\DateTimeInterface */ - public function getReleaseDate(); + public function getReleaseDate(): ?\DateTimeInterface; /** * Returns the stability of this package: one of (dev, alpha, beta, RC, stable) @@ -246,7 +248,7 @@ public function getReleaseDate(); * * @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 @@ -254,7 +256,7 @@ public function getStability(); * * @return array 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 @@ -262,7 +264,7 @@ public function getRequires(); * * @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 @@ -270,7 +272,7 @@ public function getConflicts(); * * @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 @@ -278,7 +280,7 @@ public function getProvides(); * * @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 @@ -286,7 +288,7 @@ public function getReplaces(); * * @return array 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 @@ -295,7 +297,7 @@ public function getDevRequires(); * @return array An array of package suggestions with descriptions * @phpstan-return array */ - public function getSuggests(); + public function getSuggests(): array; /** * Returns an associative array of autoloading rules @@ -308,7 +310,7 @@ public function getSuggests(); * @return array Mapping of autoloading rules * @phpstan-return AutoloadRules */ - public function getAutoload(); + public function getAutoload(): array; /** * Returns an associative array of dev autoloading rules @@ -321,7 +323,7 @@ public function getAutoload(); * @return array Mapping of dev autoloading rules * @phpstan-return DevAutoloadRules */ - public function getDevAutoload(); + public function getDevAutoload(): array; /** * Returns a list of directories which should get added to PHP's @@ -329,7 +331,7 @@ public function getDevAutoload(); * * @return string[] */ - public function getIncludePaths(); + public function getIncludePaths(): array; /** * Stores a reference to the repository that owns the package @@ -338,61 +340,61 @@ public function getIncludePaths(); * * @return void */ - public function setRepository(RepositoryInterface $repository); + public function setRepository(RepositoryInterface $repository): void; /** * Returns a reference to the repository that owns the package * * @return ?RepositoryInterface */ - public function getRepository(); + public function getRepository(): ?RepositoryInterface; /** * Returns the package binaries * * @return string[] */ - public function getBinaries(); + public function getBinaries(): array; /** * Returns package unique name, constructed from name and version. * * @return string */ - public function getUniqueName(); + public function getUniqueName(): string; /** * Returns the package notification url * * @return ?string */ - public function getNotificationUrl(); + public function getNotificationUrl(): ?string; /** * Converts the package into a readable and unique string * * @return string */ - public function __toString(); + public function __toString(): string; /** * Converts the package into a pretty readable string * * @return string */ - public function getPrettyString(); + public function getPrettyString(): string; /** * @return bool */ - public function isDefaultBranch(); + public function isDefaultBranch(): bool; /** * Returns a list of options to download package dist files * * @return mixed[] */ - public function getTransportOptions(); + public function getTransportOptions(): array; /** * Configures the list of options to download package dist files @@ -401,32 +403,32 @@ public function getTransportOptions(); * * @return void */ - public function setTransportOptions(array $options); + public function setTransportOptions(array $options): void; /** * @return void */ - public function setSourceReference(?string $reference); + public function setSourceReference(?string $reference): void; /** * @return void */ - public function setDistUrl(?string $url); + public function setDistUrl(?string $url): void; /** * @return void */ - public function setDistType(?string $type); + public function setDistType(?string $type): 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 * * @return void */ - public function setSourceDistReferences(string $reference); + public function setSourceDistReferences(string $reference): void; } diff --git a/src/Composer/Package/RootPackageInterface.php b/src/Composer/Package/RootPackageInterface.php index a1783f87579e..9e74e4ddc8f3 100644 --- a/src/Composer/Package/RootPackageInterface.php +++ b/src/Composer/Package/RootPackageInterface.php @@ -15,6 +15,8 @@ /** * 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 * * @phpstan-import-type AutoloadRules from PackageInterface @@ -27,14 +29,14 @@ interface RootPackageInterface extends CompletePackageInterface * * @return array */ - public function getAliases(); + public function getAliases(): array; /** * Returns the minimum stability of the package * * @return string */ - public function getMinimumStability(); + public function getMinimumStability(): string; /** * Returns the stability flags to apply to dependencies @@ -43,7 +45,7 @@ public function getMinimumStability(); * * @return array */ - public function getStabilityFlags(); + public function getStabilityFlags(): array; /** * Returns a set of package names and source references that must be enforced on them @@ -52,21 +54,21 @@ public function getStabilityFlags(); * * @return array */ - public function getReferences(); + public function getReferences(): array; /** * Returns true if the root package prefers picking stable packages over unstable ones * * @return bool */ - public function getPreferStable(); + public function getPreferStable(): bool; /** * Returns the root package's configuration * * @return mixed[] */ - public function getConfig(); + public function getConfig(): array; /** * Set the required packages @@ -75,7 +77,7 @@ public function getConfig(); * * @return void */ - public function setRequires(array $requires); + public function setRequires(array $requires): void; /** * Set the recommended packages @@ -84,7 +86,7 @@ public function setRequires(array $requires); * * @return void */ - public function setDevRequires(array $devRequires); + public function setDevRequires(array $devRequires): void; /** * Set the conflicting packages @@ -93,7 +95,7 @@ public function setDevRequires(array $devRequires); * * @return void */ - public function setConflicts(array $conflicts); + public function setConflicts(array $conflicts): void; /** * Set the provided virtual packages @@ -102,7 +104,7 @@ public function setConflicts(array $conflicts); * * @return void */ - public function setProvides(array $provides); + public function setProvides(array $provides): void; /** * Set the packages this one replaces @@ -111,7 +113,7 @@ public function setProvides(array $provides); * * @return void */ - public function setReplaces(array $replaces); + public function setReplaces(array $replaces): void; /** * Set the repositories @@ -120,7 +122,7 @@ public function setReplaces(array $replaces); * * @return void */ - public function setRepositories(array $repositories); + public function setRepositories(array $repositories): void; /** * Set the autoload mapping @@ -130,7 +132,7 @@ public function setRepositories(array $repositories); * * @return void */ - public function setAutoload(array $autoload); + public function setAutoload(array $autoload): void; /** * Set the dev autoload mapping @@ -140,7 +142,7 @@ public function setAutoload(array $autoload); * * @return void */ - public function setDevAutoload(array $devAutoload); + public function setDevAutoload(array $devAutoload): void; /** * Set the stabilityFlags @@ -149,7 +151,7 @@ public function setDevAutoload(array $devAutoload); * * @return void */ - public function setStabilityFlags(array $stabilityFlags); + public function setStabilityFlags(array $stabilityFlags): void; /** * Set the minimumStability @@ -158,7 +160,7 @@ public function setStabilityFlags(array $stabilityFlags); * * @return void */ - public function setMinimumStability(string $minimumStability); + public function setMinimumStability(string $minimumStability): void; /** * Set the preferStable @@ -167,7 +169,7 @@ public function setMinimumStability(string $minimumStability); * * @return void */ - public function setPreferStable(bool $preferStable); + public function setPreferStable(bool $preferStable): void; /** * Set the config @@ -176,7 +178,7 @@ public function setPreferStable(bool $preferStable); * * @return void */ - public function setConfig(array $config); + public function setConfig(array $config): void; /** * Set the references @@ -185,7 +187,7 @@ public function setConfig(array $config); * * @return void */ - public function setReferences(array $references); + public function setReferences(array $references): void; /** * Set the aliases @@ -194,7 +196,7 @@ public function setReferences(array $references); * * @return void */ - public function setAliases(array $aliases); + public function setAliases(array $aliases): void; /** * Set the suggested packages @@ -203,12 +205,12 @@ public function setAliases(array $aliases); * * @return void */ - public function setSuggests(array $suggests); + public function setSuggests(array $suggests): void; /** * @param mixed[] $extra * * @return void */ - public function setExtra(array $extra); + public function setExtra(array $extra): void; } diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 44b7dce62e6b..faa5002c785c 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -28,7 +28,7 @@ class VersionParser extends SemverVersionParser /** * @inheritDoc */ - public function parseConstraints($constraints) + public function parseConstraints($constraints): ConstraintInterface { if (!isset(self::$constraints[$constraints])) { self::$constraints[$constraints] = parent::parseConstraints($constraints); @@ -47,7 +47,7 @@ public function parseConstraints($constraints) * * @return list */ - public function parseNameVersionPairs(array $pairs) + public function parseNameVersionPairs(array $pairs): array { $pairs = array_values($pairs); $result = array(); @@ -76,7 +76,7 @@ public function parseNameVersionPairs(array $pairs) * * @return bool */ - public static function isUpgrade(string $normalizedFrom, string $normalizedTo) + public static function isUpgrade(string $normalizedFrom, string $normalizedTo): bool { if ($normalizedFrom === $normalizedTo) { return true; diff --git a/src/Composer/Repository/RepositoryManager.php b/src/Composer/Repository/RepositoryManager.php index 913768028576..0f119931ee7b 100644 --- a/src/Composer/Repository/RepositoryManager.php +++ b/src/Composer/Repository/RepositoryManager.php @@ -62,7 +62,7 @@ public function __construct(IOInterface $io, Config $config, HttpDownloader $htt * * @return PackageInterface|null */ - public function findPackage(string $name, $constraint) + public function findPackage(string $name, $constraint): ?PackageInterface { foreach ($this->repositories as $repository) { /** @var RepositoryInterface $repository */ @@ -82,7 +82,7 @@ public function findPackage(string $name, $constraint) * * @return PackageInterface[] */ - public function findPackages(string $name, $constraint) + public function findPackages(string $name, $constraint): array { $packages = array(); @@ -100,7 +100,7 @@ public function findPackages(string $name, $constraint) * * @return void */ - public function addRepository(RepositoryInterface $repository) + public function addRepository(RepositoryInterface $repository): void { $this->repositories[] = $repository; } @@ -114,7 +114,7 @@ public function addRepository(RepositoryInterface $repository) * * @return void */ - public function prependRepository(RepositoryInterface $repository) + public function prependRepository(RepositoryInterface $repository): void { array_unshift($this->repositories, $repository); } @@ -128,7 +128,7 @@ public function prependRepository(RepositoryInterface $repository) * @throws \InvalidArgumentException if repository for provided type is not registered * @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])) { throw new \InvalidArgumentException('Repository type is not registered: '.$type); @@ -162,7 +162,7 @@ public function createRepository(string $type, array $config, string $name = nul * * @return void */ - public function setRepositoryClass(string $type, $class) + public function setRepositoryClass(string $type, $class): void { $this->repositoryClasses[$type] = $class; } @@ -172,7 +172,7 @@ public function setRepositoryClass(string $type, $class) * * @return RepositoryInterface[] */ - public function getRepositories() + public function getRepositories(): array { return $this->repositories; } @@ -184,7 +184,7 @@ public function getRepositories() * * @return void */ - public function setLocalRepository(InstalledRepositoryInterface $repository) + public function setLocalRepository(InstalledRepositoryInterface $repository): void { $this->localRepository = $repository; } @@ -194,7 +194,7 @@ public function setLocalRepository(InstalledRepositoryInterface $repository) * * @return InstalledRepositoryInterface */ - public function getLocalRepository() + public function getLocalRepository(): InstalledRepositoryInterface { return $this->localRepository; } diff --git a/src/Composer/Repository/Vcs/FossilDriver.php b/src/Composer/Repository/Vcs/FossilDriver.php index 7015f833fb50..1fb0fb36bec3 100644 --- a/src/Composer/Repository/Vcs/FossilDriver.php +++ b/src/Composer/Repository/Vcs/FossilDriver.php @@ -172,12 +172,12 @@ public function getFileContent(string $file, string $identifier): ?string /** * @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); list(, $date) = explode(' ', trim($output), 3); - return new \DateTime($date, new \DateTimeZone('UTC')); + return new \DateTimeImmutable($date, new \DateTimeZone('UTC')); } /** diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index fba97fa421f2..235c4c6c36fd 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -59,7 +59,7 @@ class GitBitbucketDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { 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)); @@ -83,7 +83,7 @@ public function initialize() /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { if ($this->fallbackDriver) { return $this->fallbackDriver->getUrl(); @@ -99,7 +99,7 @@ public function getUrl() * @return bool * @phpstan-impure */ - protected function getRepoData() + protected function getRepoData(): bool { $resource = sprintf( 'https://api.bitbucket.org/2.0/repositories/%s/%s?%s', @@ -131,7 +131,7 @@ protected function getRepoData() /** * @inheritDoc */ - public function getComposerInformation(string $identifier) + public function getComposerInformation(string $identifier): array { if ($this->fallbackDriver) { return $this->fallbackDriver->getComposerInformation($identifier); @@ -205,7 +205,7 @@ public function getComposerInformation(string $identifier) /** * @inheritDoc */ - public function getFileContent(string $file, string $identifier) + public function getFileContent(string $file, string $identifier): ?string { if ($this->fallbackDriver) { return $this->fallbackDriver->getFileContent($file, $identifier); @@ -232,7 +232,7 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { if ($this->fallbackDriver) { return $this->fallbackDriver->getChangeDate($identifier); @@ -253,13 +253,13 @@ public function getChangeDate(string $identifier) ); $commit = $this->fetchWithOAuthCredentials($resource)->decodeJson(); - return new \DateTime($commit['date']); + return new \DateTimeImmutable($commit['date']); } /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { if ($this->fallbackDriver) { return $this->fallbackDriver->getSource($identifier); @@ -271,7 +271,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { if ($this->fallbackDriver) { return $this->fallbackDriver->getDist($identifier); @@ -290,7 +290,7 @@ public function getDist(string $identifier) /** * @inheritDoc */ - public function getTags() + public function getTags(): array { if ($this->fallbackDriver) { return $this->fallbackDriver->getTags(); @@ -333,7 +333,7 @@ public function getTags() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { if ($this->fallbackDriver) { return $this->fallbackDriver->getBranches(); @@ -383,7 +383,7 @@ public function getBranches() * * @phpstan-impure */ - protected function fetchWithOAuthCredentials(string $url, bool $fetchingRepoData = false) + protected function fetchWithOAuthCredentials(string $url, bool $fetchingRepoData = false): Response { try { return parent::getContents($url); @@ -413,7 +413,7 @@ protected function fetchWithOAuthCredentials(string $url, bool $fetchingRepoData * * @return string */ - protected function generateSshUrl() + protected function generateSshUrl(): string { return 'git@' . $this->originUrl . ':' . $this->owner.'/'.$this->repository.'.git'; } @@ -424,7 +424,7 @@ protected function generateSshUrl() * @return true * @throws \RuntimeException */ - protected function attemptCloneFallback() + protected function attemptCloneFallback(): bool { try { $this->setupFallbackDriver($this->generateSshUrl()); @@ -445,7 +445,7 @@ protected function attemptCloneFallback() * @param string $url * @return void */ - protected function setupFallbackDriver(string $url) + protected function setupFallbackDriver(string $url): void { $this->fallbackDriver = new GitDriver( array('url' => $url), @@ -461,7 +461,7 @@ protected function setupFallbackDriver(string $url) * @param array $cloneLinks * @return void */ - protected function parseCloneUrls(array $cloneLinks) + protected function parseCloneUrls(array $cloneLinks): void { foreach ($cloneLinks as $cloneLink) { if ($cloneLink['name'] === 'https') { @@ -475,7 +475,7 @@ protected function parseCloneUrls(array $cloneLinks) /** * @return (array{name: string}&mixed[])|null */ - protected function getMainBranchData() + protected function getMainBranchData(): ?array { $resource = sprintf( 'https://api.bitbucket.org/2.0/repositories/%s/%s?fields=mainbranch', @@ -494,7 +494,7 @@ protected function getMainBranchData() /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { if ($this->fallbackDriver) { return $this->fallbackDriver->getRootIdentifier(); @@ -527,7 +527,7 @@ public function getRootIdentifier() /** * @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)) { return false; diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index f8ee7b32d618..978db48ecf68 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -38,7 +38,7 @@ class GitDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { if (Filesystem::isLocalPath($this->url)) { $this->url = Preg::replace('{[\\/]\.git/?$}', '', $this->url); @@ -88,7 +88,7 @@ public function initialize() /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { if (null === $this->rootIdentifier) { $this->rootIdentifier = 'master'; @@ -112,7 +112,7 @@ public function getRootIdentifier() /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { return $this->url; } @@ -120,7 +120,7 @@ public function getUrl() /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { return array('type' => 'git', 'url' => $this->getUrl(), 'reference' => $identifier); } @@ -128,7 +128,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { return null; } @@ -136,7 +136,7 @@ public function getDist(string $identifier) /** * @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)); $this->process->execute(sprintf('git show %s', $resource), $content, $this->repoDir); @@ -151,20 +151,20 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { $this->process->execute(sprintf( 'git -c log.showSignature=false log -1 --format=%%at %s', ProcessExecutor::escape($identifier) ), $output, $this->repoDir); - return new \DateTime('@'.trim($output), new \DateTimeZone('UTC')); + return new \DateTimeImmutable('@'.trim($output), new \DateTimeZone('UTC')); } /** * @inheritDoc */ - public function getTags() + public function getTags(): array { if (null === $this->tags) { $this->tags = array(); @@ -183,7 +183,7 @@ public function getTags() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { if (null === $this->branches) { $branches = array(); @@ -206,7 +206,7 @@ public function getBranches() /** * @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)) { return true; diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 2f532297eb3d..0d5f90e1e186 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -57,7 +57,7 @@ class GitHubDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { if (!Preg::isMatch('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match)) { throw new \InvalidArgumentException(sprintf('The GitHub repository URL %s is invalid.', $this->url)); @@ -84,7 +84,7 @@ public function initialize() /** * @return string */ - public function getRepositoryUrl() + public function getRepositoryUrl(): string { return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository; } @@ -92,7 +92,7 @@ public function getRepositoryUrl() /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { if ($this->gitDriver) { return $this->gitDriver->getRootIdentifier(); @@ -104,7 +104,7 @@ public function getRootIdentifier() /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { if ($this->gitDriver) { return $this->gitDriver->getUrl(); @@ -116,7 +116,7 @@ public function getUrl() /** * @return string */ - protected function getApiUrl() + protected function getApiUrl(): string { if ('github.com' === $this->originUrl) { $apiUrl = 'api.github.com'; @@ -130,7 +130,7 @@ protected function getApiUrl() /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { if ($this->gitDriver) { return $this->gitDriver->getSource($identifier); @@ -149,7 +149,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { $url = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/zipball/'.$identifier; @@ -159,7 +159,7 @@ public function getDist(string $identifier) /** * @inheritDoc */ - public function getComposerInformation(string $identifier) + public function getComposerInformation(string $identifier): array { if ($this->gitDriver) { return $this->gitDriver->getComposerInformation($identifier); @@ -287,7 +287,7 @@ private function getFundingInfo() /** * @inheritDoc */ - public function getFileContent(string $file, string $identifier) + public function getFileContent(string $file, string $identifier): ?string { if ($this->gitDriver) { return $this->gitDriver->getFileContent($file, $identifier); @@ -305,7 +305,7 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { if ($this->gitDriver) { return $this->gitDriver->getChangeDate($identifier); @@ -314,13 +314,13 @@ public function getChangeDate(string $identifier) $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/commits/'.urlencode($identifier); $commit = $this->getContents($resource)->decodeJson(); - return new \DateTime($commit['commit']['committer']['date']); + return new \DateTimeImmutable($commit['commit']['committer']['date']); } /** * @inheritDoc */ - public function getTags() + public function getTags(): array { if ($this->gitDriver) { return $this->gitDriver->getTags(); @@ -348,7 +348,7 @@ public function getTags() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { if ($this->gitDriver) { return $this->gitDriver->getBranches(); @@ -379,7 +379,7 @@ public function getBranches() /** * @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)) { return false; @@ -404,7 +404,7 @@ public static function supports(IOInterface $io, Config $config, string $url, bo * * @return mixed[]|null */ - public function getRepoData() + public function getRepoData(): ?array { $this->fetchRootIdentifier(); @@ -416,7 +416,7 @@ public function getRepoData() * * @return string */ - protected function generateSshUrl() + protected function generateSshUrl(): string { if (false !== strpos($this->originUrl, ':')) { return 'ssh://git@' . $this->originUrl . '/'.$this->owner.'/'.$this->repository.'.git'; @@ -430,7 +430,7 @@ protected function generateSshUrl() * * @param bool $fetchingRepoData */ - protected function getContents(string $url, bool $fetchingRepoData = false) + protected function getContents(string $url, bool $fetchingRepoData = false): Response { try { return parent::getContents($url); @@ -521,7 +521,7 @@ protected function getContents(string $url, bool $fetchingRepoData = false) * @return void * @throws TransportException */ - protected function fetchRootIdentifier() + protected function fetchRootIdentifier(): void { if ($this->repoData) { return; @@ -563,7 +563,7 @@ protected function fetchRootIdentifier() * @return true * @throws \RuntimeException */ - protected function attemptCloneFallback() + protected function attemptCloneFallback(): bool { $this->isPrivate = true; @@ -588,7 +588,7 @@ protected function attemptCloneFallback() * * @return void */ - protected function setupGitDriver(string $url) + protected function setupGitDriver(string $url): void { $this->gitDriver = new GitDriver( array('url' => $url), @@ -603,7 +603,7 @@ protected function setupGitDriver(string $url) /** * @return string|null */ - protected function getNextPage(Response $response) + protected function getNextPage(Response $response): ?string { $header = $response->getHeader('link'); if (!$header) { diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 3c5e4d16be39..8d55dfc2c9f3 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -216,17 +216,17 @@ public function getFileContent(string $file, string $identifier): ?string /** * @inheritDoc */ - public function getChangeDate(string $identifier): ?\DateTime + public function getChangeDate(string $identifier): ?\DateTimeImmutable { if ($this->gitDriver) { return $this->gitDriver->getChangeDate($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; } /** diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index 575ce72638aa..1faa3c3e3b55 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -37,7 +37,7 @@ class HgDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { if (Filesystem::isLocalPath($this->url)) { $this->repoDir = $this->url; @@ -86,7 +86,7 @@ public function initialize() /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { if (null === $this->rootIdentifier) { $this->process->execute(sprintf('hg tip --template "{node}"'), $output, $this->repoDir); @@ -100,7 +100,7 @@ public function getRootIdentifier() /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { return $this->url; } @@ -108,7 +108,7 @@ public function getUrl() /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { return array('type' => 'hg', 'url' => $this->getUrl(), 'reference' => $identifier); } @@ -116,7 +116,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { return null; } @@ -124,7 +124,7 @@ public function getDist(string $identifier) /** * @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)); $this->process->execute($resource, $content, $this->repoDir); @@ -139,7 +139,7 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { $this->process->execute( sprintf( @@ -150,13 +150,13 @@ public function getChangeDate(string $identifier) $this->repoDir ); - return new \DateTime(trim($output), new \DateTimeZone('UTC')); + return new \DateTimeImmutable(trim($output), new \DateTimeZone('UTC')); } /** * @inheritDoc */ - public function getTags() + public function getTags(): array { if (null === $this->tags) { $tags = array(); @@ -178,7 +178,7 @@ public function getTags() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { if (null === $this->branches) { $branches = array(); @@ -208,7 +208,7 @@ public function getBranches() /** * @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)) { return true; diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 34e4d09c2219..1caad14a7557 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -18,6 +18,7 @@ use Composer\Pcre\Preg; use Composer\Util\ProcessExecutor; use Composer\Util\Perforce; +use Composer\Util\Http\Response; /** * @author Matt Whittom @@ -34,7 +35,7 @@ class PerforceDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { $this->depot = $this->repoConfig['depot']; $this->branch = ''; @@ -72,7 +73,7 @@ private function initPerforce(array $repoConfig): void /** * @inheritDoc */ - public function getFileContent(string $file, string $identifier) + public function getFileContent(string $file, string $identifier): ?string { return $this->perforce->getFileContent($file, $identifier); } @@ -80,7 +81,7 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { return null; } @@ -88,7 +89,7 @@ public function getChangeDate(string $identifier) /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { return $this->branch; } @@ -96,7 +97,7 @@ public function getRootIdentifier() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { return $this->perforce->getBranches(); } @@ -104,7 +105,7 @@ public function getBranches() /** * @inheritDoc */ - public function getTags() + public function getTags(): array { return $this->perforce->getTags(); } @@ -112,7 +113,7 @@ public function getTags() /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { return null; } @@ -120,7 +121,7 @@ public function getDist(string $identifier) /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { return array( 'type' => 'perforce', @@ -133,7 +134,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { return $this->url; } @@ -141,7 +142,7 @@ public function getUrl() /** * @inheritDoc */ - public function hasComposerFile(string $identifier) + public function hasComposerFile(string $identifier): bool { $composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); @@ -151,7 +152,7 @@ public function hasComposerFile(string $identifier) /** * @inheritDoc */ - public function getContents(string $url) + public function getContents(string $url): Response { throw new \BadMethodCallException('Not implemented/used in PerforceDriver'); } @@ -159,7 +160,7 @@ public function getContents(string $url) /** * @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)) { return Perforce::checkServerExists($url, new ProcessExecutor($io)); @@ -171,7 +172,7 @@ public static function supports(IOInterface $io, Config $config, string $url, bo /** * @inheritDoc */ - public function cleanup() + public function cleanup(): void { $this->perforce->cleanupClientSpec(); $this->perforce = null; @@ -180,7 +181,7 @@ public function cleanup() /** * @return string */ - public function getDepot() + public function getDepot(): string { return $this->depot; } @@ -188,7 +189,7 @@ public function getDepot() /** * @return string */ - public function getBranch() + public function getBranch(): string { return $this->branch; } diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 82d91721d0a2..86bea85af5b4 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -57,7 +57,7 @@ class SvnDriver extends VcsDriver /** * @inheritDoc */ - public function initialize() + public function initialize(): void { $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); @@ -93,7 +93,7 @@ public function initialize() /** * @inheritDoc */ - public function getRootIdentifier() + public function getRootIdentifier(): string { return $this->rootIdentifier ?: $this->trunkPath; } @@ -101,7 +101,7 @@ public function getRootIdentifier() /** * @inheritDoc */ - public function getUrl() + public function getUrl(): string { return $this->url; } @@ -109,7 +109,7 @@ public function getUrl() /** * @inheritDoc */ - public function getSource(string $identifier) + public function getSource(string $identifier): array { return array('type' => 'svn', 'url' => $this->baseUrl, 'reference' => $identifier); } @@ -117,7 +117,7 @@ public function getSource(string $identifier) /** * @inheritDoc */ - public function getDist(string $identifier) + public function getDist(string $identifier): ?array { return null; } @@ -125,7 +125,7 @@ public function getDist(string $identifier) /** * @inheritDoc */ - protected function shouldCache(string $identifier) + protected function shouldCache(string $identifier): bool { return $this->cache && Preg::isMatch('{@\d+$}', $identifier); } @@ -133,7 +133,7 @@ protected function shouldCache(string $identifier) /** * @inheritDoc */ - public function getComposerInformation(string $identifier) + public function getComposerInformation(string $identifier): array { if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier.'.json')) { @@ -165,7 +165,7 @@ public function getComposerInformation(string $identifier) * @param string $file * @param string $identifier */ - public function getFileContent(string $file, string $identifier) + public function getFileContent(string $file, string $identifier): ?string { $identifier = '/' . trim($identifier, '/') . '/'; @@ -194,7 +194,7 @@ public function getFileContent(string $file, string $identifier) /** * @inheritDoc */ - public function getChangeDate(string $identifier) + public function getChangeDate(string $identifier): ?\DateTimeImmutable { $identifier = '/' . trim($identifier, '/') . '/'; @@ -210,7 +210,7 @@ public function getChangeDate(string $identifier) $output = $this->execute('svn info', $this->baseUrl . $path . $rev); foreach ($this->process->splitLines($output) as $line) { 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 @@ public function getChangeDate(string $identifier) /** * @inheritDoc */ - public function getTags() + public function getTags(): array { if (null === $this->tags) { $tags = array(); @@ -251,7 +251,7 @@ public function getTags() /** * @inheritDoc */ - public function getBranches() + public function getBranches(): array { if (null === $this->branches) { $branches = array(); @@ -306,7 +306,7 @@ public function getBranches() /** * @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); if (Preg::isMatch('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) { @@ -353,7 +353,7 @@ public static function supports(IOInterface $io, Config $config, string $url, bo * * @return string */ - protected static function normalizeUrl(string $url) + protected static function normalizeUrl(string $url): string { $fs = new Filesystem(); if ($fs->isAbsolutePath($url)) { @@ -372,7 +372,7 @@ protected static function normalizeUrl(string $url) * @throws \RuntimeException * @return string */ - protected function execute(string $command, string $url) + protected function execute(string $command, string $url): string { if (null === $this->util) { $this->util = new SvnUtil($this->baseUrl, $this->io, $this->config, $this->process); @@ -400,7 +400,7 @@ protected function execute(string $command, string $url) * * @return string */ - protected function buildIdentifier(string $baseDir, int $revision) + protected function buildIdentifier(string $baseDir, int $revision): string { return rtrim($baseDir, '/') . $this->packagePath . '/@' . $revision; } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index abc4feb2306d..247ae10b5db5 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -79,7 +79,7 @@ final public function __construct(array $repoConfig, IOInterface $io, Config $co * @param string $identifier * @return bool */ - protected function shouldCache(string $identifier) + protected function shouldCache(string $identifier): bool { return $this->cache && Preg::isMatch('{^[a-f0-9]{40}$}iD', $identifier); } @@ -87,7 +87,7 @@ protected function shouldCache(string $identifier) /** * @inheritDoc */ - public function getComposerInformation(string $identifier) + public function getComposerInformation(string $identifier): array { if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) { @@ -111,7 +111,7 @@ public function getComposerInformation(string $identifier) * * @return array|null */ - protected function getBaseComposerInformation(string $identifier) + protected function getBaseComposerInformation(string $identifier): ?array { $composerFileContent = $this->getFileContent('composer.json', $identifier); @@ -121,7 +121,7 @@ protected function getBaseComposerInformation(string $identifier) $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); } @@ -131,7 +131,7 @@ protected function getBaseComposerInformation(string $identifier) /** * @inheritDoc */ - public function hasComposerFile(string $identifier) + public function hasComposerFile(string $identifier): bool { try { return (bool) $this->getComposerInformation($identifier); @@ -148,7 +148,7 @@ public function hasComposerFile(string $identifier) * * @return string The correct type of protocol */ - protected function getScheme() + protected function getScheme(): string { if (extension_loaded('openssl')) { return 'https'; @@ -165,7 +165,7 @@ protected function getScheme() * @return Response * @throws TransportException */ - protected function getContents(string $url) + protected function getContents(string $url): Response { $options = $this->repoConfig['options'] ?? array(); @@ -175,7 +175,7 @@ protected function getContents(string $url) /** * @inheritDoc */ - public function cleanup() + public function cleanup(): void { return; } diff --git a/src/Composer/Repository/Vcs/VcsDriverInterface.php b/src/Composer/Repository/Vcs/VcsDriverInterface.php index ff3a2cdcedea..e476eeff78f8 100644 --- a/src/Composer/Repository/Vcs/VcsDriverInterface.php +++ b/src/Composer/Repository/Vcs/VcsDriverInterface.php @@ -17,6 +17,7 @@ /** * @author Jordi Boggiano + * @internal */ interface VcsDriverInterface { @@ -25,7 +26,7 @@ interface VcsDriverInterface * * @return void */ - public function initialize(); + public function initialize(): void; /** * Return the composer.json file information @@ -33,7 +34,7 @@ public function initialize(); * @param string $identifier Any identifier to a specific branch/tag/commit * @return mixed[] 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. @@ -42,57 +43,56 @@ public function getComposerInformation(string $identifier); * @param string $identifier * @return string|null */ - public function getFileContent(string $file, string $identifier); + public function getFileContent(string $file, string $identifier): ?string; /** * Get the changedate for $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 string Identifier */ - public function getRootIdentifier(); + public function getRootIdentifier(): string; /** * Return list of branches in the repository * * @return array Branch names as keys, identifiers as values */ - public function getBranches(); + public function getBranches(): array; /** * Return list of tags in the repository * * @return array 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 * * @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 * * @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 string */ - public function getUrl(); + public function getUrl(): string; /** * Return true if the repository has a composer file for a given identifier, @@ -101,14 +101,14 @@ public function getUrl(); * @param string $identifier Any identifier to a specific branch/tag/commit * @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 * * @return void */ - public function cleanup(); + public function cleanup(): void; /** * Checks if this driver can handle a given url @@ -119,5 +119,5 @@ public function cleanup(); * @param bool $deep unless true, only shallow checks (url matching typically) should be done * @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; } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 9a21200988c4..32be9929fadf 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -121,7 +121,7 @@ public function getRepoConfig() /** * @return void */ - public function setLoader(LoaderInterface $loader) + public function setLoader(LoaderInterface $loader): void { $this->loader = $loader; } @@ -129,7 +129,7 @@ public function setLoader(LoaderInterface $loader) /** * @return VcsDriverInterface|null */ - public function getDriver() + public function getDriver(): ?VcsDriverInterface { if ($this->driver) { return $this->driver; @@ -167,7 +167,7 @@ public function getDriver() /** * @return bool */ - public function hadInvalidBranches() + public function hadInvalidBranches(): bool { return $this->branchErrorOccurred; } @@ -175,7 +175,7 @@ public function hadInvalidBranches() /** * @return string[] */ - public function getEmptyReferences() + public function getEmptyReferences(): array { return $this->emptyReferences; } @@ -183,7 +183,7 @@ public function getEmptyReferences() /** * @return array<'tags'|'branches', array> */ - public function getVersionTransportExceptions() + public function getVersionTransportExceptions(): array { return $this->versionTransportExceptions; } diff --git a/src/Composer/Script/Event.php b/src/Composer/Script/Event.php index 3c1bccdb2c98..ed6b7f0ba50d 100644 --- a/src/Composer/Script/Event.php +++ b/src/Composer/Script/Event.php @@ -67,7 +67,7 @@ public function __construct(string $name, Composer $composer, IOInterface $io, b * * @return Composer */ - public function getComposer() + public function getComposer(): Composer { return $this->composer; } @@ -77,7 +77,7 @@ public function getComposer() * * @return IOInterface */ - public function getIO() + public function getIO(): IOInterface { return $this->io; } @@ -87,7 +87,7 @@ public function getIO() * * @return bool */ - public function isDevMode() + public function isDevMode(): bool { return $this->devMode; } diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 7c9482a5c947..be86b3dd01d6 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -49,7 +49,7 @@ public function __construct(IOInterface $io, Config $config, ProcessExecutor $pr * * @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 $this->config->prohibitUrlByConfig($url, $this->io); @@ -272,7 +272,7 @@ public function runCommand(callable $commandCallable, string $url, ?string $cwd, * * @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') { $this->io->writeError('Aborting git mirror sync of '.$url.' as network is disabled'); @@ -317,7 +317,7 @@ public function syncMirror(string $url, string $dir) * * @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)) { return true; @@ -333,7 +333,7 @@ public function fetchRefOrSyncMirror(string $url, string $dir, string $ref) /** * @return string */ - public static function getNoShowSignatureFlag(ProcessExecutor $process) + public static function getNoShowSignatureFlag(ProcessExecutor $process): string { $gitVersion = self::getVersion($process); if ($gitVersion && version_compare($gitVersion, '2.10.0-rc0', '>=')) { @@ -395,7 +395,7 @@ private function isAuthenticationFailure(string $url, array &$match): bool /** * @return void */ - public static function cleanEnv() + public static function cleanEnv(): void { // added in git 1.7.1, prevents prompting the user for username/password if (Platform::getEnv('GIT_ASKPASS') !== 'echo') { @@ -458,7 +458,7 @@ private function throwException($message, string $url): void * * @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) { self::$version = null; diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 058180783858..93ac38a68fdb 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -85,7 +85,7 @@ public function __construct($repoConfig, string $port, string $path, ProcessExec * * @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); } @@ -96,7 +96,7 @@ public static function create($repoConfig, string $port, string $path, ProcessEx * * @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); } @@ -106,7 +106,7 @@ public static function checkServerExists(string $url, ProcessExecutor $processEx * * @return void */ - public function initialize($repoConfig) + public function initialize($repoConfig): void { $this->uniquePerforceClientName = $this->generateUniquePerforceClientName(); if (!$repoConfig) { @@ -138,7 +138,7 @@ public function initialize($repoConfig) * * @return void */ - public function initializeDepotAndBranch(?string $depot, ?string $branch) + public function initializeDepotAndBranch(?string $depot, ?string $branch): void { if (isset($depot)) { $this->p4Depot = $depot; @@ -159,7 +159,7 @@ public function generateUniquePerforceClientName() /** * @return void */ - public function cleanupClientSpec() + public function cleanupClientSpec(): void { $client = $this->getClient(); $task = 'client -d ' . ProcessExecutor::escape($client); @@ -176,7 +176,7 @@ public function cleanupClientSpec() * * @return int */ - protected function executeCommand($command) + protected function executeCommand($command): int { $this->commandResult = ''; @@ -186,7 +186,7 @@ protected function executeCommand($command) /** * @return string */ - public function getClient() + public function getClient(): string { if (!isset($this->p4Client)) { $cleanStreamName = str_replace(array('//', '/', '@'), array('', '_', ''), $this->getStream()); @@ -199,7 +199,7 @@ public function getClient() /** * @return string */ - protected function getPath() + protected function getPath(): string { return $this->path; } @@ -209,7 +209,7 @@ protected function getPath() * * @return void */ - public function initializePath(string $path) + public function initializePath(string $path): void { $this->path = $path; $fs = $this->getFilesystem(); @@ -219,7 +219,7 @@ public function initializePath(string $path) /** * @return string */ - protected function getPort() + protected function getPort(): string { return $this->p4Port; } @@ -229,7 +229,7 @@ protected function getPort() * * @return void */ - public function setStream(string $stream) + public function setStream(string $stream): void { $this->p4Stream = $stream; $index = strrpos($stream, '/'); @@ -242,7 +242,7 @@ public function setStream(string $stream) /** * @return bool */ - public function isStream() + public function isStream(): bool { return is_string($this->p4DepotType) && (strcmp($this->p4DepotType, 'stream') === 0); } @@ -250,7 +250,7 @@ public function isStream() /** * @return string */ - public function getStream() + public function getStream(): string { if (!isset($this->p4Stream)) { if ($this->isStream()) { @@ -268,7 +268,7 @@ public function getStream() * * @return string */ - public function getStreamWithoutLabel(string $stream) + public function getStreamWithoutLabel(string $stream): string { $index = strpos($stream, '@'); if ($index === false) { @@ -289,7 +289,7 @@ public function getP4ClientSpec() /** * @return string|null */ - public function getUser() + public function getUser(): ?string { return $this->p4User; } @@ -299,7 +299,7 @@ public function getUser() * * @return void */ - public function setUser(?string $user) + public function setUser(?string $user): void { $this->p4User = $user; } @@ -307,7 +307,7 @@ public function setUser(?string $user) /** * @return void */ - public function queryP4User() + public function queryP4User(): void { $this->getUser(); if (strlen((string) $this->p4User) > 0) { @@ -365,7 +365,7 @@ protected function getP4variable(string $name) /** * @return string|null */ - public function queryP4Password() + public function queryP4Password(): ?string { if (isset($this->p4Password)) { return $this->p4Password; @@ -400,7 +400,7 @@ public function generateP4Command(string $command, bool $useClient = true) /** * @return bool */ - public function isLoggedIn() + public function isLoggedIn(): bool { $command = $this->generateP4Command('login -s', false); $exitCode = $this->executeCommand($command); @@ -423,7 +423,7 @@ public function isLoggedIn() /** * @return void */ - public function connectClient() + public function connectClient(): void { $p4CreateClientCommand = $this->generateP4Command( 'client -i < ' . str_replace(" ", "\\ ", $this->getP4ClientSpec()) @@ -436,7 +436,7 @@ public function connectClient() * * @return void */ - public function syncCodeBase(?string $sourceReference) + public function syncCodeBase(?string $sourceReference): void { $prevDir = Platform::getCwd(); chdir($this->path); @@ -453,7 +453,7 @@ public function syncCodeBase(?string $sourceReference) * * @return void */ - public function writeClientSpecToFile($spec) + public function writeClientSpecToFile($spec): void { fwrite($spec, 'Client: ' . $this->getClient() . PHP_EOL . PHP_EOL); fwrite($spec, 'Update: ' . date('Y/m/d H:i:s') . PHP_EOL . PHP_EOL); @@ -479,7 +479,7 @@ public function writeClientSpecToFile($spec) /** * @return void */ - public function writeP4ClientSpec() + public function writeP4ClientSpec(): void { $clientSpec = $this->getP4ClientSpec(); $spec = fopen($clientSpec, 'w'); @@ -498,7 +498,7 @@ public function writeP4ClientSpec() * * @return void */ - protected function read($pipe, $name) + protected function read($pipe, $name): void { if (feof($pipe)) { return; @@ -514,7 +514,7 @@ protected function read($pipe, $name) * * @return int */ - public function windowsLogin(?string $password) + public function windowsLogin(?string $password): int { $command = $this->generateP4Command(' login -a'); @@ -526,7 +526,7 @@ public function windowsLogin(?string $password) /** * @return void */ - public function p4Login() + public function p4Login(): void { $this->queryP4User(); if (!$this->isLoggedIn()) { @@ -565,7 +565,7 @@ public function getComposerInformation(string $identifier) * * @return string|null */ - public function getFileContent(string $file, string $identifier) + public function getFileContent(string $file, string $identifier): ?string { $path = $this->getFilePath($file, $identifier); @@ -586,7 +586,7 @@ public function getFileContent(string $file, string $identifier) * * @return string|null */ - public function getFilePath(string $file, string $identifier) + public function getFilePath(string $file, string $identifier): ?string { $index = strpos($identifier, '@'); if ($index === false) { @@ -646,7 +646,7 @@ public function getBranches() /** * @return array */ - public function getTags() + public function getTags(): array { $command = $this->generateP4Command('labels'); $this->executeCommand($command); @@ -666,7 +666,7 @@ public function getTags() /** * @return bool */ - public function checkStream() + public function checkStream(): bool { $command = $this->generateP4Command('depots', false); $this->executeCommand($command); @@ -690,7 +690,7 @@ public function checkStream() * @param string $reference * @return mixed|null */ - protected function getChangeList(string $reference) + protected function getChangeList(string $reference): mixed { $index = strpos($reference, '@'); if ($index === false) { @@ -713,7 +713,7 @@ protected function getChangeList(string $reference) * @param string $toReference * @return mixed|null */ - public function getCommitLogs(string $fromReference, string $toReference) + public function getCommitLogs(string $fromReference, string $toReference): mixed { $fromChangeList = $this->getChangeList($fromReference); if ($fromChangeList === null) { @@ -734,7 +734,7 @@ public function getCommitLogs(string $fromReference, string $toReference) /** * @return Filesystem */ - public function getFilesystem() + public function getFilesystem(): Filesystem { if (null === $this->filesystem) { $this->filesystem = new Filesystem($this->process); @@ -746,7 +746,7 @@ public function getFilesystem() /** * @return void */ - public function setFilesystem(Filesystem $fs) + public function setFilesystem(Filesystem $fs): void { $this->filesystem = $fs; } diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index 05060bbfbeee..429337708c0a 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -68,7 +68,7 @@ public function __construct(IOInterface $io = null) * @param null|string $cwd the working directory * @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) { return $this->doExecute($command, $cwd, false, $output); @@ -84,7 +84,7 @@ public function execute($command, &$output = null, ?string $cwd = null) * @param null|string $cwd the working directory * @return int statuscode */ - public function executeTty($command, ?string $cwd = null) + public function executeTty($command, ?string $cwd = null): int { if (Platform::isTty()) { return $this->doExecute($command, $cwd, true); @@ -121,7 +121,10 @@ private function doExecute($command, ?string $cwd, bool $tty, &$output = null): } } - $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); if ($this->captureOutput && !is_callable($output)) { @@ -140,7 +143,7 @@ private function doExecute($command, ?string $cwd, bool $tty, &$output = null): * @param string $cwd the working directory * @return PromiseInterface */ - public function executeAsync($command, ?string $cwd = null) + public function executeAsync($command, ?string $cwd = null): PromiseInterface { 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'); @@ -206,6 +209,25 @@ public function executeAsync($command, ?string $cwd = null) 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 * @return void @@ -253,7 +275,7 @@ private function startJob(int $id): void * @param ?int $index job id * @return void */ - public function wait($index = null) + public function wait($index = null): void { while (true) { if (!$this->countActiveJobs($index)) { @@ -324,7 +346,7 @@ private function markJobDone(): void * @param null|string $output * @return string[] */ - public function splitLines(?string $output) + public function splitLines(?string $output): array { $output = trim((string) $output); @@ -336,42 +358,15 @@ public function splitLines(?string $output) * * @return string */ - public function getErrorOutput() + public function getErrorOutput(): string { 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 */ - public static function getTimeout() + public static function getTimeout(): int { return static::$timeout; } @@ -380,7 +375,7 @@ public static function getTimeout() * @param int $timeout the timeout in seconds * @return void */ - public static function setTimeout(int $timeout) + public static function setTimeout(int $timeout): void { static::$timeout = $timeout; } @@ -392,7 +387,7 @@ public static function setTimeout(int $timeout) * * @return string The escaped argument */ - public static function escape($argument) + public static function escape($argument): string { return self::escapeArgument($argument); } diff --git a/tests/Composer/Test/Command/InitCommandTest.php b/tests/Composer/Test/Command/InitCommandTest.php index 69af6cfbc367..25af49ed503c 100644 --- a/tests/Composer/Test/Command/InitCommandTest.php +++ b/tests/Composer/Test/Command/InitCommandTest.php @@ -20,7 +20,7 @@ class InitCommandTest extends TestCase public function testParseValidAuthorString(): void { $command = new InitCommand; - $author = $command->parseAuthorString('John Smith '); + $author = $this->callParseAuthorString($command, 'John Smith '); $this->assertEquals('John Smith', $author['name']); $this->assertEquals('john@example.com', $author['email']); } @@ -28,7 +28,7 @@ public function testParseValidAuthorString(): void public function testParseValidAuthorStringWithoutEmail(): void { $command = new InitCommand; - $author = $command->parseAuthorString('John Smith'); + $author = $this->callParseAuthorString($command, 'John Smith'); $this->assertEquals('John Smith', $author['name']); $this->assertNull($author['email']); } @@ -36,7 +36,7 @@ public function testParseValidAuthorStringWithoutEmail(): void public function testParseValidUtf8AuthorString(): void { $command = new InitCommand; - $author = $command->parseAuthorString('Matti Meikäläinen '); + $author = $this->callParseAuthorString($command, 'Matti Meikäläinen '); $this->assertEquals('Matti Meikäläinen', $author['name']); $this->assertEquals('matti@example.com', $author['email']); } @@ -46,7 +46,7 @@ public function testParseValidUtf8AuthorStringWithNonSpacingMarks(): void // \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark $utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen"; $command = new InitCommand; - $author = $command->parseAuthorString($utf8_expected." "); + $author = $this->callParseAuthorString($command, $utf8_expected." "); $this->assertEquals($utf8_expected, $author['name']); $this->assertEquals('matti@example.com', $author['email']); } @@ -54,7 +54,7 @@ public function testParseValidUtf8AuthorStringWithNonSpacingMarks(): void public function testParseNumericAuthorString(): void { $command = new InitCommand; - $author = $command->parseAuthorString('h4x0r '); + $author = $this->callParseAuthorString($command, 'h4x0r '); $this->assertEquals('h4x0r', $author['name']); $this->assertEquals('h4x@example.com', $author['email']); } @@ -66,7 +66,7 @@ public function testParseNumericAuthorString(): void public function testParseValidAlias1AuthorString(): void { $command = new InitCommand; - $author = $command->parseAuthorString( + $author = $this->callParseAuthorString($command, 'Johnathon "Johnny" Smith ' ); $this->assertEquals('Johnathon "Johnny" Smith', $author['name']); @@ -80,7 +80,7 @@ public function testParseValidAlias1AuthorString(): void public function testParseValidAlias2AuthorString(): void { $command = new InitCommand; - $author = $command->parseAuthorString( + $author = $this->callParseAuthorString($command, 'Johnathon (Johnny) Smith ' ); $this->assertEquals('Johnathon (Johnny) Smith', $author['name']); @@ -91,14 +91,14 @@ public function testParseEmptyAuthorString(): void { $command = new InitCommand; self::expectException('InvalidArgumentException'); - $command->parseAuthorString(''); + $this->callParseAuthorString($command, ''); } public function testParseAuthorStringWithInvalidEmail(): void { $command = new InitCommand; self::expectException('InvalidArgumentException'); - $command->parseAuthorString('John Smith '); + $this->callParseAuthorString($command, 'John Smith '); } public function testNamespaceFromValidPackageName(): void @@ -121,4 +121,15 @@ public function testNamespaceFromMissingPackageName(): void $namespace = $command->namespaceFromPackageName(''); $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); + } } diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index 7fa25f717a03..8ff051927061 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -223,7 +223,8 @@ public function testFullPackageDownload(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -273,7 +274,8 @@ public function testFullPackageDownloadFailover(): void $downloaderSuccess ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -330,7 +332,8 @@ public function testDistOnlyPackageDownload(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -366,7 +369,8 @@ public function testSourceOnlyPackageDownload(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -432,7 +436,8 @@ public function testFullPackageDownloadWithSourcePreferred(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -469,7 +474,8 @@ public function testDistOnlyPackageDownloadWithSourcePreferred(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -506,7 +512,8 @@ public function testSourceOnlyPackageDownloadWithSourcePreferred(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -567,7 +574,8 @@ public function testUpdateDistWithEqualTypes(): void $zipDownloader ->expects($this->once()) ->method('update') - ->with($initial, $target, 'vendor/bundles/FOS/UserBundle'); + ->with($initial, $target, 'vendor/bundles/FOS/UserBundle') + ->will($this->returnValue(\React\Promise\resolve())); $zipDownloader ->expects($this->any()) ->method('getInstallationSource') @@ -605,7 +613,8 @@ public function testUpdateDistWithNotEqualTypes(): void $xzDownloader ->expects($this->once()) ->method('remove') - ->with($initial, 'vendor/bundles/FOS/UserBundle'); + ->with($initial, 'vendor/bundles/FOS/UserBundle') + ->will($this->returnValue(\React\Promise\resolve())); $xzDownloader ->expects($this->any()) ->method('getInstallationSource') @@ -615,7 +624,8 @@ public function testUpdateDistWithNotEqualTypes(): void $zipDownloader ->expects($this->once()) ->method('install') - ->with($target, 'vendor/bundles/FOS/UserBundle'); + ->with($target, 'vendor/bundles/FOS/UserBundle') + ->will($this->returnValue(\React\Promise\resolve())); $zipDownloader ->expects($this->any()) ->method('getInstallationSource') @@ -775,7 +785,8 @@ public function testInstallPreferenceWithoutPreferenceDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -818,7 +829,8 @@ public function testInstallPreferenceWithoutPreferenceNoDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -864,7 +876,8 @@ public function testInstallPreferenceWithoutMatchDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -911,7 +924,8 @@ public function testInstallPreferenceWithoutMatchNoDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -958,7 +972,8 @@ public function testInstallPreferenceWithMatchAutoDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -1005,7 +1020,8 @@ public function testInstallPreferenceWithMatchAutoNoDev(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -1048,7 +1064,8 @@ public function testInstallPreferenceWithMatchSource(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) @@ -1091,7 +1108,8 @@ public function testInstallPreferenceWithMatchDist(): void $downloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir'); + ->with($package, 'target_dir') + ->will($this->returnValue(\React\Promise\resolve())); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setConstructorArgs(array($this->io, false, $this->filesystem)) diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index 9b0ca2382ad9..f7a44441298c 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -335,7 +335,7 @@ private function wait($promise): void 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(); } @@ -345,7 +345,7 @@ public function install(PackageInterface $package, $path, $output = true): Promi 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); } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 5f2cc55f8267..e14a830df83a 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -151,7 +151,8 @@ public function testInstall(): void $this->dm ->expects($this->once()) ->method('install') - ->with($package, $this->vendorDir.'/some/package'); + ->with($package, $this->vendorDir.'/some/package') + ->will($this->returnValue(\React\Promise\resolve())); $this->repository ->expects($this->once()) @@ -190,7 +191,8 @@ public function testUpdate(): void $this->dm ->expects($this->once()) ->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 ->expects($this->once()) @@ -226,7 +228,8 @@ public function testUninstall(): void $this->dm ->expects($this->once()) ->method('remove') - ->with($package, $this->vendorDir.'/vendor/pkg'); + ->with($package, $this->vendorDir.'/vendor/pkg') + ->will($this->returnValue(\React\Promise\resolve())); $this->repository ->expects($this->once()) diff --git a/tests/Composer/Test/Mock/ProcessExecutorMock.php b/tests/Composer/Test/Mock/ProcessExecutorMock.php index 97f4c3f56551..897d889ce4fb 100644 --- a/tests/Composer/Test/Mock/ProcessExecutorMock.php +++ b/tests/Composer/Test/Mock/ProcessExecutorMock.php @@ -135,7 +135,9 @@ private function doExecute($command, string $cwd, bool $tty, &$output = null) $this->captureOutput = func_num_args() > 3; $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; $this->log[] = $commandString; diff --git a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php index 6b4315363800..8b1d5af0cd80 100644 --- a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php +++ b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php @@ -23,32 +23,21 @@ class ArrayDumperTest extends TestCase * @var ArrayDumper */ private $dumper; - /** - * @var \Composer\Package\CompletePackageInterface|\PHPUnit\Framework\MockObject\MockObject - */ - private $package; public function setUp(): void { $this->dumper = new ArrayDumper(); - $this->package = $this->getMockBuilder('Composer\Package\CompletePackageInterface')->getMock(); - $this->packageExpects('getTransportOptions', array()); } public function testRequiredInformation(): void { - $this - ->packageExpects('getPrettyName', 'foo') - ->packageExpects('getPrettyVersion', '1.0') - ->packageExpects('getVersion', '1.0.0.0') - ; - - $config = $this->dumper->dump($this->package); + $config = $this->dumper->dump($this->getPackage()); $this->assertEquals( array( - 'name' => 'foo', - 'version' => '1.0', + 'name' => 'dummy/pkg', + 'version' => '1.0.0', 'version_normalized' => '1.0.0.0', + 'type' => 'library', ), $config ); @@ -56,33 +45,27 @@ public function testRequiredInformation(): void public function testRootPackage(): void { - $this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock(); - - $this - ->packageExpects('getMinimumStability', 'dev') - ->packageExpects('getTransportOptions', array()) - ; + $package = $this->getRootPackage(); + $package->setMinimumStability('dev'); - $config = $this->dumper->dump($this->package); + $config = $this->dumper->dump($package); $this->assertSame('dev', $config['minimum-stability']); } public function testDumpAbandoned(): void { - $this->packageExpects('isAbandoned', true); - $this->packageExpects('getReplacementPackage', true); - - $config = $this->dumper->dump($this->package); + $package = $this->getPackage(); + $package->setAbandoned(true); + $config = $this->dumper->dump($package); $this->assertTrue($config['abandoned']); } public function testDumpAbandonedReplacement(): void { - $this->packageExpects('isAbandoned', true); - $this->packageExpects('getReplacementPackage', 'foo/bar'); - - $config = $this->dumper->dump($this->package); + $package = $this->getPackage(); + $package->setAbandoned('foo/bar'); + $config = $this->dumper->dump($package); $this->assertSame('foo/bar', $config['abandoned']); } @@ -97,16 +80,12 @@ public function testDumpAbandonedReplacement(): void */ public function testKeys(string $key, $value, string $method = null, $expectedValue = null): void { - $this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock(); - - $this->packageExpects('get'.ucfirst($method ?: $key), $value); - $this->packageExpects('isAbandoned', $value); + $package = $this->getRootPackage(); - if ($method !== 'transportOptions') { - $this->packageExpects('getTransportOptions', array()); - } + // @phpstan-ignore-next-line + $package->{'set'.ucfirst($method ?: $key)}($value); - $config = $this->dumper->dump($this->package); + $config = $this->dumper->dump($package); $this->assertSame($expectedValue ?: $value, $config[$key]); } @@ -177,13 +156,13 @@ public function provideKeys(): array ), array( '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', array('foo/bar' => '1.0.0'), ), array( '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', array('foo/bar' => '1.0.0'), ), @@ -202,13 +181,19 @@ public function provideKeys(): array ), array( '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', array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), ), array( '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', array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), ), @@ -220,19 +205,28 @@ public function provideKeys(): array ), array( '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', array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), ), array( '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', array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), ), array( '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', array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'), ), @@ -243,18 +237,4 @@ public function provideKeys(): array ), ); } - - /** - * @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; - } } diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index 17168f62a14b..d2913e36ddda 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -93,41 +93,8 @@ public function testSetLockData(): void $jsonContent = $this->getJsonContent() . ' '; $locker = new Locker(new NullIO, $json, $inst, $jsonContent); - $package1 = $this->createPackageMock(); - $package2 = $this->createPackageMock(); - - $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())); - } + $package1 = $this->getPackage('pkg1', '1.0.0-beta'); + $package2 = $this->getPackage('pkg2', '0.1.10'); $contentHash = md5(trim($jsonContent)); @@ -140,8 +107,8 @@ public function testSetLockData(): void 'This file is @gener'.'ated automatically', ), 'content-hash' => $contentHash, 'packages' => array( - array('name' => 'pkg1', 'version' => '1.0.0-beta'), - array('name' => 'pkg2', 'version' => '0.1.10'), + array('name' => 'pkg1', 'version' => '1.0.0-beta', 'type' => 'library'), + array('name' => 'pkg2', 'version' => '0.1.10', 'type' => 'library'), ), 'packages-dev' => array(), 'aliases' => array(), diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index dcc0ecabf92b..32b2afc36017 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -83,6 +83,15 @@ protected function setUp(): void $dm = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->disableOriginalConstructor() ->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(); diff --git a/tests/Composer/Test/Util/AuthHelperTest.php b/tests/Composer/Test/Util/AuthHelperTest.php index cf0a9e8fcb0e..b179688e2a4e 100644 --- a/tests/Composer/Test/Util/AuthHelperTest.php +++ b/tests/Composer/Test/Util/AuthHelperTest.php @@ -377,8 +377,7 @@ public function testStoreAuthAutomatically(): void $configSource->expects($this->once()) ->method('addConfigSetting') - ->with('http-basic.'.$origin, $auth) - ->willReturn($configSource); + ->with('http-basic.'.$origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); } @@ -429,8 +428,7 @@ public function testStoreAuthWithPromptYesAnswer(): void $configSource->expects($this->once()) ->method('addConfigSetting') - ->with('http-basic.'.$origin, $auth) - ->willReturn($configSource); + ->with('http-basic.'.$origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); }