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

HasEnumValues::withoutValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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