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