Test Failed
Push — master ( 97fe68...3f86cd )
by Kirill
42s
created

HasEnumValues   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 59
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValues() 0 4 1
A hasValue() 0 4 1
A getValue() 0 4 1
A withValue() 0 8 2
A withoutValue() 0 8 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Definition\Behaviour;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesEnumValues;
13
use Railt\Reflection\Contracts\Definition\Dependent\EnumValueDefinition;
14
15
/**
16
 * Trait HasEnumValues
17
 */
18
trait HasEnumValues
19
{
20
    /**
21
     * @var array|EnumValueDefinition[]
22
     */
23
    protected $values = [];
24
25
    /**
26
     * @return iterable|EnumValueDefinition[]
27
     */
28
    public function getValues(): iterable
29
    {
30
        return \array_values($this->values);
31
    }
32
33
    /**
34
     * @param string $name
35
     * @return bool
36
     */
37
    public function hasValue(string $name): bool
38
    {
39
        return isset($this->values[$name]);
40
    }
41
42
    /**
43
     * @param string $name
44
     * @return null|EnumValueDefinition
45
     */
46
    public function getValue(string $name): ?EnumValueDefinition
47
    {
48
        return $this->values[$name] ?? null;
49
    }
50
51
    /**
52
     * @param EnumValueDefinition ...$values
53
     * @return ProvidesEnumValues|$this
54
     */
55
    public function withValue(EnumValueDefinition ...$values): ProvidesEnumValues
56
    {
57
        foreach ($values as $value) {
58
            $this->values[$value->getName()] = $value;
59
        }
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param string|EnumValueDefinition ...$values
66
     * @return $this
67
     */
68
    public function withoutValue(...$values)
69
    {
70
        foreach ($values as $value) {
71
            unset($this->values[$this->nameOf($value)]);
72
        }
73
74
        return $this;
75
    }
76
}
77