Skip to content

Commit a7dc251

Browse files
authored
Merge pull request #294 from ray-di/pure
Enhance code quality with Psalm annotations
2 parents f591d1f + 563c261 commit a7dc251

File tree

13 files changed

+23
-11
lines changed

13 files changed

+23
-11
lines changed

src/di/Argument.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ private function setDefaultValue(ReflectionParameter $parameter): void
171171
}
172172
}
173173

174+
/**
175+
* @psalm-pure
176+
*/
174177
private function getType(ReflectionParameter $parameter): string
175178
{
176179
$type = $parameter->getType();

src/di/Di/Inject.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @Annotation
1414
* @Target("METHOD")
1515
* @NamedArgumentConstructor
16+
* @psalm-immutable
1617
*/
1718
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
1819
final class Inject implements InjectInterface
@@ -22,7 +23,7 @@ final class Inject implements InjectInterface
2223
*
2324
* @var bool
2425
*/
25-
public $optional = false;
26+
public $optional;
2627

2728
/**
2829
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) // @phpstan-ignore-line

src/di/Di/Named.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* @Annotation
1414
* @Target("METHOD")
1515
* @NamedArgumentConstructor
16+
* @psalm-immutable
1617
*/
1718
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)]
1819
final class Named
1920
{
2021
/** @var string */
21-
public $value = '';
22+
public $value;
2223

2324
public function __construct(string $value)
2425
{

src/di/Di/Set.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @Target({"METHOD","PROPERTY"})
1313
* @NamedArgumentConstructor()
1414
* @template T of object
15+
* @psalm-immutable
1516
*/
1617
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
1718
final class Set

src/di/Exception/Unbound.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ private function buildMessage(self $e, array $msg): string
4848
return $this->getMainMessage($lastE) . implode('', $msg);
4949
}
5050

51+
/**
52+
* @psalm-pure
53+
*/
5154
private function getMainMessage(self $e): string
5255
{
5356
return sprintf(

src/di/MultiBinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Ray\Di;
66

77
use Ray\Di\MultiBinding\LazyInstance;
8-
use Ray\Di\MultiBinding\LazyInteterface;
8+
use Ray\Di\MultiBinding\LazyInterface;
99
use Ray\Di\MultiBinding\LazyProvider;
1010
use Ray\Di\MultiBinding\LazyTo;
1111
use Ray\Di\MultiBinding\MultiBindings;
@@ -80,7 +80,7 @@ public function toInstance($instance): void
8080
$this->bind(new LazyInstance($instance), $this->key);
8181
}
8282

83-
private function bind(LazyInteterface $lazy, ?string $key): void
83+
private function bind(LazyInterface $lazy, ?string $key): void
8484
{
8585
$bindings = [];
8686
if ($this->multiBindings->offsetExists($this->interface)) {

src/di/MultiBinding/LazyInstance.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
/**
1010
* @template T of mixed
11+
* @psalm-immutable
1112
*/
12-
final class LazyInstance implements LazyInteterface
13+
final class LazyInstance implements LazyInterface
1314
{
1415
/** @var T */
1516
private $instance;

src/di/MultiBinding/LazyInteterface.php renamed to src/di/MultiBinding/LazyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Ray\Di\InjectorInterface;
88

9-
interface LazyInteterface
9+
interface LazyInterface
1010
{
1111
/**
1212
* @return mixed

src/di/MultiBinding/LazyProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @template T of ProviderInterface
1212
*/
13-
final class LazyProvider implements LazyInteterface
13+
final class LazyProvider implements LazyInterface
1414
{
1515
/** @var class-string<T> */
1616
private $class;

src/di/MultiBinding/LazyTo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @template T of object
1111
*/
12-
final class LazyTo implements LazyInteterface
12+
final class LazyTo implements LazyInterface
1313
{
1414
/** @var class-string<T> */
1515
private $class;

0 commit comments

Comments
 (0)