Skip to content

Commit

Permalink
Merge pull request #294 from ray-di/pure
Browse files Browse the repository at this point in the history
Enhance code quality with Psalm annotations
  • Loading branch information
koriym authored Nov 29, 2024
2 parents f591d1f + 563c261 commit a7dc251
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/di/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ private function setDefaultValue(ReflectionParameter $parameter): void
}
}

/**
* @psalm-pure
*/
private function getType(ReflectionParameter $parameter): string
{
$type = $parameter->getType();
Expand Down
3 changes: 2 additions & 1 deletion src/di/Di/Inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @Annotation
* @Target("METHOD")
* @NamedArgumentConstructor
* @psalm-immutable
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
final class Inject implements InjectInterface
Expand All @@ -22,7 +23,7 @@ final class Inject implements InjectInterface
*
* @var bool
*/
public $optional = false;
public $optional;

/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) // @phpstan-ignore-line
Expand Down
3 changes: 2 additions & 1 deletion src/di/Di/Named.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
* @Annotation
* @Target("METHOD")
* @NamedArgumentConstructor
* @psalm-immutable
*/
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)]
final class Named
{
/** @var string */
public $value = '';
public $value;

public function __construct(string $value)
{
Expand Down
1 change: 1 addition & 0 deletions src/di/Di/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @Target({"METHOD","PROPERTY"})
* @NamedArgumentConstructor()
* @template T of object
* @psalm-immutable
*/
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
final class Set
Expand Down
3 changes: 3 additions & 0 deletions src/di/Exception/Unbound.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ private function buildMessage(self $e, array $msg): string
return $this->getMainMessage($lastE) . implode('', $msg);
}

/**
* @psalm-pure
*/
private function getMainMessage(self $e): string
{
return sprintf(
Expand Down
4 changes: 2 additions & 2 deletions src/di/MultiBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Ray\Di;

use Ray\Di\MultiBinding\LazyInstance;
use Ray\Di\MultiBinding\LazyInteterface;
use Ray\Di\MultiBinding\LazyInterface;
use Ray\Di\MultiBinding\LazyProvider;
use Ray\Di\MultiBinding\LazyTo;
use Ray\Di\MultiBinding\MultiBindings;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function toInstance($instance): void
$this->bind(new LazyInstance($instance), $this->key);
}

private function bind(LazyInteterface $lazy, ?string $key): void
private function bind(LazyInterface $lazy, ?string $key): void
{
$bindings = [];
if ($this->multiBindings->offsetExists($this->interface)) {
Expand Down
3 changes: 2 additions & 1 deletion src/di/MultiBinding/LazyInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

/**
* @template T of mixed
* @psalm-immutable
*/
final class LazyInstance implements LazyInteterface
final class LazyInstance implements LazyInterface
{
/** @var T */
private $instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Ray\Di\InjectorInterface;

interface LazyInteterface
interface LazyInterface
{
/**
* @return mixed
Expand Down
2 changes: 1 addition & 1 deletion src/di/MultiBinding/LazyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @template T of ProviderInterface
*/
final class LazyProvider implements LazyInteterface
final class LazyProvider implements LazyInterface
{
/** @var class-string<T> */
private $class;
Expand Down
2 changes: 1 addition & 1 deletion src/di/MultiBinding/LazyTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @template T of object
*/
final class LazyTo implements LazyInteterface
final class LazyTo implements LazyInterface
{
/** @var class-string<T> */
private $class;
Expand Down
4 changes: 2 additions & 2 deletions src/di/MultiBinding/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*/
final class Map implements IteratorAggregate, ArrayAccess, Countable
{
/** @var array<array-key, LazyInteterface> $lazies */
/** @var array<array-key, LazyInterface> $lazies */
private $lazies;

/** @var InjectorInterface */
private $injector;

/**
* @param array<array-key, LazyInteterface> $lazies
* @param array<array-key, LazyInterface> $lazies
*/
public function __construct(array $lazies, InjectorInterface $injector)
{
Expand Down
2 changes: 1 addition & 1 deletion src/di/MultiBinding/MultiBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function array_merge_recursive;

/**
* @extends ArrayObject<string, non-empty-array<array-key, LazyInteterface>>
* @extends ArrayObject<string, non-empty-array<array-key, LazyInterface>>
*/
final class MultiBindings extends ArrayObject
{
Expand Down
2 changes: 2 additions & 0 deletions src/di/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ private function setName(string $name): void

/**
* @return array<string, string>
*
* @psalm-pure
*/
private function parseName(string $name): array
{
Expand Down

0 comments on commit a7dc251

Please sign in to comment.