Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| CollectionMakeReturnTypeExtension | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | n/a |
0 / 0 |
|||
| getClass | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| isStaticMethodSupported | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getTypeFromStaticMethodCall | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Icawebdesign\Hibp\PHPStan; |
| 6 | |
| 7 | use Illuminate\Support\Collection; |
| 8 | use PhpParser\Node\Expr\StaticCall; |
| 9 | use PHPStan\Analyser\Scope; |
| 10 | use PHPStan\Reflection\MethodReflection; |
| 11 | use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; |
| 12 | use PHPStan\Type\Type; |
| 13 | |
| 14 | /** @codeCoverageIgnore */ |
| 15 | class CollectionMakeReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension |
| 16 | { |
| 17 | public function getClass(): string |
| 18 | { |
| 19 | return Collection::class; |
| 20 | } |
| 21 | |
| 22 | public function isStaticMethodSupported(MethodReflection $methodReflection): bool |
| 23 | { |
| 24 | return $methodReflection->getName() === 'make'; |
| 25 | } |
| 26 | |
| 27 | public function getTypeFromStaticMethodCall( |
| 28 | MethodReflection $methodReflection, |
| 29 | StaticCall $methodCall, |
| 30 | Scope $scope, |
| 31 | ): ?Type { |
| 32 | if (!isset($methodCall->getArgs()[0])) { |
| 33 | return null; // fall back to default resolution |
| 34 | } |
| 35 | |
| 36 | $argType = $scope->getType($methodCall->getArgs()[0]->value); |
| 37 | // Build Collection<key, value> from $argType's array key/value types |
| 38 | // ... (use $argType->getIterableKeyType() / getIterableValueType()) |
| 39 | |
| 40 | return new \PHPStan\Type\Generic\GenericObjectType( |
| 41 | Collection::class, |
| 42 | [$argType->getIterableKeyType(), $argType->getIterableValueType()], |
| 43 | ); |
| 44 | } |
| 45 | } |