Passed
Push — develop ( 45600c...ff69f6 )
by Paul
03:16
created

PhpFileModel::getFullNameUse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace PhpUnitGen\Model;
4
5
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
6
use PhpUnitGen\Model\PropertyTrait\NamespaceTrait;
7
use PhpUnitGen\Model\PropertyTrait\NameTrait;
8
9
/**
10
 * Class PhpFileModel.
11
 *
12
 * @author     Paul Thébaud <[email protected]>.
13
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
14
 * @license    https://opensource.org/licenses/MIT The MIT license.
15
 * @link       https://github.com/paul-thebaud/phpunit-generator
16
 * @since      Class available since Release 2.0.0.
17
 */
18
class PhpFileModel implements PhpFileModelInterface
19
{
20
    // The name trait is used as the file name.
21
    use NameTrait;
22
    use NamespaceTrait;
23
24
    /**
25
     * @var string $path The file path from the main directory.
26
     */
27
    private $path = '';
28
29
    /**
30
     * This array is constructed with the name or the alias as key, and the real namespace, full name as a value.
31
     * @var string[] $uses Imports contained in the file.
32
     */
33
    private $uses = [];
34
35
    /**
36
     * @var FunctionModel[] $functions Functions contained in the file.
37
     */
38
    private $functions = [];
39
40
    /**
41
     * @var ClassModel[] $classes Classes contained in the file.
42
     */
43
    private $classes = [];
44
45
    /**
46
     * @var TraitModel[] $traits Traits contained in the file.
47
     */
48
    private $traits = [];
49
50
    /**
51
     * @var InterfaceModel[] $interfaces Interfaces contained in the file.
52
     */
53
    private $interfaces = [];
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function setPath(string $path): void
59
    {
60
        $this->path = $path;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getPath(): string
67
    {
68
        return $this->path;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function addUse(string $name, string $fullName): void
75
    {
76
        $this->uses[$name] = $fullName;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function hasUse(string $name): bool
83
    {
84
        return isset($this->uses[$name]);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getFullNameUse(string $name): ?string
91
    {
92
        if ($this->hasUse($name)) {
93
            return $this->uses[$name];
94
        }
95
        return null;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getUses(): array
102
    {
103
        return $this->uses;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function addFunction(FunctionModel $function): void
110
    {
111
        $this->functions[] = $function;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getFunctions(): array
118
    {
119
        return $this->functions;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function addClass(ClassModel $class): void
126
    {
127
        $this->classes[] = $class;
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function getClasses(): array
134
    {
135
        return $this->classes;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function addTrait(TraitModel $trait): void
142
    {
143
        $this->traits[] = $trait;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function getTraits(): array
150
    {
151
        return $this->traits;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function addInterface(InterfaceModel $interface): void
158
    {
159
        $this->interfaces[] = $interface;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function getInterfaces(): array
166
    {
167
        return $this->interfaces;
168
    }
169
}