GroupRef   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
dl 0
loc 80
ccs 26
cts 28
cp 0.9286
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setMin() 0 3 1
A getMax() 0 3 1
A setMax() 0 3 1
A getName() 0 3 1
A getMin() 0 3 1
B getElements() 0 24 6
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
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
        /**
65
         * @var int $k
66
         */
67 7
        foreach ($elements as $k => $element) {
68
            /**
69
             * @var Element|ElementRef|ElementSingle|GroupRef $e
70
             */
71 7
            $e = clone $element;
72 7
            if ($this->getMax() > 0 || $this->getMax() === -1) {
73 7
                $e->setMax($this->getMax());
74
            }
75
76 7
            if ($this->getMin() > 1 && $e->getMin() === 1) {
77 2
                $e->setMin($this->getMin());
78
            }
79
80 7
            $elements[$k] = $e;
81
        }
82
83 7
        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