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

AbstractTypeDefinition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 43.75%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 71
ccs 7
cts 16
cp 0.4375
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getDescription() 0 4 1
A setDescription() 0 4 1
A instanceOf() 0 4 1
A getName() 0 4 1
A fetch() 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;
11
12
use Railt\Reflection\Contracts\Definition\TypeDefinition;
13
use Railt\Reflection\Definition\Behaviour\HasDeprecation;
14
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
15
16
/**
17
 * Class AbstractTypeDefinition
18
 */
19
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition
20
{
21
    use HasDirectives;
22
    use HasDeprecation;
23
24
    /**
25
     * @var string
26
     */
27
    protected $name;
28
29
    /**
30
     * @var string|null
31
     */
32
    protected $description;
33
34
    /**
35
     * AbstractTypeDefinition constructor.
36
     * @param Document $document
37
     * @param string $name
38
     */
39 2
    public function __construct(Document $document, string $name)
40
    {
41 2
        $this->name = $name;
42
43 2
        parent::__construct($document);
44
45 2
        $document->addTypeDefinition($this);
46 2
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getDescription(): string
52
    {
53
        return (string)$this->description;
54
    }
55
56
    /**
57
     * @param null|string $description
58
     */
59
    public function setDescription(?string $description): void
60
    {
61
        $this->description = $description;
62
    }
63
64
    /**
65
     * @param TypeDefinition $definition
66
     * @return bool
67
     */
68
    public function instanceOf(TypeDefinition $definition): bool
69
    {
70
        return $this instanceof $definition;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 2
    public function getName(): string
77
    {
78 2
        return $this->name;
79
    }
80
81
    /**
82
     * @param string $type
83
     * @return TypeDefinition
84
     */
85
    protected function fetch(string $type): TypeDefinition
86
    {
87
        return $this->document->getReflection()->get($type, $this);
88
    }
89
}
90