Passed
Push — static-analysis ( d8a1cf...2cdeb5 )
by SignpostMarv
07:38 queued 04:26
created

GroupRef::getElements()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

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