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

HasTypeIndication   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 65
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeDefinition() 0 6 1
A isList() 0 5 1
A isNonNull() 0 5 1
A isListOfNonNulls() 0 5 1
A setModifiers() 0 4 1
A setTypeDefinition() 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\ProvidesTypeIndication;
13
use Railt\Reflection\Contracts\Definition\TypeDefinition;
14
15
/**
16
 * Trait HasTypeIndication
17
 * @mixin ProvidesTypeIndication
18
 */
19
trait HasTypeIndication
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $definition;
25
26
    /**
27
     * @var int
28
     */
29
    protected $modifiers = 0b0000;
30
31
    /**
32
     * @return TypeDefinition
33
     */
34
    public function getTypeDefinition(): TypeDefinition
35
    {
36
        \assert(\is_string($this->definition));
37
38
        return $this->fetch($this->definition);
0 ignored issues
show
Bug introduced by
It seems like fetch() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isList(): bool
45
    {
46
        return ProvidesTypeIndication::IS_LIST ===
47
            ($this->modifiers & ProvidesTypeIndication::IS_LIST);
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function isNonNull(): bool
54
    {
55
        return ProvidesTypeIndication::IS_NOT_NULL ===
56
            ($this->modifiers & ProvidesTypeIndication::IS_NOT_NULL);
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function isListOfNonNulls(): bool
63
    {
64
        return ProvidesTypeIndication::IS_LIST_OF_NOT_NULL ===
65
            ($this->modifiers & ProvidesTypeIndication::IS_LIST_OF_NOT_NULL);
66
    }
67
68
    /**
69
     * @param int $value
70
     */
71
    public function setModifiers(int $value): void
72
    {
73
        $this->modifiers |= $value;
74
    }
75
76
    /**
77
     * @param string $name
78
     */
79
    public function setTypeDefinition(string $name): void
80
    {
81
        $this->definition = $name;
82
    }
83
}
84