Skip to content

Commit 56c1b11

Browse files
authored
Format code (#5172)
1 parent 67d3ca4 commit 56c1b11

21 files changed

+68
-39
lines changed

src/AbstractCallableDefinitionCollector.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
*/
1212
namespace Hyperf\Di;
1313

14+
use ReflectionNamedType;
15+
use ReflectionParameter;
16+
use ReflectionUnionType;
17+
1418
abstract class AbstractCallableDefinitionCollector extends MetadataCollector
1519
{
1620
/**
17-
* @param array<\ReflectionParameter> $parameters
21+
* @param array<ReflectionParameter> $parameters
1822
*/
1923
protected function getDefinitionsFromParameters(array $parameters): array
2024
{
@@ -38,8 +42,8 @@ protected function createType(string $name, ?\ReflectionType $type, bool $allows
3842
{
3943
// TODO: Support ReflectionUnionType.
4044
$typeName = match (true) {
41-
$type instanceof \ReflectionNamedType => $type->getName(),
42-
$type instanceof \ReflectionUnionType => $type->getTypes()[0]->getName(),
45+
$type instanceof ReflectionNamedType => $type->getName(),
46+
$type instanceof ReflectionUnionType => $type->getTypes()[0]->getName(),
4347
default => 'mixed'
4448
};
4549
return new ReflectionType($typeName, $allowsNull, [

src/Annotation/AnnotationReader.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ReflectionClass;
1616
use ReflectionMethod;
1717
use ReflectionProperty;
18+
use Reflector;
1819

1920
/**
2021
* A reader for docblock annotations.
@@ -79,7 +80,7 @@ public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
7980
return null;
8081
}
8182

82-
public function getAttributes(\Reflector $reflection): array
83+
public function getAttributes(Reflector $reflection): array
8384
{
8485
$result = [];
8586
if (! method_exists($reflection, 'getAttributes')) {

src/Annotation/Aspect.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Hyperf\Di\Annotation;
1313

1414
use Attribute;
15+
use InvalidArgumentException;
1516

1617
#[Attribute(Attribute::TARGET_CLASS)]
1718
class Aspect extends AbstractAnnotation
@@ -40,7 +41,7 @@ protected function collect(string $className)
4041
$annotationPriority = $this->priority;
4142
$propertyPriority = $instancePriority ?: null;
4243
if (! is_null($annotationPriority) && ! is_null($propertyPriority) && $annotationPriority !== $propertyPriority) {
43-
throw new \InvalidArgumentException('Cannot define two difference priority of Aspect.');
44+
throw new InvalidArgumentException('Cannot define two difference priority of Aspect.');
4445
}
4546
$priority = $annotationPriority ?? $propertyPriority;
4647
// Save the metadata to AspectCollector

src/Annotation/Inject.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Hyperf\Di\ReflectionManager;
1717
use Hyperf\Utils\CodeGen\PhpDocReaderManager;
1818
use PhpDocReader\AnnotationException as DocReaderAnnotationException;
19+
use Throwable;
1920

2021
#[Attribute(Attribute::TARGET_PROPERTY)]
2122
class Inject extends AbstractAnnotation
@@ -53,7 +54,7 @@ public function collectProperty(string $className, ?string $target): void
5354
throw new AnnotationException($exception->getMessage());
5455
}
5556
$this->value = '';
56-
} catch (\Throwable $exception) {
57+
} catch (Throwable $exception) {
5758
throw new AnnotationException("The @Inject value is invalid for {$className}->{$target}. Because {$exception->getMessage()}");
5859
}
5960
}

src/Aop/AstVisitorRegistry.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\Di\Aop;
1313

14+
use InvalidArgumentException;
1415
use SplPriorityQueue;
1516

1617
/**
@@ -28,7 +29,7 @@ public static function __callStatic($name, $arguments)
2829
if (method_exists($queue, $name)) {
2930
return $queue->{$name}(...$arguments);
3031
}
31-
throw new \InvalidArgumentException('Invalid method for ' . __CLASS__);
32+
throw new InvalidArgumentException('Invalid method for ' . __CLASS__);
3233
}
3334

3435
public static function insert($value, $priority = 0)

src/Aop/ProceedingJoinPoint.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Hyperf\Di\Annotation\AnnotationCollector;
1616
use Hyperf\Di\Exception\Exception;
1717
use Hyperf\Di\ReflectionManager;
18+
use ReflectionFunction;
19+
use ReflectionMethod;
1820

1921
class ProceedingJoinPoint
2022
{
@@ -78,7 +80,7 @@ public function getArguments()
7880
});
7981
}
8082

81-
public function getReflectMethod(): \ReflectionMethod
83+
public function getReflectMethod(): ReflectionMethod
8284
{
8385
return ReflectionManager::reflectMethod(
8486
$this->className,
@@ -88,7 +90,7 @@ public function getReflectMethod(): \ReflectionMethod
8890

8991
public function getInstance(): ?object
9092
{
91-
$ref = new \ReflectionFunction($this->originalMethod);
93+
$ref = new ReflectionFunction($this->originalMethod);
9294

9395
return $ref->getClosureThis();
9496
}

src/Aop/PropertyHandlerTrait.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Hyperf\Di\Annotation\AnnotationCollector;
1515
use Hyperf\Di\Definition\PropertyHandlerManager;
1616
use Hyperf\Di\ReflectionManager;
17+
use ReflectionClass;
1718

1819
trait PropertyHandlerTrait
1920
{
@@ -54,7 +55,7 @@ protected function __handlePropertyHandler(string $className)
5455
}
5556
}
5657

57-
protected function __handleTrait(\ReflectionClass $reflectionClass, array $handled, string $className): array
58+
protected function __handleTrait(ReflectionClass $reflectionClass, array $handled, string $className): array
5859
{
5960
foreach ($reflectionClass->getTraits() ?? [] as $reflectionTrait) {
6061
if (in_array($reflectionTrait->getName(), [ProxyTrait::class, PropertyHandlerTrait::class])) {

src/Aop/ProxyTrait.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Hyperf\Di\Annotation\AspectCollector;
1717
use Hyperf\Di\ReflectionManager;
1818
use Hyperf\Utils\ApplicationContext;
19+
use SplPriorityQueue;
1920

2021
trait ProxyTrait
2122
{
@@ -62,7 +63,7 @@ protected static function handleAround(ProceedingJoinPoint $proceedingJoinPoint)
6263
if (! AspectManager::has($className, $methodName)) {
6364
AspectManager::set($className, $methodName, []);
6465
$aspects = array_unique(array_merge(static::getClassesAspects($className, $methodName), static::getAnnotationAspects($className, $methodName)));
65-
$queue = new \SplPriorityQueue();
66+
$queue = new SplPriorityQueue();
6667
foreach ($aspects as $aspect) {
6768
$queue->insert($aspect, AspectCollector::getPriority($aspect));
6869
}

src/Aop/RegisterInjectPropertyHandler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Hyperf\Di\Exception\NotFoundException;
1717
use Hyperf\Di\ReflectionManager;
1818
use Hyperf\Utils\ApplicationContext;
19+
use Throwable;
1920

2021
class RegisterInjectPropertyHandler
2122
{
@@ -41,7 +42,7 @@ public static function register()
4142
} elseif ($annotation->required) {
4243
throw new NotFoundException("No entry or class found for '{$annotation->value}'");
4344
}
44-
} catch (\Throwable $throwable) {
45+
} catch (Throwable $throwable) {
4546
if ($annotation->required) {
4647
throw $throwable;
4748
}

src/ClosureDefinitionCollector.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@
1111
*/
1212
namespace Hyperf\Di;
1313

14+
use Closure;
15+
use ReflectionFunction;
16+
1417
class ClosureDefinitionCollector extends AbstractCallableDefinitionCollector implements ClosureDefinitionCollectorInterface
1518
{
1619
protected static array $container = [];
1720

18-
public function getParameters(\Closure $closure): array
21+
public function getParameters(Closure $closure): array
1922
{
2023
$key = spl_object_hash($closure);
2124
if (static::has($key)) {
2225
return static::get($key);
2326
}
24-
$reflectionFunction = new \ReflectionFunction($closure);
27+
$reflectionFunction = new ReflectionFunction($closure);
2528
$parameters = $reflectionFunction->getParameters();
2629

2730
$definitions = $this->getDefinitionsFromParameters($parameters);
2831
static::set($key, $definitions);
2932
return $definitions;
3033
}
3134

32-
public function getReturnType(\Closure $closure): ReflectionType
35+
public function getReturnType(Closure $closure): ReflectionType
3336
{
3437
$key = spl_object_hash($closure) . '@return';
3538
if (static::has($key)) {
3639
return static::get($key);
3740
}
38-
$returnType = (new \ReflectionFunction($closure))->getReturnType();
41+
$returnType = (new ReflectionFunction($closure))->getReturnType();
3942
$type = $this->createType('', $returnType, $returnType ? $returnType->allowsNull() : true);
4043
static::set($key, $type);
4144
return $type;

src/ClosureDefinitionCollectorInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
*/
1212
namespace Hyperf\Di;
1313

14+
use Closure;
15+
1416
interface ClosureDefinitionCollectorInterface
1517
{
1618
/**
1719
* @return ReflectionType[]
1820
*/
19-
public function getParameters(\Closure $closure): array;
21+
public function getParameters(Closure $closure): array;
2022

21-
public function getReturnType(\Closure $closure): ReflectionType;
23+
public function getReturnType(Closure $closure): ReflectionType;
2224
}

src/Definition/DefinitionSource.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Hyperf\Di\ReflectionManager;
1515
use ReflectionFunctionAbstract;
16+
use ReflectionNamedType;
1617

1718
use function class_exists;
1819
use function interface_exists;
@@ -73,7 +74,7 @@ private function getParametersDefinition(ReflectionFunctionAbstract $constructor
7374
}
7475

7576
$parameterType = $parameter->getType();
76-
if ($parameterType instanceof \ReflectionNamedType && ! $parameterType->isBuiltin()) {
77+
if ($parameterType instanceof ReflectionNamedType && ! $parameterType->isBuiltin()) {
7778
$parameters[$index] = new Reference($parameterType->getName());
7879
}
7980
}

src/Exception/CircularDependencyException.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Di\Exception;
1313

14-
class CircularDependencyException extends \RuntimeException
14+
use RuntimeException;
15+
16+
class CircularDependencyException extends RuntimeException
1517
{
1618
protected array $list = [];
1719

tests/Annotation/ScannerTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use HyperfTest\Di\Stub\AspectCollector;
2828
use Mockery;
2929
use PHPUnit\Framework\TestCase;
30+
use ReflectionClass;
3031

3132
/**
3233
* @internal
@@ -56,7 +57,7 @@ public function testGetChangedAspects()
5657
Composer::setLoader($loader);
5758

5859
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
59-
$ref = new \ReflectionClass($scanner);
60+
$ref = new ReflectionClass($scanner);
6061
$property = $ref->getProperty('filesystem');
6162
$property->setAccessible(true);
6263
$property->setValue($scanner, $filesystem = Mockery::mock(Filesystem::class . '[lastModified]'));

tests/AnnotationReaderTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use HyperfTest\Di\Stub\NotFoundAttributeTarget;
1818
use PHPUnit\Framework\TestCase;
1919
use ReflectionClass;
20+
use Throwable;
2021

2122
/**
2223
* @internal
@@ -33,7 +34,7 @@ public function testGetNotFoundAttributesOfClass()
3334
try {
3435
$annotationReader = new AnnotationReader();
3536
$annotationReader->getAttributes($reflectionClass);
36-
} catch (\Throwable $exception) {
37+
} catch (Throwable $exception) {
3738
} finally {
3839
$actual = '';
3940
if (isset($exception)) {
@@ -53,7 +54,7 @@ public function testGetNotFoundAttributesOfMethod()
5354
try {
5455
$annotationReader = new AnnotationReader();
5556
$annotationReader->getAttributes($reflectionMethod);
56-
} catch (\Throwable $exception) {
57+
} catch (Throwable $exception) {
5758
} finally {
5859
$actual = '';
5960
if (isset($exception)) {
@@ -73,7 +74,7 @@ public function testGetNotFoundAttributesOfProperty()
7374
try {
7475
$annotationReader = new AnnotationReader();
7576
$annotationReader->getAttributes($reflectionProperty);
76-
} catch (\Throwable $exception) {
77+
} catch (Throwable $exception) {
7778
} finally {
7879
$actual = '';
7980
if (isset($exception)) {
@@ -87,14 +88,14 @@ public function testIgnoreAnnotations()
8788
{
8889
$reader = new AnnotationReader(['NotExistAnnotation']);
8990

90-
$res = $reader->getClassAnnotations(new \ReflectionClass(FooWithNotExistAnnotation::class));
91+
$res = $reader->getClassAnnotations(new ReflectionClass(FooWithNotExistAnnotation::class));
9192

9293
$this->assertSame(1, count($res));
9394
$this->assertInstanceOf(IgnoreDemoAnnotation::class, $res[0]);
9495

9596
$reader = new AnnotationReader(['NotExistAnnotation', IgnoreDemoAnnotation::class]);
9697

97-
$res = $reader->getClassAnnotations(new \ReflectionClass(FooWithNotExistAnnotation::class));
98+
$res = $reader->getClassAnnotations(new ReflectionClass(FooWithNotExistAnnotation::class));
9899

99100
$this->assertSame([], $res);
100101
}

tests/AnnotationTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Hyperf\Di\ScanHandler\NullScanHandler;
1818
use Mockery;
1919
use PHPUnit\Framework\TestCase;
20+
use ReflectionClass;
2021

2122
/**
2223
* @internal
@@ -32,7 +33,7 @@ protected function tearDown(): void
3233
public function testScanAnnotationsDirectoryNotExist()
3334
{
3435
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
35-
$ref = new \ReflectionClass($scanner);
36+
$ref = new ReflectionClass($scanner);
3637
$method = $ref->getMethod('normalizeDir');
3738
$method->setAccessible(true);
3839

@@ -43,7 +44,7 @@ public function testScanAnnotationsDirectoryNotExist()
4344
public function testScanAnnotationsDirectoryEmpty()
4445
{
4546
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
46-
$ref = new \ReflectionClass($scanner);
47+
$ref = new ReflectionClass($scanner);
4748
$method = $ref->getMethod('normalizeDir');
4849
$method->setAccessible(true);
4950

tests/ClassLoaderTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Hyperf\Di\ClassLoader;
1515
use PHPUnit\Framework\TestCase;
16+
use ReflectionClass;
1617

1718
/**
1819
* @internal
@@ -28,7 +29,7 @@ public function __construct()
2829
}
2930
};
3031

31-
$ref = new \ReflectionClass($class);
32+
$ref = new ReflectionClass($class);
3233
$method = $ref->getMethod('loadDotenv');
3334
$method->setAccessible(true);
3435
$method->invoke($class);

0 commit comments

Comments
 (0)