Completed
Push — master ( da8fcc...d64df6 )
by Asmir
02:56
created

GroupRef::addElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
3
4
use GoetasWebservices\XML\XSDReader\Schema\Item;
5
6
class GroupRef extends Group
7
{
8
9
    protected $wrapped;
10
11
    protected $min = 1;
12
13
    protected $max = 1;
14
15 39
    public function __construct(Group $group)
16
    {
17 39
        parent::__construct($group->getSchema(), '');
18 39
        $this->wrapped = $group;
19 39
    }
20
21
    public function getMin()
22
    {
23
        return $this->min;
24
    }
25
26 39
    public function setMin($min)
27
    {
28 39
        $this->min = $min;
29 39
        return $this;
30
    }
31
32
    public function getMax()
33
    {
34
        return $this->max;
35
    }
36
37 39
    public function setMax($max)
38
    {
39 39
        $this->max = $max;
40 39
        return $this;
41
    }
42
43 1
    public function getName()
44
    {
45 1
        return $this->wrapped->getName();
46
    }
47
48
    public function setName($name)
49
    {
50
        throw new \Exception("Can't set the name for a ref group");
51
    }
52
53
    public function getElements()
54
    {
55
        $elements = $this->wrapped->getElements();
56
        if($this->getMax()>0 || $this->getMax()===-1){
57
            foreach ($elements as $k => $element) {
58
                $e = clone $element;
59
                $e->setMax($this->getMax());
60
                $elements[$k] = $e;
61
            }
62
        }
63
        return $elements;
64
    }
65
66
    public function addElement(ElementItem $element)
67
    {
68
        throw new \Exception("Can't set the name for a ref group");
69
    }
70
}
71