Passed
Branch php-7.1 (52dd08)
by SignpostMarv
03:16
created

GroupRef   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
dl 0
loc 113
ccs 28
cts 34
cp 0.8235
rs 10
c 0
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setMin() 0 4 1
A __construct() 0 4 1
A getMax() 0 3 1
A getMin() 0 3 1
A setName() 0 3 1
A setMax() 0 4 1
A loadGroupRef() 0 9 1
A getName() 0 3 1
A addElement() 0 3 1
A getElements() 0 14 4
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
3
4
use BadMethodCallException;
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\SchemaReader;
7
8
class GroupRef extends Group implements InterfaceSetMinMax
9
{
10
    /**
11
    * @var Group
12
    */
13
    protected $wrapped;
14
15
    /**
16
    * @var int
17
    */
18
    protected $min = 1;
19
20
    /**
21
    * @var int
22
    */
23
    protected $max = 1;
24
25 45
    public function __construct(Group $group)
26
    {
27 45
        parent::__construct($group->getSchema(), '');
28 45
        $this->wrapped = $group;
29 45
    }
30
31
    /**
32
    * @return int
33
    */
34
    public function getMin()
35
    {
36
        return $this->min;
37
    }
38
39
    /**
40
    * @param int $min
41
    *
42
    * @return $this
43
    */
44 45
    public function setMin($min)
45
    {
46 45
        $this->min = $min;
47 45
        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 45
    public function setMax($max)
64
    {
65 45
        $this->max = $max;
66 45
        return $this;
67
    }
68
69
    /**
70
    * @return string
71
    */
72 1
    public function getName()
73
    {
74 1
        return $this->wrapped->getName();
75
    }
76
77
    /**
78
    * @param string $name
79
    */
80
    public function setName($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

80
    public function setName(/** @scrutinizer ignore-unused */ $name)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        throw new BadMethodCallException("Can't set the name for a ref group");
83
    }
84
85
    /**
86
    * @return ElementItem[]
87
    */
88 1
    public function getElements()
89
    {
90 1
        $elements = $this->wrapped->getElements();
91 1
        if($this->getMax()>0 || $this->getMax()===-1){
92 1
            foreach ($elements as $k => $element) {
93
                /**
94
                * @var Element|ElementRef|ElementSingle|GroupRef $e
95
                */
96 1
                $e = clone $element;
97 1
                $e->setMax($this->getMax());
98 1
                $elements[$k] = $e;
99
            }
100
        }
101 1
        return $elements;
102
    }
103
104
    public function addElement(ElementItem $element)
105
    {
106
        throw new BadMethodCallException("Can't add an element for a ref group");
107
    }
108
109
    /**
110
    * @return GroupRef
111
    */
112 45
    public static function loadGroupRef(Group $referenced, DOMElement $node)
113
    {
114 45
        $ref = new GroupRef($referenced);
115 45
        $ref->setDoc(SchemaReader::getDocumentation($node));
116
117 45
        SchemaReader::maybeSetMax($ref, $node);
118 45
        SchemaReader::maybeSetMin($ref, $node);
119
120 45
        return $ref;
121
    }
122
}
123