Passed
Push — master ( 5cb917...3c1566 )
by Sergey
02:41
created

HostnameValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author: Viskov Sergey
4
 * @date  : 4/12/16
5
 * @time  : 1:00 PM
6
 */
7
8
namespace LTDBeget\dns\configurator\validators;
9
10
use Zend\Validator\Hostname;
11
12
/**
13
 * Class HostnameValidator
14
 *
15
 * @package beget\lib\dns\lib\validators
16
 */
17
class HostnameValidator
18
{
19
    /**
20
     * @var HostnameValidator
21
     */
22
    static private $instance = null;
23
24
    /**
25
     * @var Hostname
26
     */
27
    private        $validator;
28
29
    /**
30
     * DomainNameValidator constructor.
31
     */
32 1
    private function __construct() {
33 1
        $this->validator = new Hostname([
34 1
            'allow'         => Hostname::ALLOW_DNS | Hostname::ALLOW_LOCAL,
35
            'useIdnCheck'   => false,
36
            'useTldCheck'   => false
37
        ]);
38 1
    }
39
40
    /**
41
     * @return HostnameValidator
42
     */
43 1
    static private function getInstance() {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
44 1
        return self::$instance ?? self::$instance = new static();
45
    }
46
47
    /**
48
     * @param $hostname
49
     * @return bool
50
     */
51 1
    public static function validate(string $hostname) : bool
52
    {
53 1
        return self::getInstance()->validator->isValid($hostname);
54
    }
55
}
56