Passed
Push — master ( 78d773...f66cb5 )
by Sergey
03:07
created

DnsZoneDomainNameValidator::validate()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4
Metric Value
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 8.9197
cc 4
eloc 11
nc 4
nop 1
crap 4
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
/**
11
 * Class DnsZoneDomainNameValidator
12
 *
13
 * @package beget\lib\dns\lib\validators
14
 */
15
class DnsZoneDomainNameValidator
16
{
17
    /**
18
     * @param $hostname
19
     * @return bool
20
     */
21 1
    public static function validate(string $hostname) : bool 
22
    {
23 1
        $hostname = preg_replace('/^\*\./', '', $hostname); // wild card allowed in hostname
24
25 1
        if(in_array($hostname, ['@', '*', '.'])) {
26 1
            return true;
27
        }
28
29 1
        $hostnameValidation = HostnameValidator::validate($hostname);
30
31 1
        if ($hostnameValidation) {
32 1
            return true;
33
        }
34
        
35 1
        $ipValidation = Ip4Validator::validate($hostname);
36
37 1
        if ($ipValidation) {
38 1
            return true;
39
        }
40
41 1
        return false;
42
    }
43
}
44