Skip to content

Commit f25de9c

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
2 parents c30921b + 714877b commit f25de9c

File tree

144 files changed

+1406
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1406
-264
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,11 @@ parameters:
641641
count: 1
642642
path: src/Type/Accessory/AccessoryLiteralStringType.php
643643

644+
-
645+
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
646+
count: 1
647+
path: src/Type/Accessory/AccessoryLowercaseStringType.php
648+
644649
-
645650
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
646651
count: 1

resources/functionMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6361,7 +6361,7 @@
63616361
'mb_strripos' => ['0|positive-int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'],
63626362
'mb_strrpos' => ['0|positive-int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'],
63636363
'mb_strstr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'],
6364-
'mb_strtolower' => ['string', 'str'=>'string', 'encoding='=>'string'],
6364+
'mb_strtolower' => ['lowercase-string', 'str'=>'string', 'encoding='=>'string'],
63656365
'mb_strtoupper' => ['string', 'str'=>'string', 'encoding='=>'string'],
63666366
'mb_strwidth' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
63676367
'mb_substitute_character' => ['mixed', 'substchar='=>'mixed'],
@@ -12085,7 +12085,7 @@
1208512085
'strstr' => ['string|false', 'haystack'=>'string', 'needle'=>'mixed', 'before_needle='=>'bool'],
1208612086
'strtok' => ['non-empty-string|false', 'str'=>'string', 'token'=>'string'],
1208712087
'strtok\'1' => ['non-empty-string|false', 'token'=>'string'],
12088-
'strtolower' => ['string', 'str'=>'string'],
12088+
'strtolower' => ['lowercase-string', 'str'=>'string'],
1208912089
'strtotime' => ['int|false', 'time'=>'string', 'now='=>'int'],
1209012090
'strtoupper' => ['string', 'str'=>'string'],
1209112091
'strtr' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function __construct(
206206
private ScopeContext $context,
207207
private PhpVersion $phpVersion,
208208
private bool $declareStrictTypes = false,
209-
private FunctionReflection|ExtendedMethodReflection|null $function = null,
209+
private PhpFunctionFromParserNodeReflection|null $function = null,
210210
?string $namespace = null,
211211
private array $expressionTypes = [],
212212
private array $nativeExpressionTypes = [],
@@ -306,9 +306,8 @@ public function getTraitReflection(): ?ClassReflection
306306

307307
/**
308308
* @api
309-
* @return FunctionReflection|ExtendedMethodReflection|null
310309
*/
311-
public function getFunction()
310+
public function getFunction(): ?PhpFunctionFromParserNodeReflection
312311
{
313312
return $this->function;
314313
}
@@ -1714,7 +1713,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17141713
return new MixedType();
17151714
}
17161715

1717-
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
1716+
$returnType = $functionReflection->getReturnType();
17181717
$generatorSendType = $returnType->getTemplateType(Generator::class, 'TSend');
17191718
if ($generatorSendType instanceof ErrorType) {
17201719
return new MixedType();
@@ -3132,17 +3131,16 @@ private function enterFunctionLike(
31323131
bool $preserveThis,
31333132
): self
31343133
{
3135-
$acceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants());
31363134
$parametersByName = [];
31373135

3138-
foreach ($acceptor->getParameters() as $parameter) {
3136+
foreach ($functionReflection->getParameters() as $parameter) {
31393137
$parametersByName[$parameter->getName()] = $parameter;
31403138
}
31413139

31423140
$expressionTypes = [];
31433141
$nativeExpressionTypes = [];
31443142
$conditionalTypes = [];
3145-
foreach ($acceptor->getParameters() as $parameter) {
3143+
foreach ($functionReflection->getParameters() as $parameter) {
31463144
$parameterType = $parameter->getType();
31473145

31483146
if ($parameterType instanceof ConditionalTypeForParameter) {
@@ -5508,7 +5506,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
55085506

55095507
$assignedToProperty = $node->getAttribute(NewAssignedToPropertyVisitor::ATTRIBUTE_NAME);
55105508
if ($assignedToProperty !== null) {
5511-
$constructorVariant = ParametersAcceptorSelector::selectSingle($constructorMethod->getVariants());
5509+
$constructorVariant = $constructorMethod->getOnlyVariant();
55125510
$classTemplateTypes = $classReflection->getTemplateTypeMap()->getTypes();
55135511
$originalClassTemplateTypes = $classTemplateTypes;
55145512
foreach ($constructorVariant->getParameters() as $parameter) {

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ private function processStmtNode(
723723
$classReflection = $scope->getClassReflection();
724724

725725
$methodReflection = $methodScope->getFunction();
726-
if (!$methodReflection instanceof ExtendedMethodReflection) {
726+
if (!$methodReflection instanceof PhpMethodFromParserNodeReflection) {
727727
throw new ShouldNotHappenException();
728728
}
729729

src/Analyser/Scope.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Reflection\NamespaceAnswerer;
1717
use PHPStan\Reflection\ParameterReflection;
1818
use PHPStan\Reflection\ParametersAcceptor;
19+
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
1920
use PHPStan\TrinaryLogic;
2021
use PHPStan\Type\Type;
2122
use PHPStan\Type\TypeWithClassName;
@@ -49,10 +50,7 @@ public function isInTrait(): bool;
4950

5051
public function getTraitReflection(): ?ClassReflection;
5152

52-
/**
53-
* @return FunctionReflection|ExtendedMethodReflection|null
54-
*/
55-
public function getFunction();
53+
public function getFunction(): ?PhpFunctionFromParserNodeReflection;
5654

5755
public function getFunctionName(): ?string;
5856

src/Dependency/DependencyResolver.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use PHPStan\Reflection\ClassReflection;
1919
use PHPStan\Reflection\FunctionReflection;
2020
use PHPStan\Reflection\ParameterReflectionWithPhpDocs;
21-
use PHPStan\Reflection\ParametersAcceptorSelector;
2221
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
2322
use PHPStan\Reflection\ReflectionProvider;
2423
use PHPStan\Type\ClosureType;
@@ -70,9 +69,8 @@ public function resolveDependencies(Node $node, Scope $scope): NodeDependencies
7069
}
7170
} elseif ($node instanceof InClassMethodNode) {
7271
$nativeMethod = $node->getMethodReflection();
73-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($nativeMethod->getVariants());
7472
$this->extractThrowType($nativeMethod->getThrowType(), $dependenciesReflections);
75-
$this->extractFromParametersAcceptor($parametersAcceptor, $dependenciesReflections);
73+
$this->extractFromParametersAcceptor($nativeMethod, $dependenciesReflections);
7674
foreach ($nativeMethod->getAsserts()->getAll() as $assertTag) {
7775
foreach ($assertTag->getType()->getReferencedClasses() as $referencedClass) {
7876
$this->addClassToDependencies($referencedClass, $dependenciesReflections);
@@ -103,9 +101,8 @@ public function resolveDependencies(Node $node, Scope $scope): NodeDependencies
103101
} elseif ($node instanceof InFunctionNode) {
104102
$functionReflection = $node->getFunctionReflection();
105103
$this->extractThrowType($functionReflection->getThrowType(), $dependenciesReflections);
106-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants());
107104

108-
$this->extractFromParametersAcceptor($parametersAcceptor, $dependenciesReflections);
105+
$this->extractFromParametersAcceptor($functionReflection, $dependenciesReflections);
109106
foreach ($functionReflection->getAsserts()->getAll() as $assertTag) {
110107
foreach ($assertTag->getType()->getReferencedClasses() as $referencedClass) {
111108
$this->addClassToDependencies($referencedClass, $dependenciesReflections);

src/Internal/ContainerDynamicReturnTypeExtension.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3333
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3434
{
3535
if (count($methodCall->getArgs()) === 0) {
36-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
36+
return ParametersAcceptorSelector::selectFromArgs(
37+
$scope,
38+
$methodCall->getArgs(),
39+
$methodReflection->getVariants(),
40+
)->getReturnType();
3741
}
3842
$argType = $scope->getType($methodCall->getArgs()[0]->value);
3943
if (!$argType instanceof ConstantStringType) {
40-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
44+
return ParametersAcceptorSelector::selectFromArgs(
45+
$scope,
46+
$methodCall->getArgs(),
47+
$methodReflection->getVariants(),
48+
)->getReturnType();
4149
}
4250

4351
$type = new ObjectType($argType->getValue());

src/Node/FunctionReturnStatementsNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpParser\NodeAbstract;
1010
use PHPStan\Analyser\ImpurePoint;
1111
use PHPStan\Analyser\StatementResult;
12-
use PHPStan\Reflection\FunctionReflection;
12+
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
1313
use function count;
1414

1515
/**
@@ -32,7 +32,7 @@ public function __construct(
3232
private StatementResult $statementResult,
3333
private array $executionEnds,
3434
private array $impurePoints,
35-
private FunctionReflection $functionReflection,
35+
private PhpFunctionFromParserNodeReflection $functionReflection,
3636
)
3737
{
3838
parent::__construct($function->getAttributes());
@@ -91,7 +91,7 @@ public function getSubNodeNames(): array
9191
return [];
9292
}
9393

94-
public function getFunctionReflection(): FunctionReflection
94+
public function getFunctionReflection(): PhpFunctionFromParserNodeReflection
9595
{
9696
return $this->functionReflection;
9797
}

src/Node/MethodReturnStatementsNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PHPStan\Analyser\ImpurePoint;
1111
use PHPStan\Analyser\StatementResult;
1212
use PHPStan\Reflection\ClassReflection;
13-
use PHPStan\Reflection\ExtendedMethodReflection;
13+
use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
1414
use function count;
1515

1616
/**
@@ -36,7 +36,7 @@ public function __construct(
3636
private array $executionEnds,
3737
private array $impurePoints,
3838
private ClassReflection $classReflection,
39-
private ExtendedMethodReflection $methodReflection,
39+
private PhpMethodFromParserNodeReflection $methodReflection,
4040
)
4141
{
4242
parent::__construct($method->getAttributes());
@@ -88,7 +88,7 @@ public function getClassReflection(): ClassReflection
8888
return $this->classReflection;
8989
}
9090

91-
public function getMethodReflection(): ExtendedMethodReflection
91+
public function getMethodReflection(): PhpMethodFromParserNodeReflection
9292
{
9393
return $this->methodReflection;
9494
}

src/Php/PhpVersion.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,9 @@ public function deprecatesImplicitlyNullableParameterTypes(): bool
348348
return $this->versionId >= 80400;
349349
}
350350

351+
public function substrReturnFalseInsteadOfEmptyString(): bool
352+
{
353+
return $this->versionId < 80000;
354+
}
355+
351356
}

0 commit comments

Comments
 (0)