Skip to content

Commit

Permalink
Add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 23, 2022
1 parent e52071a commit 584d090
Show file tree
Hide file tree
Showing 26 changed files with 401 additions and 410 deletions.
2 changes: 1 addition & 1 deletion src/Composer/Command/DiagnoseCommand.php
Expand Up @@ -52,7 +52,7 @@ class DiagnoseCommand extends BaseCommand
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setName('diagnose')
Expand Down
15 changes: 7 additions & 8 deletions src/Composer/Command/InitCommand.php
Expand Up @@ -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<name>[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?:\s+<(?P<email>.+?)>)?$/u', $author, $match)) {
$hasEmail = isset($match['email']) && '' !== $match['email'];
Expand All @@ -485,7 +484,7 @@ public function parseAuthorString(string $author)
*
* @return array<int, array{name: string, email?: string}>
*/
protected function formatAuthors(string $author)
protected function formatAuthors(string $author): array
{
$author = $this->parseAuthorString($author);
if (null === $author['email']) {
Expand All @@ -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;
Expand All @@ -526,7 +525,7 @@ function ($part): string {
/**
* @return array<string, string>
*/
protected function getGitConfig()
protected function getGitConfig(): array
{
if (null !== $this->gitConfig) {
return $this->gitConfig;
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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')) {
Expand Down
15 changes: 4 additions & 11 deletions src/Composer/Command/RequireCommand.php
Expand Up @@ -335,15 +335,6 @@ private function getPackagesByRequireKey(): array
);
}

/**
* @private
* @return void
*/
public function markSolverComplete()
{
$this->dependencyResolutionCompleted = true;
}

/**
* @param array<string, string> $requirements
* @param string $requireKey
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
24 changes: 12 additions & 12 deletions src/Composer/Command/ShowCommand.php
Expand Up @@ -602,7 +602,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @return string[]
*/
protected function getRootRequires()
protected function getRootRequires(): array
{
$rootPackage = $this->requireComposer()->getPackage();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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('<info>name</info> : ' . $package->getPrettyName());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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',
Expand All @@ -1052,7 +1052,7 @@ protected function initStyles(OutputInterface $output)
* @param array<int, array<string, string|mixed[]>> $arrayTree
* @return void
*/
protected function displayPackageTree(array $arrayTree)
protected function displayPackageTree(array $arrayTree): void
{
$io = $this->getIO();
foreach ($arrayTree as $package) {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ protected function generatePackageTree(
PackageInterface $package,
InstalledRepository $installedRepo,
RepositoryInterface $remoteRepos
) {
): array {
$requires = $package->getRequires();
ksort($requires);
$children = array();
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -1202,7 +1202,7 @@ protected function addTree(
InstalledRepository $installedRepo,
RepositoryInterface $remoteRepos,
array $packagesInTree
) {
): array {
$children = array();
list($package) = $this->getPackage(
$installedRepo,
Expand Down
10 changes: 5 additions & 5 deletions src/Composer/EventDispatcher/Event.php
Expand Up @@ -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;
}
Expand All @@ -68,7 +68,7 @@ public function getName()
*
* @return string[] The event arguments
*/
public function getArguments()
public function getArguments(): array
{
return $this->args;
}
Expand All @@ -78,7 +78,7 @@ public function getArguments()
*
* @return mixed[] The event flags
*/
public function getFlags()
public function getFlags(): array
{
return $this->flags;
}
Expand All @@ -88,7 +88,7 @@ public function getFlags()
*
* @return bool Whether propagation has been stopped
*/
public function isPropagationStopped()
public function isPropagationStopped(): bool
{
return $this->propagationStopped;
}
Expand All @@ -98,7 +98,7 @@ public function isPropagationStopped()
*
* @return void
*/
public function stopPropagation()
public function stopPropagation(): void
{
$this->propagationStopped = true;
}
Expand Down

0 comments on commit 584d090

Please sign in to comment.