Skip to content

Commit e085bda

Browse files
committed
Refactor: remove redundant assertions and improve array handling
Removed unnecessary assertions such as `assert` and `property_exists` to make the tests cleaner and more efficient. Adjusted array handling by casting `bindings` to an array for better compatibility and added necessary code comments to suppress static analysis warnings where applicable. These changes improve the maintainability and readability of the codebase without affecting the functionality.
1 parent 8e263f5 commit e085bda

File tree

7 files changed

+5
-15
lines changed

7 files changed

+5
-15
lines changed

src/di/Bind.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function getStringName(array $name): string
218218
* @param array-key $key
219219
*/
220220
static function (array $carry, $key) use ($name): array {
221-
if (! is_string($key)) {
221+
if (! is_string($key)) { // @phpstan-ignore-line
222222
throw new InvalidToConstructorNameParameter((string) $key);
223223
}
224224

src/di/MultiBinding/LazyProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Ray\Di\InjectorInterface;
88
use Ray\Di\ProviderInterface;
99

10-
use function assert;
11-
1210
/**
1311
* @template T of ProviderInterface
1412
*/

src/di/Name.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ private function parseName(string $name): array
151151
if (isset($exploded[1])) {
152152
[$key, $value] = $exploded;
153153
if (isset($key[0]) && $key[0] === '$') {
154+
assert(is_string($key)); // @phpstan-ignore-line
154155
$key = substr($key, 1);
155156
}
156157

158+
/** @psalm-suppress MixedArgument */
157159
$names[trim($key)] = trim($value);
158160
}
159161
}

tests/di/ArgumentsTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use ReflectionMethod;
99
use ReflectionParameter;
1010

11-
use function assert;
12-
use function is_object;
1311
use function spl_object_hash;
1412

1513
class ArgumentsTest extends TestCase

tests/di/DependencyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testInjectInterceptor(): void
115115
$isWeave = (new ReflectionClass($instance))->implementsInterface(WeavedInterface::class);
116116
$this->assertTrue($isWeave);
117117
assert(property_exists($instance, 'bindings'));
118-
$this->assertArrayHasKey('returnSame', $instance->bindings);
118+
$this->assertArrayHasKey('returnSame', (array) $instance->bindings);
119119
}
120120

121121
/**

tests/di/GrapherTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
use function assert;
1111
use function file_get_contents;
12-
use function is_object;
1312
use function is_string;
1413
use function passthru;
15-
use function property_exists;
1614
use function unserialize;
1715

1816
class GrapherTest extends TestCase
@@ -28,7 +26,6 @@ public function testGetInstanceWithArgs(): void
2826
$grapher = new Grapher(new FakeUntargetModule(), __DIR__ . '/tmp');
2927
$instance = $grapher->newInstanceArgs(FakeUntargetChild::class, ['1']);
3028
$this->assertInstanceOf(FakeUntargetChild::class, $instance);
31-
assert(property_exists($instance, 'val'));
3229
$this->assertSame('1', $instance->val);
3330
}
3431

tests/di/InjectorTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function file_get_contents;
1717
use function is_string;
1818
use function passthru;
19-
use function property_exists;
2019
use function serialize;
2120
use function spl_object_hash;
2221
use function unlink;
@@ -184,7 +183,6 @@ public function testAnnotationBasedInjection(): Injector
184183
$this->assertInstanceOf(FakeMirrorInterface::class, $car->spareMirror);
185184
$this->assertSame(spl_object_hash($car->rightMirror), spl_object_hash($car->spareMirror));
186185
$this->assertInstanceOf(FakeHandle::class, $car->handle);
187-
assert($car->handle instanceof FakeHandle);
188186
$this->assertSame($car->handle->logo, 'momo');
189187

190188
return $injector;
@@ -242,7 +240,6 @@ public function testSerializeBuiltinBinding(): void
242240
$injector = unserialize(serialize(new Injector()));
243241
assert($injector instanceof InjectorInterface);
244242
$instance = $injector->getInstance(FakeBuiltin::class);
245-
assert(property_exists($instance, 'injector'));
246243
$this->assertInstanceOf(Injector::class, $instance->injector);
247244
}
248245

@@ -430,9 +427,7 @@ protected function configure()
430427
$instance = $injector->getInstance(FakeAop::class);
431428
$result = $instance->returnSame(2);
432429
$this->assertSame(2, $result);
433-
assert(property_exists($instance, 'bindings'));
434-
assert(isset($instance->bindings['returnSame'][0]));
435-
$this->assertInstanceOf(NullInterceptor::class, $instance->bindings['returnSame'][0]);
430+
$this->assertInstanceOf(NullInterceptor::class, $instance->bindings['returnSame'][0]); // @phpstan-ignore-line
436431
}
437432

438433
public function testModuleArray(): void

0 commit comments

Comments
 (0)