Skip to content

Commit

Permalink
Remove unnecessary assertions and suppress warnings
Browse files Browse the repository at this point in the history
This commit eliminates redundant assert statements to streamline the code and improve readability. Additionally, it uses `@phpstan-ignore-line` annotations to suppress specific warnings, enhancing compatibility with static analysis tools.
  • Loading branch information
koriym committed Nov 29, 2024
1 parent f7c8844 commit 8e263f5
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/di/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getMeta(): string
/**
* {@inheritDoc}
*/
public function serialize(): ?string
public function serialize(): ?string // @phpstan-ignore-line
{
return serialize($this->__serialize());
}
Expand Down
2 changes: 1 addition & 1 deletion src/di/Di/Inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Inject implements InjectInterface
public $optional = false;

/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) // @phpstan-ignore-line
*/
public function __construct(bool $optional = false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/di/InjectionPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __unserialize(array $array): void
[$this->pClass, $this->pFunction, $this->pName] = $array;
}

public function serialize(): ?string
public function serialize(): ?string // @phpstan-ignore-line
{
return serialize($this->__serialize());
}
Expand Down
1 change: 0 additions & 1 deletion src/di/MultiBinding/LazyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct(string $class)
public function __invoke(InjectorInterface $injector)
{
$provider = $injector->getInstance($this->class);
assert($provider instanceof ProviderInterface);

return $provider->get();
}
Expand Down
1 change: 0 additions & 1 deletion src/di/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ private function parseName(string $name): array
$exploded = explode('=', $keyValue);
if (isset($exploded[1])) {
[$key, $value] = $exploded;
assert(is_string($key));
if (isset($key[0]) && $key[0] === '$') {
$key = substr($key, 1);

Check failure on line 154 in src/di/Name.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 1 of substr cannot be mixed, expecting string

Check failure on line 154 in src/di/Name.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 1 of substr cannot be mixed, expecting string
}
Expand Down
1 change: 0 additions & 1 deletion tests/di/ArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function testInject(): void
$this->assertInstanceOf(FakeTyre::class, $parameters[0]);
$this->assertInstanceOf(FakeTyre::class, $parameters[1]);
$param0 = $parameters[0];
assert(is_object($param0));
$this->assertNotSame(spl_object_hash($param0), $parameters[1]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/di/Fake/FakePhp8Car.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function setQualiferMirrors(#[FakeRight] FakeMirrorInterface $rightMirror
}

#[Inject]
public function notQualifer(#[FakeNotQualifer] FakeMirrorInterface $rightMirror = null): void
public function notQualifer(#[FakeNotQualifer] ?FakeMirrorInterface $rightMirror = null): void
{
}

Expand Down
1 change: 0 additions & 1 deletion tests/di/GrapherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function testGetInstanceWithArgs(): void
$grapher = new Grapher(new FakeUntargetModule(), __DIR__ . '/tmp');
$instance = $grapher->newInstanceArgs(FakeUntargetChild::class, ['1']);
$this->assertInstanceOf(FakeUntargetChild::class, $instance);
assert(is_object($instance));
assert(property_exists($instance, 'val'));

Check failure on line 31 in tests/di/GrapherTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function property_exists() with Ray\Di\FakeUntargetChild and 'val' will always evaluate to true.

Check failure on line 31 in tests/di/GrapherTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function property_exists() with Ray\Di\FakeUntargetChild and 'val' will always evaluate to true.
$this->assertSame('1', $instance->val);
}
Expand Down

0 comments on commit 8e263f5

Please sign in to comment.