Test Failed
Push — master ( 1b72cc...b6de3d )
by Kirill
05:40
created

Document::getLine()   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 0
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;
11
12
use Railt\Io\File;
13
use Railt\Io\Readable;
14
use Railt\Reflection\Common\Serializable;
15
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesTypeDefinitions;
16
use Railt\Reflection\Contracts\Definition\TypeDefinition;
17
use Railt\Reflection\Contracts\Dictionary;
18
use Railt\Reflection\Contracts\Document as DocumentInterface;
19
use Railt\Reflection\Contracts\Reflection as ReflectionInterface;
20
use Railt\Reflection\Contracts\Type as TypeInterface;
21
use Railt\Reflection\Definition\Behaviour\HasDefinitions;
22
use Railt\Reflection\Invocation\Behaviour\HasDirectives;
23
24
/**
25
 * Class Document
26
 */
27
class Document extends AbstractDefinition implements DocumentInterface
28
{
29
    use Serializable;
30
    use HasDirectives;
31
    use HasDefinitions {
32
        withDefinition as private __withDefinition;
33
    }
34
35
    /**
36
     * @var Readable
37
     */
38
    protected $file;
39
40
    /**
41
     * @var Reflection
42
     */
43
    protected $dictionary;
44
45
    /**
46
     * DocumentDefinition constructor.
47
     * @param Reflection|ReflectionInterface $parent
48
     * @param Readable|null $file
49
     */
50 9
    public function __construct(Reflection $parent, Readable $file = null)
51
    {
52 9
        $this->file = $file ?? File::fromSources('');
53 9
        $this->dictionary = $parent;
54
55 9
        parent::__construct($this);
56
57 9
        $parent->addDocument($this);
58 9
    }
59
60
    /**
61
     * @return TypeInterface
62
     */
63
    public static function getType(): TypeInterface
64
    {
65
        return Type::of(Type::DOCUMENT);
66
    }
67
68
    /**
69
     * @return Readable
70
     */
71 1
    public function getFile(): Readable
72
    {
73 1
        return $this->file;
74
    }
75
76
    /**
77
     * @return ReflectionInterface|Reflection|Dictionary
78
     */
79 11
    public function getDictionary(): Dictionary
80
    {
81 11
        return $this->dictionary;
82
    }
83
84
    /**
85
     * @return bool
86
     */
87
    public function isDeprecated(): bool
88
    {
89
        return false;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getDeprecationReason(): string
96
    {
97
        return '';
98
    }
99
100
    /**
101
     * @return string
102
     */
103 17
    public function getName(): string
104
    {
105 17
        return $this->file->isFile()
106 9
            ? \basename($this->file->getPathname())
107 17
            : $this->file->getPathname();
108
    }
109
110
    /**
111
     * @param string|TypeDefinition $type
112
     * @return ProvidesTypeDefinitions
113
     */
114 17
    public function withDefinition($type): ProvidesTypeDefinitions
115
    {
116 17
        if ($type instanceof TypeDefinition) {
117 17
            $this->dictionary->add($type);
118
        }
119
120 17
        return $this->__withDefinition($type);
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function __toString(): string
127
    {
128
        return \sprintf('%s<%s>', $this->getName(), static::getType());
129
    }
130
131
    /**
132
     * @return int
133
     */
134
    public function getLine(): int
135
    {
136
        return 0;
137
    }
138
139
    /**
140
     * @return int
141
     */
142 1
    public function getColumn(): int
143
    {
144 1
        return 0;
145
    }
146
}
147