GroupRef::getElements()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

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