Completed
Push — master ( c51bd4...0a1432 )
by Asmir
8s
created

GroupRef::getElements()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 8.6737
c 0
b 0
f 0
cc 6
eloc 10
nc 5
nop 0
crap 6
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 58
    public function __construct(Group $group)
27
    {
28 58
        parent::__construct($group->getSchema(), '');
29 58
        $this->wrapped = $group;
30 58
    }
31
32 58
    public function getMin(): int
33
    {
34 58
        return $this->min;
35
    }
36
37 58
    public function setMin(int $min): void
38
    {
39 58
        $this->min = $min;
40 58
    }
41
42 58
    public function getMax(): int
43
    {
44 58
        return $this->max;
45
    }
46
47 58
    public function setMax(int $max): void
48
    {
49 58
        $this->max = $max;
50 58
    }
51
52 8
    public function getName(): string
53
    {
54 8
        return $this->wrapped->getName();
55
    }
56
57
    /**
58
     * @return ElementItem[]
59
     */
60 7
    public function getElements(): array
61
    {
62 7
        $elements = $this->wrapped->getElements();
63
64 7
        foreach ($elements as $k => $element) {
65
            /**
66
             * @var Element|ElementRef|ElementSingle|GroupRef $e
67
             */
68 7
            $e = clone $element;
69 7
            if ($this->getMax() > 0 || $this->getMax() === -1) {
70 7
                $e->setMax($this->getMax());
71
            }
72
73 7
            if ($this->getMin() > 1 && $e->getMin() === 1) {
74 2
                $e->setMin($this->getMin());
75
            }
76
77 7
            $elements[$k] = $e;
78
        }
79
80 7
        return $elements;
81
    }
82
83
    public function addElement(ElementItem $element): void
84
    {
85
        throw new BadMethodCallException("Can't add an element for a ref group");
86
    }
87
}
88