Skip to content

Commit

Permalink
Refactor and update dependencies for stability.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Nov 30, 2024
1 parent 7d6df30 commit 995bf54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/AirInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CachedInjectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/InjectionPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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]));
}
Expand Down

0 comments on commit 995bf54

Please sign in to comment.