Skip to content

Commit 1b45eae

Browse files
committed
[BCB] acceptsNamedArguments() returns TrinaryLogic instead of bool
1 parent 773e87a commit 1b45eae

32 files changed

+71
-68
lines changed

UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,4 @@ Instead of `PHPStanTestCase::createBroker()`, call `PHPStanTestCase::createRefle
276276
* Parameter `$isList` in `ConstantArrayType` constructor can only be `TrinaryLogic`, no longer bool
277277
* Parameter `$nextAutoIndexes` in `ConstantArrayType` constructor can only be `non-empty-list<int>`, no longer int
278278
* Remove `ConstantType` interface, use [`Type::isConstantValue()`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.Type.html#_isConstantValue) instead
279+
* `acceptsNamedArguments()` in `FunctionReflection`, `ExtendedMethodReflection` and `CallableParametersAcceptor` interfaces returns `TrinaryLogic` instead of `bool`

src/Analyser/ArgumentsNormalizer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Reflection\ParametersAcceptor;
1212
use PHPStan\Reflection\ParametersAcceptorSelector;
1313
use PHPStan\ShouldNotHappenException;
14+
use PHPStan\TrinaryLogic;
1415
use PHPStan\Type\Constant\ConstantArrayType;
1516
use function array_key_exists;
1617
use function array_keys;
@@ -27,7 +28,7 @@ final class ArgumentsNormalizer
2728
public const ORIGINAL_ARG_ATTRIBUTE = 'originalArg';
2829

2930
/**
30-
* @return array{ParametersAcceptor, FuncCall, bool}|null
31+
* @return array{ParametersAcceptor, FuncCall, TrinaryLogic}|null
3132
*/
3233
public static function reorderCallUserFuncArguments(
3334
FuncCall $callUserFuncCall,
@@ -73,9 +74,9 @@ public static function reorderCallUserFuncArguments(
7374
null,
7475
);
7576

76-
$acceptsNamedArguments = true;
77+
$acceptsNamedArguments = TrinaryLogic::createYes();
7778
foreach ($callableParametersAcceptors as $callableParametersAcceptor) {
78-
$acceptsNamedArguments = $acceptsNamedArguments && $callableParametersAcceptor->acceptsNamedArguments();
79+
$acceptsNamedArguments = $acceptsNamedArguments->and($callableParametersAcceptor->acceptsNamedArguments());
7980
}
8081

8182
return [$parametersAcceptor, new FuncCall(

src/Analyser/MutatingScope.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
13571357
$cachedClosureData['impurePoints'],
13581358
$cachedClosureData['invalidateExpressions'],
13591359
$cachedClosureData['usedVariables'],
1360-
true,
1360+
TrinaryLogic::createYes(),
13611361
);
13621362
}
13631363
if (self::$resolveClosureTypeDepth >= 2) {
@@ -1572,7 +1572,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
15721572
$impurePointsForClosureType,
15731573
$invalidateExpressions,
15741574
$usedVariables,
1575-
true,
1575+
TrinaryLogic::createYes(),
15761576
);
15771577
} elseif ($node instanceof New_) {
15781578
if ($node->class instanceof Name) {
@@ -2521,7 +2521,7 @@ private function createFirstClassCallable(
25212521

25222522
$throwPoints = [];
25232523
$impurePoints = [];
2524-
$acceptsNamedArguments = true;
2524+
$acceptsNamedArguments = TrinaryLogic::createYes();
25252525
if ($variant instanceof CallableParametersAcceptor) {
25262526
$throwPoints = $variant->getThrowPoints();
25272527
$impurePoints = $variant->getImpurePoints();
@@ -3151,7 +3151,7 @@ private function enterFunctionLike(
31513151

31523152
$paramExprString = '$' . $parameter->getName();
31533153
if ($parameter->isVariadic()) {
3154-
if ($this->phpVersion->supportsNamedArguments() && $functionReflection->acceptsNamedArguments()) {
3154+
if ($this->phpVersion->supportsNamedArguments() && $functionReflection->acceptsNamedArguments()->yes()) {
31553155
$parameterType = new ArrayType(new UnionType([new IntegerType(), new StringType()]), $parameterType);
31563156
} else {
31573157
$parameterType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $parameterType), new AccessoryArrayListType());
@@ -3166,7 +3166,7 @@ private function enterFunctionLike(
31663166

31673167
$nativeParameterType = $parameter->getNativeType();
31683168
if ($parameter->isVariadic()) {
3169-
if ($this->phpVersion->supportsNamedArguments() && $functionReflection->acceptsNamedArguments()) {
3169+
if ($this->phpVersion->supportsNamedArguments() && $functionReflection->acceptsNamedArguments()->yes()) {
31703170
$nativeParameterType = new ArrayType(new UnionType([new IntegerType(), new StringType()]), $nativeParameterType);
31713171
} else {
31723172
$nativeParameterType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $nativeParameterType), new AccessoryArrayListType());

src/Reflection/Annotations/AnnotationMethodReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ public function getAsserts(): Assertions
147147
return Assertions::createEmpty();
148148
}
149149

150-
public function acceptsNamedArguments(): bool
150+
public function acceptsNamedArguments(): TrinaryLogic
151151
{
152-
return $this->declaringClass->acceptsNamedArguments();
152+
return TrinaryLogic::createFromBoolean($this->declaringClass->acceptsNamedArguments());
153153
}
154154

155155
public function getSelfOutType(): ?Type

src/Reflection/CallableFunctionVariantWithPhpDocs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
private array $impurePoints,
3636
private array $invalidateExpressions,
3737
private array $usedVariables,
38-
private bool $acceptsNamedArguments,
38+
private TrinaryLogic $acceptsNamedArguments,
3939
)
4040
{
4141
parent::__construct(
@@ -75,7 +75,7 @@ public function getUsedVariables(): array
7575
return $this->usedVariables;
7676
}
7777

78-
public function acceptsNamedArguments(): bool
78+
public function acceptsNamedArguments(): TrinaryLogic
7979
{
8080
return $this->acceptsNamedArguments;
8181
}

src/Reflection/Callables/CallableParametersAcceptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getThrowPoints(): array;
1919

2020
public function isPure(): TrinaryLogic;
2121

22-
public function acceptsNamedArguments(): bool;
22+
public function acceptsNamedArguments(): TrinaryLogic;
2323

2424
/**
2525
* @return SimpleImpurePoint[]

src/Reflection/Callables/FunctionCallableVariant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getUsedVariables(): array
163163
return [];
164164
}
165165

166-
public function acceptsNamedArguments(): bool
166+
public function acceptsNamedArguments(): TrinaryLogic
167167
{
168168
return $this->function->acceptsNamedArguments();
169169
}

src/Reflection/Dummy/ChangedTypeMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getAsserts(): Assertions
119119
return $this->reflection->getAsserts();
120120
}
121121

122-
public function acceptsNamedArguments(): bool
122+
public function acceptsNamedArguments(): TrinaryLogic
123123
{
124124
return $this->reflection->acceptsNamedArguments();
125125
}

src/Reflection/Dummy/DummyConstructorReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public function getAsserts(): Assertions
117117
return Assertions::createEmpty();
118118
}
119119

120-
public function acceptsNamedArguments(): bool
120+
public function acceptsNamedArguments(): TrinaryLogic
121121
{
122-
return $this->declaringClass->acceptsNamedArguments();
122+
return TrinaryLogic::createFromBoolean($this->declaringClass->acceptsNamedArguments());
123123
}
124124

125125
public function getSelfOutType(): ?Type

src/Reflection/Dummy/DummyMethodReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public function getAsserts(): Assertions
114114
return Assertions::createEmpty();
115115
}
116116

117-
public function acceptsNamedArguments(): bool
117+
public function acceptsNamedArguments(): TrinaryLogic
118118
{
119-
return true;
119+
return TrinaryLogic::createYes();
120120
}
121121

122122
public function getSelfOutType(): ?Type

0 commit comments

Comments
 (0)