Skip to content

Commit 9b26ffe

Browse files
committed
Create PHPParser.stub
1 parent 38712dd commit 9b26ffe

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

build/PHPStan/Build/ContainerDynamicReturnTypeExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Type\TypeCombinator;
1515
use function count;
1616
use function in_array;
17+
use function PHPStan\dumpType;
1718

1819
final class ContainerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
1920
{
@@ -32,13 +33,15 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3233

3334
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3435
{
36+
dumpType($methodCall->getArgs());
3537
if (count($methodCall->getArgs()) === 0) {
3638
return ParametersAcceptorSelector::selectFromArgs(
3739
$scope,
3840
$methodCall->getArgs(),
3941
$methodReflection->getVariants(),
4042
)->getReturnType();
4143
}
44+
dumpType($methodCall->getArgs());
4245
$argType = $scope->getType($methodCall->getArgs()[0]->value);
4346
if (!$argType instanceof ConstantStringType) {
4447
return ParametersAcceptorSelector::selectFromArgs(

build/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ parameters:
124124
- stubs/ReactStreams.stub
125125
- stubs/NetteDIContainer.stub
126126
- stubs/PhpParserName.stub
127+
- stubs/PhpParserExpr.stub
127128
- stubs/Identifier.stub
128129

129130
rules:

build/stubs/PhpParserExpr.stub

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace PhpParser\Node\Expr;
4+
5+
use PhpParser\Node;
6+
use PhpParser\NodeAbstract;
7+
use PhpParser\Node\Arg;
8+
use PhpParser\Node\Expr;
9+
use PhpParser\Node\Identifier;
10+
use PhpParser\Node\VariadicPlaceholder;
11+
12+
abstract class CallLike extends Expr {
13+
/**
14+
* Return raw arguments, which may be actual Args, or VariadicPlaceholders for first-class
15+
* callables.
16+
*
17+
* @return list<Arg|VariadicPlaceholder>
18+
*/
19+
abstract public function getRawArgs(): array;
20+
/**
21+
* Assert that this is not a first-class callable and return only ordinary Args.
22+
*
23+
* @return list<Arg>
24+
*/
25+
public function getArgs(): array {
26+
assert(!$this->isFirstClassCallable());
27+
return $this->getRawArgs();
28+
}
29+
}
30+
31+
class FuncCall extends CallLike {
32+
/** @var list<Node\Arg|Node\VariadicPlaceholder> Arguments */
33+
public array $args;
34+
35+
/**
36+
* Constructs a function call node.
37+
*
38+
* @param Node\Name|Expr $name Function name
39+
* @param list<Node\Arg|Node\VariadicPlaceholder> $args Arguments
40+
* @param array<string, mixed> $attributes Additional attributes
41+
*/
42+
public function __construct(Node $name, array $args = [], array $attributes = []) {}
43+
}
44+
45+
class MethodCall extends CallLike {
46+
/** @var list<Node\Arg|Node\VariadicPlaceholder> Arguments */
47+
public array $args;
48+
49+
/**
50+
* Constructs a function call node.
51+
*
52+
* @param Expr $var Variable holding object
53+
* @param string|Identifier|Expr $name Method name
54+
* @param list<Arg|VariadicPlaceholder> $args Arguments
55+
* @param array<string, mixed> $attributes Additional attributes
56+
*/
57+
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {}
58+
}
59+
60+
class New_ extends CallLike {
61+
/** @var list<Arg|VariadicPlaceholder> Arguments */
62+
public array $args;
63+
64+
/**
65+
* Constructs a function call node.
66+
*
67+
* @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes)
68+
* @param list<Arg|VariadicPlaceholder> $args Arguments
69+
* @param array<string, mixed> $attributes Additional attributes
70+
*/
71+
public function __construct(Node $class, array $args = [], array $attributes = []) {}
72+
}
73+
74+
class NullsafeMethodCall extends CallLike {
75+
/** @var list<Arg|VariadicPlaceholder> Arguments */
76+
public array $args;
77+
78+
/**
79+
* Constructs a nullsafe method call node.
80+
*
81+
* @param Expr $var Variable holding object
82+
* @param string|Identifier|Expr $name Method name
83+
* @param list<Arg|VariadicPlaceholder> $args Arguments
84+
* @param array<string, mixed> $attributes Additional attributes
85+
*/
86+
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {}
87+
}
88+
89+
class StaticCall extends CallLike {
90+
/** @var list<Arg|VariadicPlaceholder> Arguments */
91+
public array $args;
92+
93+
/**
94+
* Constructs a static method call node.
95+
*
96+
* @param Node\Name|Expr $class Class name
97+
* @param string|Identifier|Expr $name Method name
98+
* @param list<Arg|VariadicPlaceholder> $args Arguments
99+
* @param array<string, mixed> $attributes Additional attributes
100+
*/
101+
public function __construct(Node $class, $name, array $args = [], array $attributes = []) {}
102+
}

0 commit comments

Comments
 (0)