IPv6Visitor::visit()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 4
nc 3
nop 2
1
<?php
2
3
namespace BenTools\HostnameExtractor\Visitor;
4
5
use BenTools\HostnameExtractor\ParsedHostname;
6
use function BenTools\Violin\string;
7
8
/**
9
 * Class IPv6Visitor
10
 * @internal
11
 */
12
final class IPv6Visitor implements HostnameVisitorInterface
13
{
14
    /**
15
     * @inheritDoc
16
     */
17
    public function visit($hostname, ParsedHostname $parsedHostname): void
18
    {
19
        $hostname = string($hostname);
20
        if ($hostname->startsWith('[') && $hostname->endsWith(']')) {
21
            $ipv6 = (string) $hostname->removeLeft('[')->removeRight(']');
22
            if (\filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
23
                $parsedHostname->setIsIpv6(true);
24
            }
25
        }
26
    }
27
}
28