Skip to content

Commit 2127ecf

Browse files
committed
Soothe SA:vRefactor type checks and suppress annotations.
Replaced implicit null checks with strict comparisons to improve clarity and prevent potential bugs. Adjusted or added suppress annotations for static analysis tools where required. Removed unnecessary assertions and cleaned up redundant code.
1 parent 19d04e1 commit 2127ecf

File tree

11 files changed

+16
-16
lines changed

11 files changed

+16
-16
lines changed

src/di/Argument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getMeta(): string
9393
* {@inheritDoc}
9494
*/
9595
#[Override]
96-
public function serialize(): ?string // @phpstan-ignore-line
96+
public function serialize(): string
9797
{
9898
return serialize($this->__serialize());
9999
}

src/di/Bind.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function toConstructor(string $class, $name, ?InjectionPoints $injectionP
117117
}
118118

119119
$this->untarget = null;
120-
$postConstructRef = $postConstruct ? new ReflectionMethod($class, $postConstruct) : null;
120+
$postConstructRef = $postConstruct !== null ? new ReflectionMethod($class, $postConstruct) : null;
121121
/** @var ReflectionClass<object> $reflection */
122122
$reflection = new ReflectionClass($class);
123123
$this->bound = (new DependencyFactory())->newToConstructor($reflection, $name, $injectionPoints, $postConstructRef);

src/di/Container.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function getInstanceWithArgs(string $interface, array $params)
9696
throw new BadMethodCallException($interface);
9797
}
9898

99+
/** @psalm-suppress ArgumentTypeCoercion */
99100
return $dependency->injectWithArgs($this, $params);
100101
}
101102

src/di/Dependency.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ public function register(array &$container, Bind $bind): void
7070
public function inject(Container $container)
7171
{
7272
// singleton ?
73-
if ($this->isSingleton === true && $this->instance) {
73+
if ($this->isSingleton === true && $this->instance !== null) {
7474
return $this->instance;
7575
}
7676

7777
// create dependency injected instance
7878
$this->instance = ($this->newInstance)($container);
7979

8080
// @PostConstruct
81-
if ($this->postConstruct) {
81+
if ($this->postConstruct !== null) {
8282
assert(method_exists($this->instance, $this->postConstruct));
8383
$this->instance->{$this->postConstruct}();
8484
}
@@ -94,15 +94,15 @@ public function inject(Container $container)
9494
public function injectWithArgs(Container $container, array $params)
9595
{
9696
// singleton ?
97-
if ($this->isSingleton === true && $this->instance) {
97+
if ($this->isSingleton === true && $this->instance !== null) {
9898
return $this->instance;
9999
}
100100

101101
// create dependency injected instance
102102
$this->instance = $this->newInstance->newInstanceArgs($container, $params);
103103

104104
// @PostConstruct
105-
if ($this->postConstruct) {
105+
if ($this->postConstruct !== null) {
106106
assert(method_exists($this->instance, $this->postConstruct));
107107
$this->instance->{$this->postConstruct}();
108108
}

src/di/DependencyProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function register(array &$container, Bind $bind): void
6464
#[Override]
6565
public function inject(Container $container)
6666
{
67-
if ($this->isSingleton && $this->instance) {
67+
if ($this->isSingleton && $this->instance !== null) {
6868
return $this->instance;
6969
}
7070

src/di/InjectionPoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class InjectionPoint implements InjectionPointInterface, Serializable
3333
public function __construct(ReflectionParameter $parameter)
3434
{
3535
$this->parameter = $parameter;
36-
$this->pFunction = (string) $parameter->getDeclaringFunction()->name;
36+
$this->pFunction = $parameter->getDeclaringFunction()->name;
3737
$class = $parameter->getDeclaringClass();
3838
$this->pClass = $class instanceof ReflectionClass ? $class->name : '';
3939
$this->pName = $parameter->name;
@@ -113,7 +113,7 @@ public function __unserialize(array $array): void
113113
}
114114

115115
#[Override]
116-
public function serialize(): ?string // @phpstan-ignore-line
116+
public function serialize(): string
117117
{
118118
return serialize($this->__serialize());
119119
}

src/di/Name.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use ReflectionMethod;
1313
use ReflectionParameter;
1414

15-
use function assert;
1615
use function class_exists;
1716
use function explode;
1817
use function get_class;
@@ -153,7 +152,6 @@ private function parseName(string $name): array
153152
if (isset($exploded[1])) {
154153
[$key, $value] = $exploded;
155154
if (isset($key[0]) && $key[0] === '$') {
156-
assert(is_string($key)); // @phpstan-ignore-line
157155
$key = substr($key, 1);
158156
}
159157

src/di/NewInstance.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(
4848
*/
4949
public function __invoke(Container $container): object
5050
{
51-
/** @psalm-suppress MixedMethodCall */
51+
/** @psalm-suppress MixedMethodCall, ArgumentTypeCoercion */
5252
$instance = $this->arguments instanceof Arguments ? (new ReflectionClass($this->class))->newInstanceArgs($this->arguments->inject($container)) : new $this->class();
5353

5454
return $this->postNewInstance($container, $instance);
@@ -69,6 +69,7 @@ public function __toString()
6969
*/
7070
public function newInstanceArgs(Container $container, array $params): object
7171
{
72+
/** @psalm-suppress ArgumentTypeCoercion */
7273
$instance = (new ReflectionClass($this->class))->newInstanceArgs($params);
7374

7475
return $this->postNewInstance($container, $instance);

tests/di/DependencyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
$setters[] = new SetterMethod(new ReflectionMethod(FakeCar::class, 'setTires'), $name);
3131
$setters[] = new SetterMethod(new ReflectionMethod(FakeCar::class, 'setHardtop'), $name);
3232
$setterMethods = new SetterMethods($setters);
33-
$newInstance = new NewInstance($class, $setterMethods);
33+
$newInstance = new NewInstance($class, $setterMethods); // @phpstan-ignore-line
3434
$this->dependency = new Dependency($newInstance, new ReflectionMethod(FakeCar::class, 'postConstruct'));
3535
}
3636

@@ -105,7 +105,7 @@ public function testSingleton(Container $container): void
105105

106106
public function testInjectInterceptor(): void
107107
{
108-
$dependency = new Dependency(new NewInstance(new ReflectionClass(FakeAop::class), new SetterMethods([])));
108+
$dependency = new Dependency(new NewInstance(new ReflectionClass(FakeAop::class), new SetterMethods([]))); // @phpstan-ignore-line
109109
$pointcut = new Pointcut((new Matcher())->any(), (new Matcher())->any(), [FakeDoubleInterceptor::class]);
110110
$dependency->weaveAspects(new Compiler(__DIR__ . '/tmp'), [$pointcut]);
111111
$container = new Container();

tests/di/NewInstanceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function setUp(): void
2323
$setters[] = new SetterMethod(new ReflectionMethod(FakeCar::class, 'setTires'), $name);
2424
$setters[] = new SetterMethod(new ReflectionMethod(FakeCar::class, 'setHardtop'), $name);
2525
$setterMethods = new SetterMethods($setters);
26-
$this->newInstance = new NewInstance($class, $setterMethods);
26+
$this->newInstance = new NewInstance($class, $setterMethods); // @phpstan-ignore-line
2727
}
2828

2929
public function testInvoke(): void

0 commit comments

Comments
 (0)