IPv6Visitor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 10 4
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