Skip to content

Commit 7a2cc53

Browse files
committed
Fixes for phpstan warnings
1 parent a5bf223 commit 7a2cc53

File tree

7 files changed

+188
-201
lines changed

7 files changed

+188
-201
lines changed

composer.lock

Lines changed: 170 additions & 177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Suhock/DependencyInjection/ContainerTransientBuilderTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ abstract protected function getInjector(): InjectorInterface;
2828

2929
/**
3030
* @template TClass of object
31-
* @template TImplementation of TClass
3231
*
3332
* @param class-string<TClass> $className
34-
* @param class-string<TImplementation>|Closure|null $source
33+
* @param class-string<TClass>|Closure|null $source
3534
*
3635
* @return $this
3736
*/

src/Suhock/DependencyInjection/InjectorInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function call(callable $function, array $params = []): mixed;
3131
/**
3232
* Creates a new instance of the specified class, injecting any constructor parameter values.
3333
*
34-
* @template T of object
34+
* @template TClass of object
3535
*
36-
* @param class-string<T> $className The name of the class to instantiate
36+
* @param class-string<TClass> $className The name of the class to instantiate
3737
* @param array<mixed> $params [optional] A list of parameter values to provide to the constructor. String keys will
3838
* be matched by name; integer keys will be matched by position.
3939
*
40-
* @return T A new instance of the specified class
40+
* @return TClass A new instance of the specified class
4141
* @throws InjectorException If there was an error resolving values for the constructor parameters or invoking the
4242
* constructor
4343
*/

src/Suhock/DependencyInjection/Provision/ClassInstanceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use DomainException;
1515
use ReflectionException;
1616
use ReflectionFunction;
17+
use ReflectionNamedType;
1718
use Suhock\DependencyInjection\DependencyInjectionException;
1819
use Suhock\DependencyInjection\InjectorInterface;
1920

@@ -78,12 +79,12 @@ public static function isMutator(callable $function, string $className): bool
7879

7980
$firstParamType = $closureReflection->getParameters()[0]->getType();
8081

81-
if ($firstParamType?->isBuiltin() ?? false) {
82+
if (!$firstParamType instanceof ReflectionNamedType || $firstParamType->isBuiltin()) {
8283
return false;
8384
}
8485

8586
/** @var class-string $firstParamTypeName */
86-
$firstParamTypeName = $firstParamType?->getName();
87+
$firstParamTypeName = $firstParamType->getName();
8788

8889
return $firstParamTypeName === $className || is_subclass_of($className, $firstParamTypeName);
8990
}

src/Suhock/DependencyInjection/Provision/ImplementationInstanceProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
* the container.
1919
*
2020
* @template TClass of object
21-
* @template TImplementation of TClass
2221
* @template-implements InstanceProviderInterface<TClass>
2322
*/
2423
class ImplementationInstanceProvider implements InstanceProviderInterface
2524
{
2625
/**
2726
* @param class-string<TClass> $className The name of the class or interface provided
28-
* @param class-string<TImplementation> $implementationClassName The name of the class providing the implementation
27+
* @param class-string<TClass> $implementationClassName The name of the class providing the implementation
2928
* instance
3029
*
3130
* @throws ImplementationException If {@see $implementationClassName} is not a subclass of {@see $className}
@@ -43,8 +42,6 @@ public function __construct(
4342
/**
4443
* @inheritDoc
4544
* @return TClass An instance of the class
46-
* @psalm-return TClass An instance of the class
47-
* @phpstan-return TImplementation
4845
* @throws ClassNotFoundException If the container could not resolve a value for the specified class
4946
*/
5047
public function get(): object

src/Suhock/DependencyInjection/Provision/InstanceProviderFactory.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ final class InstanceProviderFactory
2020
{
2121
/**
2222
* @template TClass of object
23-
* @template TImplementation of TClass
2423
*
2524
* @param InjectorInterface $injector
2625
* @param ContainerInterface $container
2726
* @param class-string<TClass> $className
28-
* @param class-string<TImplementation>|TImplementation|null $source
27+
* @param class-string<TClass>|TClass|Closure|null $source
2928
*
30-
* @return InstanceProviderInterface<TClass>|InstanceProviderInterface<TImplementation>
29+
* @return InstanceProviderInterface<TClass>
3130
*/
3231
public static function createInstanceProvider(
3332
InjectorInterface $injector,
@@ -73,13 +72,12 @@ public static function createClassInstanceProvider(
7372

7473
/**
7574
* @template TClass of object
76-
* @template TImplementation of TClass
7775
*
7876
* @param ContainerInterface $container
7977
* @param class-string<TClass> $className
80-
* @param class-string<TImplementation> $implementationClassName
78+
* @param class-string<TClass> $implementationClassName
8179
*
82-
* @return ImplementationInstanceProvider<TClass, TImplementation>
80+
* @return ImplementationInstanceProvider<TClass>
8381
*/
8482
public static function createImplementationInstanceProvider(
8583
ContainerInterface $container,
@@ -91,10 +89,9 @@ public static function createImplementationInstanceProvider(
9189

9290
/**
9391
* @template TClass of object
94-
* @template TInstance of TClass
9592
*
9693
* @param class-string<TClass> $className
97-
* @param TInstance $object
94+
* @param TClass $object
9895
*
9996
* @return ObjectInstanceProvider<TClass>
10097
*/
@@ -119,6 +116,6 @@ public static function createClosureInstanceProvider(
119116
string $className,
120117
callable $closure
121118
): ClosureInstanceProvider {
122-
return new ClosureInstanceProvider($className, $closure, $injector);
119+
return new ClosureInstanceProvider($className, $closure(...), $injector);
123120
}
124121
}

tests/Suhock/DependencyInjection/DependencyInjectionTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
class DependencyInjectionTestCase extends TestCase
2424
{
2525
/**
26-
* @template T of Throwable
26+
* @template TClass of Throwable
2727
*
28-
* @param class-string<T> $expectedException
29-
* @param callable(T):void $exceptionTest
28+
* @param class-string<TClass> $expectedException
29+
* @param callable(TClass):void $exceptionTest
3030
* @param callable $codeUnderTest
3131
*
3232
* @return void
@@ -43,7 +43,7 @@ private static function assertThrowsThrowable(
4343
throw $e;
4444
} catch (Throwable $exception) {
4545
self::assertInstanceOf($expectedException, $exception, $exception->getMessage());
46-
/** @var T $exception */
46+
/** @var TClass $exception */
4747
$exceptionTest($exception);
4848
}
4949
}

0 commit comments

Comments
 (0)