Passed
Push — static-analysis ( 0c4f4f...d5a974 )
by SignpostMarv
03:25
created

Type::setDoc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Type;
3
4
use Closure;
5
use DOMNode;
6
use DOMElement;
7
use GoetasWebservices\XML\XSDReader\SchemaReader;
8
use GoetasWebservices\XML\XSDReader\Schema\Schema;
9
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem;
10
use GoetasWebservices\XML\XSDReader\Schema\SchemaItemTrait;
11
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Extension;
12
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction;
13
abstract class Type implements SchemaItem
14
{
15
    use SchemaItemTrait;
16
17
    /**
18
    * @var string|null
19
    */
20
    protected $name;
21
22
    /**
23
    * @var bool
24
    */
25
    protected $abstract = false;
26
27
    /**
28
     *
29
     * @var Restriction|null
30
     */
31
    protected $restriction;
32
33
    /**
34
     *
35
     * @var Extension|null
36
     */
37
    protected $extension;
38
39
    /**
40
    * @param string|null $name
41
    */
42 135
    public function __construct(Schema $schema, $name = null)
43
    {
44 135
        $this->name = $name?:null;
45 135
        $this->schema = $schema;
46 135
    }
47
48
    /**
49
    * @return string|null
50
    */
51 135
    public function getName()
52
    {
53 135
        return $this->name;
54
    }
55
56
    /**
57
    * @param string $name
58
    *
59
    * @return $this
60
    */
61
    public function setName($name)
62
    {
63
        $this->name = $name;
64
        return $this;
65
    }
66
67
    public function __toString()
68
    {
69
        return strval($this->name);
70
    }
71
72
    /**
73
    * @return bool
74
    */
75
    public function isAbstract()
76
    {
77
        return $this->abstract;
78
    }
79
80
    /**
81
    * @param bool $abstract
82
    *
83
    * @return $this
84
    */
85 135
    public function setAbstract($abstract)
86
    {
87 135
        $this->abstract = $abstract;
88 135
        return $this;
89
    }
90
91
    /**
92
     *
93
     * @return Restriction|Extension|null
94
    */
95
    public function getParent()
96
    {
97
        return $this->restriction ?  : $this->extension;
98
    }
99
100
    /**
101
    * @return Restriction|null
102
    */
103
    public function getRestriction()
104
    {
105
        return $this->restriction;
106
    }
107
108
    /**
109
    * @return $this
110
    */
111 135
    public function setRestriction(Restriction $restriction)
112
    {
113 135
        $this->restriction = $restriction;
114 135
        return $this;
115
    }
116
117
    /**
118
    * @return Extension|null
119
    */
120 9
    public function getExtension()
121
    {
122 9
        return $this->extension;
123
    }
124
125
    /**
126
    * @return $this
127
    */
128 135
    public function setExtension(Extension $extension)
129
    {
130 135
        $this->extension = $extension;
131 135
        return $this;
132
    }
133
134 135
    public static function loadTypeWithCallbackOnChildNodes(
135
        SchemaReader $schemaReader,
136
        Schema $schema,
137
        DOMNode $node,
138
        Closure $callback
139
    ) {
140 135
        foreach ($node->childNodes as $childNode) {
141 135
            static::loadTypeWithCallback(
142 135
                $schemaReader,
143 135
                $schema,
144 135
                $childNode,
145 90
                $callback
146 45
            );
147 45
        }
148 135
    }
149
150 135
    public static function loadTypeWithCallback(
151
        SchemaReader $schemaReader,
152
        Schema $schema,
153
        DOMNode $childNode,
154
        Closure $callback
155
    ) {
156 135
        if (! ($childNode instanceof DOMElement)) {
157 135
            return;
158
        }
159
        $methods = [
160 135
            'complexType' => 'loadComplexType',
161 45
            'simpleType' => 'loadSimpleType',
162 45
        ];
163
164 135
        $func = $schemaReader->maybeCallMethod(
165 135
            $methods,
166 135
            $childNode->localName,
167 135
            $childNode,
168 135
            $schema,
169 135
            $childNode,
170 90
            $callback
171 45
        );
172
173 135
        if ($func instanceof Closure) {
174 135
            call_user_func($func);
175 45
        }
176 135
    }
177
}
178