Test Failed
Push — master ( 4bdf7b...97fe68 )
by Kirill
02:15
created

AbstractTypeDefinition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 53.85%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 58
ccs 7
cts 13
cp 0.5385
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDescription() 0 4 1
A withDescription() 0 6 1
A isBuiltin() 0 4 1
A __toString() 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\Definition\Behaviour\HasInheritance;
15
use Railt\Reflection\Definition\Behaviour\HasName;
16
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
17
18
/**
19
 * Class AbstractTypeDefinition
20
 */
21
abstract class AbstractTypeDefinition extends AbstractDefinition implements TypeDefinition
22
{
23
    use HasName;
24
    use HasDirectives;
25
    use HasDeprecation;
26
    use HasInheritance;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $description;
32
33
    /**
34
     * AbstractTypeDefinition constructor.
35
     * @param Document|\Railt\Reflection\Contracts\Document $document
36
     * @param string $name
37
     */
38 9
    public function __construct(Document $document, string $name)
39
    {
40 9
        $this->renameTo($name);
41 9
        parent::__construct($document);
42 9
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getDescription(): string
48
    {
49
        return (string)$this->description;
50
    }
51
52
    /**
53
     * @param null|string $description
54
     * @return TypeDefinition|$this
55
     */
56 9
    public function withDescription(?string $description): TypeDefinition
57
    {
58 9
        $this->description = $description;
59
60 9
        return $this;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isBuiltin(): bool
67
    {
68
        return false;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function __toString(): string
75
    {
76
        return \sprintf('%s<%s>', $this->name ?? '?', static::getType());
77
    }
78
}
79