Passed
Push — master ( fa014f...3ede18 )
by Christopher
01:47
created

EnumerationTrait::checkEnumeration()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 2
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->enumeration[] = $enumerationValue;
29
    }
30
31
    private function checkEnumeration($v)
32
    {
33
        if (is_array($this->enumeration) && 0 != count($this->enumeration) && !in_array($v, $this->enumeration)) {
34
            throw new \InvalidArgumentException(
35
                "The provided value for " . __CLASS__ . " is not " .
36
                implode(" || ", $this->enumeration)
37
            );
38
        }
39
    }
40
}
41