From 995bf54d8d3aa3dbad6780f0fdad233a2c8c4591 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 30 Nov 2024 18:43:28 +0900 Subject: [PATCH] Refactor and update dependencies for stability. Added type annotations and exception handling to improve code clarity and reliability. Updated the PHPStan dependency to a newer version for enhanced static analysis and to benefit from bug fixes. These changes help maintain better code quality and alignment with best practices. --- src/AirInjector.php | 3 ++- src/CachedInjectorFactory.php | 1 + src/InjectionPoint.php | 13 +++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/AirInjector.php b/src/AirInjector.php index fc590c8..1081c59 100644 --- a/src/AirInjector.php +++ b/src/AirInjector.php @@ -77,9 +77,10 @@ public function getInstance($interface, $name = Name::ANY) throw new Unbound($dependencyIndex); } - /** @var mixed $instance */ + /** @psalm-suppress UnsupportedPropertyReferenceUsage */ $singletons = &$this->singletons; $scriptDir = $this->scriptDir; + /** @var mixed $instance */ $instance = require $scriptFile; // Save singleton diff --git a/src/CachedInjectorFactory.php b/src/CachedInjectorFactory.php index 2329490..f6e5a5a 100644 --- a/src/CachedInjectorFactory.php +++ b/src/CachedInjectorFactory.php @@ -38,6 +38,7 @@ public static function getInstance(string $injectorId, string $scriptDir, callab /** @psalm-suppress DeprecatedClass */ $cache = $cache ?? new NullCache(); $cache->setNamespace($injectorId); + /** @var ScriptInjectorInterface|null $cachedInjector */ $cachedInjector = $cache->fetch(ScriptInjectorInterface::class); if ($cachedInjector instanceof ScriptInjectorInterface) { return $cachedInjector; // @codeCoverageIgnore diff --git a/src/InjectionPoint.php b/src/InjectionPoint.php index 45ce0c6..9465591 100644 --- a/src/InjectionPoint.php +++ b/src/InjectionPoint.php @@ -9,12 +9,16 @@ use Ray\Di\Di\Qualifier; use Ray\Di\InjectionPointInterface; use Ray\ServiceLocator\ServiceLocator; +use ReflectionException; use ReflectionParameter; use function assert; use function class_exists; -/** @psalm-import-type ScriptDir from CompileInjector */ +/** + * @psalm-import-type ScriptDir from CompileInjector + * @psalm-import-type Ip from CompileInjector + */ final class InjectionPoint implements InjectionPointInterface { /** @var ReflectionParameter */ @@ -26,7 +30,12 @@ public function __construct(ReflectionParameter $parameter) $this->parameter = $parameter; } - public static function getInstance(array $ip) + /** + * @param Ip $ip + * + * @throws ReflectionException + */ + public static function getInstance(array $ip): self { return new self(new ReflectionParameter([$ip[0], $ip[1]], $ip[2])); }