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

HostnameValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstance() 0 3 1
A validate() 0 4 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