Skip to content

Commit

Permalink
fix exception message(s), clarify some conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
alcohol committed Nov 12, 2019
1 parent 7a84d01 commit 73f4624
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/PackageSelection/PackageSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public function select(Composer $composer, bool $verbose): array

if (0 === count($repos)) {
throw new \InvalidArgumentException(sprintf('Specified repository url "%s" does not exist.', $this->repositoryFilter));
} elseif (count($repos) > 1) {
}

if (count($repos) > 1) {
throw new \InvalidArgumentException(sprintf('Found more than one repository for url "%s".', $this->repositoryFilter));
}
}
Expand All @@ -163,9 +165,17 @@ public function select(Composer $composer, bool $verbose): array
$repos = $this->filterPackages($repos);

if (0 === count($repos)) {
throw new \InvalidArgumentException(sprintf('Specified package name "%s" does not exist.', $this->packagesFilter));
} elseif (count($repos) > 1) {
throw new \InvalidArgumentException(sprintf('Found more than one package name "%s".', $this->packagesFilter));
throw new \InvalidArgumentException(sprintf(
'Could not find any package(s) matching: %s',
implode(', ', $this->packagesFilter)
));
}

if (count($repos) > 1) {
throw new \InvalidArgumentException(sprintf(
'Found more than one package matching: %s',
implode(', ', $this->packagesFilter)
));
}
}

Expand Down Expand Up @@ -377,7 +387,7 @@ private function createStripHostsPatterns($stripHostsConfig)
} else {
$mask = (int) $mask;

if ($mask < 0 || 'ipv4' === $type && $mask > 32 || 'ipv6' === $type && $mask > 128) {
if ($mask < 0 || ('ipv4' === $type && $mask > 32) || ('ipv6' === $type && $mask > 128)) {
continue;
}
}
Expand Down Expand Up @@ -464,10 +474,10 @@ private function matchStripHostsPatterns(string $url): bool
@list($type, $host, $mask) = $pattern;

if ('/local' === $type) {
if ('name' === $urltype && 'localhost' === strtolower($url)
|| ('ipv4' === $urltype || 'ipv6' === $urltype)
&& false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)
) {
if (('name' === $urltype && 'localhost' === strtolower($url)) || (
('ipv4' === $urltype || 'ipv6' === $urltype) &&
false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)
)) {
return true;
}
} elseif ('/private' === $type) {
Expand Down

0 comments on commit 73f4624

Please sign in to comment.