Passed
Push — master ( 74fe39...1bab75 )
by Christopher
02:23
created

EnumerationTrait::handleAddArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
namespace AlgoWeb\xsdTypes\Facets;
3
4
trait EnumerationTrait
5
{
6
    /**
7
     * @Exclude
8
     * @var array Defines a list of acceptable values
9
     */
10
    private $enumeration = null;
11
12
    /**
13
     * @param array $enumerationValues Defines a list of acceptable values
14
     */
15
    protected function setEnumeration(array $enumerationValues)
16
    {
17
        $this->enumeration = $enumerationValues;
18
    }
19
20
    /**
21
     * @param string $enumerationValue adds a value to the enumeration set
22
     */
23
    protected function addEnumeration($enumerationValue)
24
    {
25
        if (!is_array($this->enumeration)) {
26
            $this->enumeration = [];
27
        }
28
        $this->handleAddArray($enumerationValue) ? :$this->enumeration[] = $enumerationValue;
29
    }
30
    /**
31
     * @param string $enumerationValue adds a value to the enumeration set
32
     */
33
    private function handleAddArray($enumerationValue)
34
    {
35
        if (!is_array($enumerationValue)) {
36
            return false;
37
        }
38
        foreach ($enumerationValue as $eValue) {
39
            $this->addEnumeration($eValue);
40
        }
41
        return;
42
    }
43
        
44
45
    private function checkEnumeration($v)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
46
    {
47
        if (is_array($this->enumeration) && 0 != count($this->enumeration) && !in_array($v, $this->enumeration)) {
48
            throw new \InvalidArgumentException(
49
                'The provided value for ' . get_class($this) . ' is not ' .
50
                implode(' || ', $this->enumeration)
51
            );
52
        }
53
    }
54
}
55