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/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/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/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;