Test Failed
Push — master ( 3b7232...dbe410 )
by Kirill
02:20
created

HasEnumValues::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
 * @mixin ProvidesEnumValues
18
 */
19
trait HasEnumValues
20
{
21
    /**
22
     * @var array|EnumValueDefinition[]
23
     */
24
    protected $values = [];
25
26
    /**
27
     * @return iterable|EnumValueDefinition[]
28
     */
29
    public function getValues(): iterable
30
    {
31
        return \array_values($this->values);
32
    }
33
34
    /**
35
     * @param string $name
36
     * @return bool
37
     */
38
    public function hasValue(string $name): bool
39
    {
40
        return isset($this->values[$name]);
41
    }
42
43
    /**
44
     * @param string $name
45
     * @return null|EnumValueDefinition
46
     */
47
    public function getValue(string $name): ?EnumValueDefinition
48
    {
49
        return $this->values[$name] ?? null;
50
    }
51
52
    /**
53
     * @param EnumValueDefinition ...$values
54
     * @return ProvidesEnumValues|$this
55
     */
56
    public function withValue(EnumValueDefinition ...$values): ProvidesEnumValues
57
    {
58
        foreach ($values as $value) {
59
            $this->values[$value->getName()] = $value;
60
        }
61
62
        return $this;
63
    }
64
}
65