Passed
Branch php-7.1 (52dd08)
by SignpostMarv
03:16
created

Restriction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 84
ccs 13
cts 15
cp 0.8667
rs 10
c 1
b 0
f 0
wmc 8

4 Methods

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