Passed
Push — php-7.1 ( 52dd08...541704 )
by SignpostMarv
01:57
created

Restriction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 86
ccs 14
cts 16
cp 0.875
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addCheck() 0 4 1
A getChecksByType() 0 3 2
B loadRestriction() 0 49 4
A getChecks() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
namespace GoetasWebservices\XML\XSDReader\Schema\Inheritance;
4
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
7
use GoetasWebservices\XML\XSDReader\SchemaReader;
8
9
class Restriction extends Base
10
{
11
    /**
12
    * @var mixed[][]
13
    */
14
    protected $checks = array();
15
16
    /**
17
    * @param string $type
18
    * @param mixed[] $value
19
    *
20
    * @return $this
21
    */
22 45
    public function addCheck(string $type, array $value)
23
    {
24 45
        $this->checks[$type][] = $value;
25 45
        return $this;
26
    }
27
28
    /**
29
    * @return mixed[][]
30
    */
31 10
    public function getChecks() : array
32
    {
33 10
        return $this->checks;
34
    }
35
36
    /**
37
    * @param string $type
38
    *
39
    * @return mixed[]
40
    */
41
    public function getChecksByType(string $type) : array
42
    {
43
        return isset($this->checks[$type])?$this->checks[$type]:array();
44
    }
45
46 45
    public static function loadRestriction(
47
        SchemaReader $reader,
48
        Type $type,
49
        DOMElement $node
50
    ) : void {
51 45
        $restriction = new Restriction();
52 45
        $type->setRestriction($restriction);
53 45
        if ($node->hasAttribute("base")) {
54 45
            $reader->findAndSetSomeBase($type, $restriction, $node);
55
        } else {
56 45
            $addCallback = function (Type $restType) use (
57 45
                $restriction
58
            ) : void {
59 45
                $restriction->setBase($restType);
60 45
            };
61
62
            Type::loadTypeWithCallbackOnChildNodes(
63
                $reader,
64
                $type->getSchema(),
65
                $node,
66
                $addCallback
67
            );
68
        }
69
        foreach ($node->childNodes as $childNode) {
70
            if (
71
                in_array(
72
                    $childNode->localName,
73
                    [
74
                        'enumeration',
75
                        'pattern',
76
                        'length',
77
                        'minLength',
78
                        'maxLength',
79
                        'minInclusive',
80
                        'maxInclusive',
81
                        'minExclusive',
82
                        'maxExclusive',
83
                        'fractionDigits',
84
                        'totalDigits',
85
                        'whiteSpace'
86
                    ],
87
                    true
88
                )
89
            ) {
90
                $restriction->addCheck(
91
                    $childNode->localName,
92
                    [
93
                        'value' => $childNode->getAttribute("value"),
94
                        'doc' => SchemaReader::getDocumentation($childNode)
95
                    ]
96
                );
97
            }
98
        }
99
    }
100
}
101