Passed
Pull Request — master (#17)
by Sergey
02:57
created

OutOfZoneDataValidator::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.7898

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 5
cts 9
cp 0.5556
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 3.7898
1
<?php
2
/**
3
 * @author: Viskov Sergey
4
 * @date  : 7/15/16
5
 * @time  : 6:55 PM
6
 */
7
8
namespace LTDBeget\dns\configurator\validators;
9
10
use LTDBeget\dns\configurator\zoneEntities\Node;
11
12
/**
13
 * Class OutOfZoneDataValidator
14
 *
15
 * @package LTDBeget\dns\configurator\validators
16
 */
17
class OutOfZoneDataValidator
18
{
19
    /**
20
     * @param Node $node
21
     * @return bool
22
     */
23 1
    public static function validate(Node $node) : bool
24
    {
25 1
        $origin   = $node->getZone()->getOrigin();
26 1
        $nodeName = $node->getName();
27
28 1
        if (substr($nodeName, -1) !== '.') {
29 1
            return true;
30
        }
31
        $pattern = "/{$origin}\.$/";
32
        if (preg_match($pattern, $nodeName)) {
33
            return true;
34
        }
35
36
        return false;
37
    }
38
39
}