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

EnumerationTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnumeration() 0 4 1
A addEnumoration() 0 7 2
A checkEnumeration() 0 9 4
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