Skip to content

Commit cd96fa0

Browse files
committed
- code improvements
- add doc comment phpstan & readabilities improvement
1 parent b473be1 commit cd96fa0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/Services/Ipv6Service.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
use function explode;
88
use function is_array;
99
use function is_numeric;
10+
use function reset;
1011
use function str_contains;
1112
use function str_starts_with;
1213

1314
class Ipv6Service extends AbstractRdapService
1415
{
16+
/**
17+
* @var array<string, array{0: string, 1: string}|false> $cidrRanges The RDAP services
18+
*/
1519
private array $cidrRanges = [];
1620

21+
/**
22+
* @inheritDoc
23+
*/
1724
protected function normalizeSource(string $target): string
1825
{
1926
$explode = explode('/', $target);
@@ -30,9 +37,12 @@ protected function normalizeSource(string $target): string
3037
$this->throwInvalidTarget($target);
3138
}
3239

40+
/**
41+
* @inheritDoc
42+
*/
3343
public function normalize(string $target): ?string
3444
{
35-
if (str_contains($target, ':')) {
45+
if (!str_contains($target, ':')) {
3646
return null;
3747
}
3848
if (str_contains($target, '/')) {
@@ -45,26 +55,33 @@ public function normalize(string $target): ?string
4555
return $target;
4656
}
4757

58+
/**
59+
* @inheritDoc
60+
*/
4861
public function getRdapURL(string $target) : ?string
4962
{
5063
$target = $this->normalize($target);
5164
if (!$target) {
5265
return null;
5366
}
5467
[$start] = explode(':', $target);
55-
$start .= ':';
68+
// just take first character
69+
// @previous: $start += ':';
70+
// @patch
71+
$start = $start[0];
5672
foreach ($this->services as $service) {
5773
$urls = $service[1]??[];
74+
$service0 = $service[0]??[];
5875
$url = reset($urls);
59-
if (!$url) {
76+
if (!$url || empty($service0)) {
6077
continue;
6178
}
62-
foreach ($service[0] as $cidr) {
79+
foreach ($service0 as $cidr) {
6380
if (!str_starts_with($cidr, $start)) {
6481
continue;
6582
}
6683
if (!isset($this->cidrRanges[$cidr])) {
67-
$this->cidrRanges[$cidr] = CIDR::ip6cidrToRange($cidr);
84+
$this->cidrRanges[$cidr] = CIDR::ip6cidrToRange($cidr)?:false;
6885
}
6986
if (!is_array($this->cidrRanges[$cidr])) {
7087
continue;

0 commit comments

Comments
 (0)