Skip to content

Commit 992f441

Browse files
Prefixed all PHP builtin classes with a starting slash
1 parent 3aa2bb5 commit 992f441

File tree

6 files changed

+57
-83
lines changed

6 files changed

+57
-83
lines changed

src/AnnotationLoader.php

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717

1818
namespace Biurad\Annotations;
1919

20-
use FilesystemIterator;
21-
use RecursiveDirectoryIterator;
22-
use RecursiveIteratorIterator;
23-
use ReflectionClass;
24-
use ReflectionClassConstant;
25-
use ReflectionMethod;
26-
use ReflectionParameter;
27-
use ReflectionProperty;
28-
use Reflector;
29-
use RegexIterator;
3020
use Spiral\Attributes\ReaderInterface;
3121

3222
class AnnotationLoader implements LoaderInterface
@@ -133,7 +123,7 @@ private function findAnnotations(string $resource): array
133123
{
134124
$annotations = [];
135125

136-
$classReflection = new ReflectionClass($resource);
126+
$classReflection = new \ReflectionClass($resource);
137127
$className = $classReflection->getName();
138128

139129
if ($classReflection->isAbstract()) {
@@ -158,36 +148,36 @@ private function findAnnotations(string $resource): array
158148
}
159149

160150
/**
161-
* @param Reflector $reflection
151+
* @param \Reflector $reflection
162152
*
163153
* @return iterable<object>
164154
*/
165-
private function getAnnotations(Reflector $reflection): iterable
155+
private function getAnnotations(\Reflector $reflection): iterable
166156
{
167157
$annotations = [];
168158

169159
switch (true) {
170-
case $reflection instanceof ReflectionClass:
160+
case $reflection instanceof \ReflectionClass:
171161
$annotations = $this->reader->getClassMetadata($reflection);
172162

173163
break;
174164

175-
case $reflection instanceof ReflectionMethod:
165+
case $reflection instanceof \ReflectionMethod:
176166
$annotations = $this->reader->getFunctionMetadata($reflection);
177167

178168
break;
179169

180-
case $reflection instanceof ReflectionProperty:
170+
case $reflection instanceof \ReflectionProperty:
181171
$annotations = $this->reader->getPropertyMetadata($reflection);
182172

183173
break;
184174

185-
case $reflection instanceof ReflectionClassConstant:
175+
case $reflection instanceof \ReflectionClassConstant:
186176
$annotations = $this->reader->getConstantMetadata($reflection);
187177

188178
break;
189179

190-
case $reflection instanceof ReflectionParameter:
180+
case $reflection instanceof \ReflectionParameter:
191181
$annotations = $this->reader->getParameterMetadata($reflection);
192182
}
193183

@@ -203,7 +193,7 @@ private function getAnnotations(Reflector $reflection): iterable
203193
}
204194

205195
/**
206-
* @param ReflectionParameter[] $parameters
196+
* @param \ReflectionParameter[] $parameters
207197
*
208198
* @return iterable<int,object[]>
209199
*/
@@ -224,24 +214,24 @@ private function getMethodParameter(array $parameters): iterable
224214
* Fetch annotations from methods, constant, property and methods parameter
225215
*
226216
* @param string $className
227-
* @param Reflector[] $reflections
217+
* @param \Reflector[] $reflections
228218
* @param array<string,array<string,mixed>> $annotations
229219
*
230220
* @return array<string,array<string,mixed>>
231221
*/
232222
private function fetchAnnotations(string $className, array $reflections, array $annotations): array
233223
{
234224
foreach ($reflections as $name => $reflection) {
235-
if ($reflection instanceof ReflectionMethod && $reflection->isAbstract()) {
225+
if ($reflection instanceof \ReflectionMethod && $reflection->isAbstract()) {
236226
continue;
237227
}
238228

239229
if (is_string($name)) {
240-
$reflection = new ReflectionClassConstant($className, $name);
230+
$reflection = new \ReflectionClassConstant($className, $name);
241231
}
242232

243233
foreach ($this->getAnnotations($reflection) as $annotation) {
244-
if ($reflection instanceof ReflectionMethod) {
234+
if ($reflection instanceof \ReflectionMethod) {
245235
$annotations[$className]['method'][] = [$reflection, $annotation];
246236

247237
foreach ($this->getMethodParameter($reflection->getParameters()) as $parameter) {
@@ -251,7 +241,7 @@ private function fetchAnnotations(string $className, array $reflections, array $
251241
continue;
252242
}
253243

254-
if ($reflection instanceof ReflectionClassConstant) {
244+
if ($reflection instanceof \ReflectionClassConstant) {
255245
$annotations[$className]['constant'][] = [$reflection, $annotation];
256246

257247
continue;
@@ -291,11 +281,9 @@ private function findClasses(array $files): array
291281
*/
292282
private function findFiles(string $resource): array
293283
{
294-
$flags = FilesystemIterator::CURRENT_AS_PATHNAME;
295-
296-
$directory = new RecursiveDirectoryIterator($resource, $flags);
297-
$iterator = new RecursiveIteratorIterator($directory);
298-
$files = new RegexIterator($iterator, '/\.php$/');
284+
$directory = new \RecursiveDirectoryIterator($resource, \FilesystemIterator::CURRENT_AS_PATHNAME);
285+
$iterator = new \RecursiveIteratorIterator($directory);
286+
$files = new \RegexIterator($iterator, '/\.php$/');
299287

300288
return \iterator_to_array($files);
301289
}

src/InvalidAnnotationException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
namespace Biurad\Annotations;
1919

20-
use InvalidArgumentException;
21-
22-
class InvalidAnnotationException extends InvalidArgumentException
20+
class InvalidAnnotationException extends \InvalidArgumentException
2321
{
2422
}

tests/AnnotationLoaderTest.php

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
use Biurad\Annotations\AnnotationLoader;
2121
use Doctrine\Common\Annotations\AnnotationRegistry;
2222
use PHPUnit\Framework\TestCase;
23-
use ReflectionClassConstant;
24-
use ReflectionMethod;
25-
use ReflectionParameter;
26-
use ReflectionProperty;
2723
use Spiral\Attributes\AnnotationReader;
2824
use Spiral\Attributes\AttributeReader;
2925

@@ -93,25 +89,25 @@ public function testAttach(): void
9389
], $names);
9490

9591
$this->assertEquals([
96-
['handler' => ReflectionMethod::class, 'priority' => 24],
97-
['handler' => ReflectionProperty::class, 'priority' => 0],
98-
['handler' => ReflectionMethod::class, 'priority' => 0],
99-
['handler' => ReflectionMethod::class, 'priority' => 14],
100-
['handler' => ReflectionMethod::class, 'priority' => 1],
101-
['handler' => ReflectionMethod::class, 'priority' => 0],
102-
['handler' => ReflectionMethod::class, 'priority' => 0],
103-
['handler' => ReflectionMethod::class, 'priority' => 24],
104-
['handler' => ReflectionProperty::class, 'priority' => 0],
105-
['handler' => ReflectionMethod::class, 'priority' => 24],
106-
['handler' => ReflectionProperty::class, 'priority' => 0],
107-
['handler' => ReflectionMethod::class, 'priority' => 24],
108-
['handler' => ReflectionProperty::class, 'priority' => 0],
109-
['handler' => ReflectionMethod::class, 'priority' => 0],
110-
['handler' => ReflectionMethod::class, 'priority' => 0],
111-
['handler' => ReflectionProperty::class, 'priority' => 4],
112-
['handler' => ReflectionMethod::class, 'priority' => 323],
113-
['handler' => ReflectionProperty::class, 'priority' => 0],
114-
['handler' => ReflectionProperty::class, 'priority' => 0],
92+
['handler' => \ReflectionMethod::class, 'priority' => 24],
93+
['handler' => \ReflectionProperty::class, 'priority' => 0],
94+
['handler' => \ReflectionMethod::class, 'priority' => 0],
95+
['handler' => \ReflectionMethod::class, 'priority' => 14],
96+
['handler' => \ReflectionMethod::class, 'priority' => 1],
97+
['handler' => \ReflectionMethod::class, 'priority' => 0],
98+
['handler' => \ReflectionMethod::class, 'priority' => 0],
99+
['handler' => \ReflectionMethod::class, 'priority' => 24],
100+
['handler' => \ReflectionProperty::class, 'priority' => 0],
101+
['handler' => \ReflectionMethod::class, 'priority' => 24],
102+
['handler' => \ReflectionProperty::class, 'priority' => 0],
103+
['handler' => \ReflectionMethod::class, 'priority' => 24],
104+
['handler' => \ReflectionProperty::class, 'priority' => 0],
105+
['handler' => \ReflectionMethod::class, 'priority' => 0],
106+
['handler' => \ReflectionMethod::class, 'priority' => 0],
107+
['handler' => \ReflectionProperty::class, 'priority' => 4],
108+
['handler' => \ReflectionMethod::class, 'priority' => 323],
109+
['handler' => \ReflectionProperty::class, 'priority' => 0],
110+
['handler' => \ReflectionProperty::class, 'priority' => 0],
115111
['handler' => Fixtures\Annotation\Valid\SingleClass::class, 'priority' => 0],
116112
], $result);
117113
}
@@ -142,16 +138,16 @@ public function testAttachAttribute(): void
142138
}
143139

144140
$this->assertEquals([
145-
'attribute_specific_name' => ['handler' => ReflectionMethod::class, 'priority' => 0],
146-
'attribute_specific_none' => ['handler' => ReflectionMethod::class, 'priority' => 14],
147-
'attribute_property' => ['handler' => ReflectionProperty::class, 'priority' => 0],
148-
'attribute_constant' => ['handler' => ReflectionClassConstant::class, 'priority' => 0],
149-
'attribute_method_property' => ['handler' => ReflectionParameter::class, 'priority' => 4],
150-
'attribute_added_specific_name' => ['handler' => ReflectionMethod::class, 'priority' => 0],
151-
'attribute_added_specific_none' => ['handler' => ReflectionMethod::class, 'priority' => 14],
152-
'attribute_added_property' => ['handler' => ReflectionProperty::class, 'priority' => 0],
153-
'attribute_added_constant' => ['handler' => ReflectionClassConstant::class, 'priority' => 0],
154-
'attribute_added_method_property' => ['handler' => ReflectionParameter::class, 'priority' => 4],
141+
'attribute_specific_name' => ['handler' => \ReflectionMethod::class, 'priority' => 0],
142+
'attribute_specific_none' => ['handler' => \ReflectionMethod::class, 'priority' => 14],
143+
'attribute_property' => ['handler' => \ReflectionProperty::class, 'priority' => 0],
144+
'attribute_constant' => ['handler' => \ReflectionClassConstant::class, 'priority' => 0],
145+
'attribute_method_property' => ['handler' => \ReflectionParameter::class, 'priority' => 4],
146+
'attribute_added_specific_name' => ['handler' => \ReflectionMethod::class, 'priority' => 0],
147+
'attribute_added_specific_none' => ['handler' => \ReflectionMethod::class, 'priority' => 14],
148+
'attribute_added_property' => ['handler' => \ReflectionProperty::class, 'priority' => 0],
149+
'attribute_added_constant' => ['handler' => \ReflectionClassConstant::class, 'priority' => 0],
150+
'attribute_added_method_property' => ['handler' => \ReflectionParameter::class, 'priority' => 4],
155151
], $result);
156152
}
157153
}

tests/Fixtures/Sample.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
namespace Biurad\Annotations\Tests\Fixtures;
1919

20-
use InvalidArgumentException;
21-
2220
/**
2321
* Annotation class for @Listener().
2422
*
@@ -53,14 +51,14 @@ public function __construct($data = null, string $name = null, int $priority = 0
5351
$this->priority = $data['priority'] ?? $priority;
5452

5553
if (empty($this->name) || !\is_string($this->name)) {
56-
throw new InvalidArgumentException(\sprintf(
54+
throw new \InvalidArgumentException(\sprintf(
5755
'@Sample.name must %s.',
5856
empty($this->event) ? 'be not an empty string' : 'contain only a string'
5957
));
6058
}
6159

6260
if (!\is_integer($this->priority)) {
63-
throw new InvalidArgumentException('@Sample.priority must contain only an integer');
61+
throw new \InvalidArgumentException('@Sample.priority must contain only an integer');
6462
}
6563
}
6664

tests/Fixtures/SampleCollector.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace Biurad\Annotations\Tests\Fixtures;
1919

20-
use ArrayObject;
21-
use Reflector;
22-
2320
class SampleCollector
2421
{
2522
private $collected = [];
@@ -32,16 +29,16 @@ class SampleCollector
3229
public function add(string $name, int $priority, $handler): void
3330
{
3431
$this->collected[$name] = [
35-
'handler' => $handler instanceof Reflector ? \get_class($handler) : $handler,
32+
'handler' => $handler instanceof \Reflector ? \get_class($handler) : $handler,
3633
'priority' => $priority,
3734
];
3835
}
3936

4037
/**
41-
* @return ArrayObject
38+
* @return \ArrayObject
4239
*/
43-
public function getCollected(): ArrayObject
40+
public function getCollected(): \ArrayObject
4441
{
45-
return new ArrayObject($this->collected);
42+
return new \ArrayObject($this->collected);
4643
}
4744
}

tests/Fixtures/SampleListener.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
namespace Biurad\Annotations\Tests\Fixtures;
1919

2020
use Biurad\Annotations\ListenerInterface;
21-
use ReflectionMethod;
22-
use ReflectionProperty;
23-
use Reflector;
2421

2522
class SampleListener implements ListenerInterface
2623
{
@@ -76,9 +73,9 @@ public function onAnnotation(array $annotations): SampleCollector
7673
}
7774

7875
/**
79-
* @param Sample $annotation
80-
* @param Reflector|string $handler
81-
* @param null|Sample $group
76+
* @param Sample $annotation
77+
* @param \Reflector|string $handler
78+
* @param null|Sample $group
8279
*/
8380
private function addSample(Sample $annotation, $handler, ?Sample $group = null): void
8481
{
@@ -101,7 +98,7 @@ private function addSampleGroup(array $groups, array $collection): void
10198
{
10299
$handleCollection = function (array $collection, ?Sample $group = null): void {
103100
/**
104-
* @var ReflectionMethod|ReflectionProperty $reflector
101+
* @var \ReflectionMethod|\ReflectionProperty $reflector
105102
* @var Sample $annotation
106103
*/
107104
foreach ($collection as [$reflector, $annotation]) {

0 commit comments

Comments
 (0)