Skip to content

Commit

Permalink
Fix confusing method names and return values, refs #1408
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jan 8, 2024
1 parent a564062 commit 584a81a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/Entity/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,27 +275,37 @@ public function getVendor(): string
}

/**
* @return array<string> Vendor and package name
* @return array<string>|null Vendor and package name
*/
public function isGitHub(): array|false
public function getGitHubComponents(): array|null
{
if (Preg::isMatchStrictGroups('{^(?:git://|git@|https?://)github.com[:/]([^/]+)/(.+?)(?:\.git|/)?$}i', $this->getRepository(), $match)) {
return $match;
}

return false;
return null;
}

/**
* @return array<string> Vendor and package name
* @return array<string>|null Vendor and package name
*/
public function isGitLab(): array|false
public function getGitLabComponents(): array|null
{
if (Preg::isMatchStrictGroups('{^(?:git://|git@|https?://)gitlab.com[:/]([^/]+)/(.+?)(?:\.git|/)?$}i', $this->getRepository(), $match)) {
return $match;
}

return false;
return null;
}

public function isGitHub(): bool
{
return (bool) $this->isGitHub();
}

public function isGitLab(): bool
{
return (bool) $this->isGitLab();

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jan 8, 2024

Author Member

Dumbness fixed in f1c5a5a

}

/**
Expand Down Expand Up @@ -362,7 +372,7 @@ public function getGitHubStarsUrl(): string|null
{
if ($this->isGitHub()) {
return $this->getBrowsableRepository() . '/stargazers';
}
}
if ($this->isGitLab()) {
return $this->getBrowsableRepository() . '/-/starrers';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Package/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public function update(IOInterface $io, Config $config, Package $package, VcsRep
);
}

if ($match = $package->isGitHub()) {
if (null !== ($match = $package->getGitHubComponents())) {
$this->updateGitHubInfo($httpDownloader, $package, $match[1], $match[2], $driver);
} elseif ($match = $package->isGitLab()) {
} elseif (null !== ($match = $package->getGitLabComponents())) {
$this->updateGitLabInfo($httpDownloader, $io, $package, $match[1], $match[2], $driver);
} else {
$this->updateReadme($io, $package, $driver);
Expand Down

0 comments on commit 584a81a

Please sign in to comment.