Passed
Push — php-7.1 ( ed6d10...451fb2 )
by SignpostMarv
02:49
created

Group::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
declare(strict_types = 1);
3
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute;
4
5
use Closure;
6
use DOMElement;
7
use GoetasWebservices\XML\XSDReader\SchemaReader;
8
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction;
9
use GoetasWebservices\XML\XSDReader\Schema\Schema;
10
11
class Group implements AttributeItem, AttributeContainer
12
{
13
    use AttributeItemTrait;
14
    use AttributeContainerTrait;
15
16
    /**
17
     *
18
     * @var Schema
19
     */
20
    protected $schema;
21
22
    /**
23
    * @var string
24
    */
25
    protected $doc = '';
26
27 45
    public function __construct(Schema $schema, string $name)
28
    {
29 45
        $this->schema = $schema;
30 45
        $this->name = $name;
31 45
    }
32
33
    public function getDoc() : string
34
    {
35
        return $this->doc;
36
    }
37
38
    /**
39
    * @return $this
40
    */
41 45
    public function setDoc(string $doc) : self
42
    {
43 45
        $this->doc = $doc;
44 45
        return $this;
45
    }
46
47
    public function getSchema() : Schema
48
    {
49
        return $this->schema;
50
    }
51
52 45
    public static function findSomethingLikeThis(
53
        SchemaReaderLoadAbstraction $useThis,
54
        Schema $schema,
55
        DOMElement $node,
56
        DOMElement $childNode,
57
        AttributeContainer $addToThis
58
    ) : void {
59
        /**
60
        * @var AttributeItem $attribute
61
        */
62 45
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref"));
63 45
        $addToThis->addAttribute($attribute);
64 45
    }
65
66 45
    public static function loadAttributeGroup(
67
        SchemaReaderLoadAbstraction $schemaReader,
68
        Schema $schema,
69
        DOMElement $node
70
    ) : Closure {
71 45
        $attGroup = new self($schema, $node->getAttribute("name"));
72 45
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
73 45
        $schema->addAttributeGroup($attGroup);
74
75 45
        return function () use (
76 45
            $schemaReader,
77 45
            $schema,
78 45
            $node,
79 45
            $attGroup
80
        ) : void {
81 45
            SchemaReaderLoadAbstraction::againstDOMNodeList(
82 45
                $node,
83 45
                function (
84
                    DOMElement $node,
85
                    DOMElement $childNode
86
                ) use (
87 45
                    $schemaReader,
88 45
                    $schema,
89 45
                    $attGroup
90
                ) : void {
91 45
                    switch ($childNode->localName) {
92 45
                        case 'attribute':
93 45
                            $attribute = Attribute::getAttributeFromAttributeOrRef(
94 45
                                $schemaReader,
95 45
                                $childNode,
96 45
                                $schema,
97 45
                                $node
98
                            );
99 45
                            $attGroup->addAttribute($attribute);
100 45
                            break;
101 45
                        case 'attributeGroup':
102 1
                            self::findSomethingLikeThis(
103 1
                                $schemaReader,
104 1
                                $schema,
105 1
                                $node,
106 1
                                $childNode,
107 1
                                $attGroup
108
                            );
109 1
                            break;
110
                    }
111 45
                }
112
            );
113
        };
114
    }
115
}
116