Completed
Push — php-7.1 ( 657403...bab180 )
by SignpostMarv
07:32
created

GroupRef   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 98
ccs 28
cts 32
cp 0.875
rs 10
c 1
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getMin() 0 3 1
A setMin() 0 5 1
A __construct() 0 4 1
A getMax() 0 3 1
A setMax() 0 5 1
A getName() 0 3 1
B getElements() 0 19 5
A loadGroupRef() 0 11 1
A addElement() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
6
7
use BadMethodCallException;
8
use DOMElement;
9
use GoetasWebservices\XML\XSDReader\SchemaReader;
10
11
class GroupRef extends Group implements InterfaceSetMinMax
12
{
13
    /**
14
     * @var Group
15
     */
16
    protected $wrapped;
17
18
    /**
19
     * @var int
20
     */
21
    protected $min = 1;
22
23
    /**
24
     * @var int
25
     */
26
    protected $max = 1;
27
28 45
    public function __construct(Group $group)
29
    {
30 45
        parent::__construct($group->getSchema(), '');
31 45
        $this->wrapped = $group;
32 45
    }
33
34
    public function getMin(): int
35
    {
36
        return $this->min;
37
    }
38
39
    /**
40
     * @return $this
41
     */
42 45
    public function setMin(int $min): self
43
    {
44 45
        $this->min = $min;
45
46 45
        return $this;
47
    }
48
49 1
    public function getMax(): int
50
    {
51 1
        return $this->max;
52
    }
53
54
    /**
55
     * @return $this
56
     */
57 45
    public function setMax(int $max): self
58
    {
59 45
        $this->max = $max;
60
61 45
        return $this;
62
    }
63
64 1
    public function getName(): string
65
    {
66 1
        return $this->wrapped->getName();
67
    }
68
69
    /**
70
     * @return ElementItem[]
71
     */
72 1
    public function getElements(): array
73
    {
74 1
        $elements = $this->wrapped->getElements();
75 1
        if ($this->getMax() > 0 || $this->getMax() === -1) {
76 1
            foreach ($elements as $k => $element) {
77
                if (! ($element instanceof InterfaceSetMinMax)) {
78
                    continue;
79
                }
80 1
                $e = clone $element;
81 1
                $e->setMax($this->getMax());
82 1
83
                /**
84
                 * @var Element|ElementRef|ElementSingle|GroupRef $e
85
                 */
86 1
                $elements[$k] = $e;
87
            }
88
        }
89
90
        return $elements;
91
    }
92
93
    public function addElement(ElementItem $element): void
94 45
    {
95
        throw new BadMethodCallException("Can't add an element for a ref group");
96
    }
97
98 45
    public static function loadGroupRef(
99 45
        Group $referenced,
100
        DOMElement $node
101 45
    ): self {
102 45
        $ref = new self($referenced);
103
        $ref->setDoc(SchemaReader::getDocumentation($node));
104 45
105
        SchemaReader::maybeSetMax($ref, $node);
106
        SchemaReader::maybeSetMin($ref, $node);
107
108
        return $ref;
109
    }
110
}
111