Passed
Push — master ( db02fd...873e90 )
by Christopher
02:22 queued 48s
created

EnumerationTrait::setEnumeration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Barnso
5
 * Date: 30/06/2017
6
 * Time: 9:17 PM
7
 */
8
9
namespace AlgoWeb\xsdTypes\Facets;
10
11
trait EnumerationTrait
12
{
13
    /**
14
     * @Exclude
15
     * @var array Defines a list of acceptable values
16
     */
17
    private $enumeration = null;
18
19
    protected function setEnumeration(array $enumorationValues)
20
    {
21
        $this->enumeration = $enumorationValues;
22
    }
23
24
    protected function addEnumoration($enumorationValue)
25
    {
26
        if (!is_array($this->enumeration)) {
27
            $this->enumeration = [];
28
        }
29
        $this->enumeration[] = $enumorationValue;
30
    }
31
32
    private function checkEnumeration($v)
33
    {
34
        if (is_array($this->enumeration) && 0 != count($this->enumeration) && !in_array($v, $this->enumeration)) {
35
            throw new \InvalidArgumentException(
36
                "the provided value for " . __CLASS__ . " is not " .
37
                implode(" || ", $this->enumeration)
38
            );
39
        }
40
    }
41
}
42