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