Completed
Push — php-7.1 ( d2218e...926e65 )
by SignpostMarv
08:16
created

GroupRef::loadGroupRef()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
6
7
use BadMethodCallException;
8
9
class GroupRef extends Group implements InterfaceSetMinMax
10
{
11
    /**
12
     * @var Group
13
     */
14
    protected $wrapped;
15
16
    /**
17
     * @var int
18
     */
19
    protected $min = 1;
20
21
    /**
22
     * @var int
23
     */
24
    protected $max = 1;
25
26
    public function __construct(Group $group)
27
    {
28 45
        parent::__construct($group->getSchema(), '');
29
        $this->wrapped = $group;
30 45
    }
31 45
32 45
    public function getMin(): int
33
    {
34
        return $this->min;
35
    }
36
37
    /**
38
     * @return $this
39
     */
40
    public function setMin(int $min): self
41
    {
42 45
        $this->min = $min;
43
44 45
        return $this;
45
    }
46 45
47
    public function getMax(): int
48
    {
49 1
        return $this->max;
50
    }
51 1
52
    /**
53
     * @return $this
54
     */
55
    public function setMax(int $max): self
56
    {
57 45
        $this->max = $max;
58
59 45
        return $this;
60
    }
61 45
62
    public function getName(): string
63
    {
64 1
        return $this->wrapped->getName();
65
    }
66 1
67
    /**
68
     * @return ElementItem[]
69
     */
70
    public function getElements(): array
71
    {
72 1
        $elements = $this->wrapped->getElements();
73
        if ($this->getMax() > 0 || $this->getMax() === -1) {
74 1
            foreach ($elements as $k => $element) {
75 1
                if (!($element instanceof InterfaceSetMinMax)) {
76 1
                    continue;
77
                }
78
                $e = clone $element;
79
                $e->setMax($this->getMax());
80 1
81 1
                /**
82 1
                 * @var Element|ElementRef|ElementSingle|GroupRef $e
83
                 */
84
                $elements[$k] = $e;
85
            }
86 1
        }
87
88
        return $elements;
89
    }
90
91
    public function addElement(ElementItem $element): void
92
    {
93
        throw new BadMethodCallException("Can't add an element for a ref group");
94 45
    }
95
}
96