Lines n/a 0 / 0
Functions and Methods n/a 0 / 0
Classes and Traits n/a 0 / 0
Covered by tests of size
Name Lines Functions and Methods CRAP Classes and Traits
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
3declare(strict_types=1);
4
5namespace Icawebdesign\Hibp\PHPStan;
6
7use Illuminate\Support\Collection;
8use PhpParser\Node\Expr\StaticCall;
9use PHPStan\Analyser\Scope;
10use PHPStan\Reflection\MethodReflection;
11use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
12use PHPStan\Type\Type;
13
14/** @codeCoverageIgnore */
15class 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}