Test Failed
Push — master ( da2c9c...d0cc4d )
by Kirill
02:03
created

HasFields   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 41
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldDefinitions() 0 4 1
A hasFieldDefinition() 0 4 1
A getFieldDefinition() 0 4 1
A addFieldDefinition() 0 4 1
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\ProvidesFields;
13
use Railt\Reflection\Contracts\Definition\Dependent\FieldDefinition;
14
use Railt\Reflection\Exception\TypeConflictException;
15
16
/**
17
 * Trait HasFields
18
 * @mixin ProvidesFields
19
 */
20
trait HasFields
21
{
22
    /**
23
     * @var array|FieldDefinition[]
24
     */
25
    protected $fields = [];
26
27
    /**
28
     * @return iterable|FieldDefinition[]
29
     */
30
    public function getFieldDefinitions(): iterable
31
    {
32
        return \array_values($this->fields);
33
    }
34
35
    /**
36
     * @param string $name
37
     * @return bool
38
     */
39
    public function hasFieldDefinition(string $name): bool
40
    {
41
        return isset($this->fields[$name]);
42
    }
43
44
    /**
45
     * @param string $name
46
     * @return null|FieldDefinition
47
     */
48
    public function getFieldDefinition(string $name): ?FieldDefinition
49
    {
50
        return $this->fields[$name] ?? null;
51
    }
52
53
    /**
54
     * @param FieldDefinition $field
55
     */
56
    public function addFieldDefinition(FieldDefinition $field): void
57
    {
58
        $this->fields[$field->getName()] = $field;
59
    }
60
}
61