forked from phpstan/phpstan-src
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestTypeOverwriteSpecifyingExtensions.php
58 lines (48 loc) · 1.39 KB
/
TestTypeOverwriteSpecifyingExtensions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Comparison;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Analyser\SpecifiedTypes;
use PHPStan\Analyser\TypeSpecifier;
use PHPStan\Analyser\TypeSpecifierAwareExtension;
use PHPStan\Analyser\TypeSpecifierContext;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\MethodTypeSpecifyingExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Generic\GenericObjectType;
class GenericTypeOverride implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{
/** @var TypeSpecifier */
private $typeSpecifier;
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
{
$this->typeSpecifier = $typeSpecifier;
}
public function getClass(): string
{
return \GenericTypeOverride\Foo::class;
}
public function isMethodSupported(
MethodReflection $methodReflection,
MethodCall $node,
TypeSpecifierContext $context
): bool
{
return $methodReflection->getName() === 'setFetchMode';
}
public function specifyTypes(
MethodReflection $methodReflection,
MethodCall $node,
Scope $scope,
TypeSpecifierContext $context
): SpecifiedTypes
{
$newType = new GenericObjectType(\GenericTypeOverride\Foo::class, [new ObjectType(\GenericTypeOverride\Bar::class)]);
return $this->typeSpecifier->create(
$node->var,
$newType,
TypeSpecifierContext::createTruthy(),
true
);
}
}