Completed
Push — master ( 55881e...c51bd4 )
by SignpostMarv
03:05
created

GroupRef   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 76
ccs 22
cts 26
cp 0.8462
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getMin() 0 4 1
A getMax() 0 4 1
A getName() 0 4 1
A __construct() 0 5 1
A setMin() 0 4 1
A setMax() 0 4 1
A getElements() 0 19 4
A addElement() 0 4 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 49
    public function __construct(Group $group)
27
    {
28 49
        parent::__construct($group->getSchema(), '');
29 49
        $this->wrapped = $group;
30 49
    }
31
32
    public function getMin(): int
33
    {
34
        return $this->min;
35
    }
36
37 49
    public function setMin(int $min): void
38
    {
39 49
        $this->min = $min;
40 49
    }
41
42 1
    public function getMax(): int
43
    {
44 1
        return $this->max;
45
    }
46
47 49
    public function setMax(int $max): void
48
    {
49 49
        $this->max = $max;
50 49
    }
51
52 1
    public function getName(): string
53
    {
54 1
        return $this->wrapped->getName();
55
    }
56
57
    /**
58
     * @return ElementItem[]
59
     */
60 1
    public function getElements(): array
61
    {
62 1
        $elements = $this->wrapped->getElements();
63 1
        if ($this->getMax() > 0 || $this->getMax() === -1) {
64
            /**
65
             * @var string $k
66
             */
67 1
            foreach ($elements as $k => $element) {
68
                /**
69
                 * @var Element|ElementRef|ElementSingle|GroupRef $e
70
                 */
71 1
                $e = clone $element;
72 1
                $e->setMax($this->getMax());
73 1
                $elements[$k] = $e;
74
            }
75
        }
76
77 1
        return $elements;
78
    }
79
80
    public function addElement(ElementItem $element): void
81
    {
82
        throw new BadMethodCallException("Can't add an element for a ref group");
83
    }
84
}
85