TldVisitor::visit()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
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 TldVisitor
10
 * @internal
11
 */
12
final class TldVisitor implements HostnameVisitorInterface
13
{
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function visit($hostname, ParsedHostname $parsedHostname): void
19
    {
20
        if (null !== $parsedHostname->getSuffix()) {
21
            $suffix = string($parsedHostname->getSuffix());
22
            if ($suffix->contains('.')) {
23
                $suffixParts = \explode('.', (string) $suffix);
24
                $parsedHostname->setTld(\array_pop($suffixParts));
25
            } else {
26
                $parsedHostname->setTld((string) $suffix);
27
            }
28
        }
29
    }
30
}
31