Skip to content

Commit 250133c

Browse files
phpstan-botclaude
andcommitted
Move isBuiltin() method to CallableParametersAcceptor interface
Instead of checking `instanceof FunctionCallableVariant` in CallableType, the isBuiltin() method is now part of the CallableParametersAcceptor interface and implemented by all classes. The value is propagated through ExtendedCallableFunctionVariant and ResolvedFunctionVariantWithCallable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e1817a5 commit 250133c

9 files changed

Lines changed: 40 additions & 2 deletions

src/Reflection/Callables/CallableParametersAcceptor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ public function mustUseReturnValue(): TrinaryLogic;
6060

6161
public function getAsserts(): Assertions;
6262

63+
public function isBuiltin(): TrinaryLogic;
64+
6365
}

src/Reflection/ExtendedCallableFunctionVariant.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct(
3838
private TrinaryLogic $acceptsNamedArguments,
3939
private TrinaryLogic $mustUseReturnValue,
4040
private ?Assertions $assertions = null,
41+
private ?TrinaryLogic $isBuiltinCallable = null,
4142
)
4243
{
4344
parent::__construct(
@@ -92,4 +93,9 @@ public function getAsserts(): Assertions
9293
return $this->assertions ?? Assertions::createEmpty();
9394
}
9495

96+
public function isBuiltin(): TrinaryLogic
97+
{
98+
return $this->isBuiltinCallable ?? TrinaryLogic::createNo();
99+
}
100+
95101
}

src/Reflection/GenericParametersAcceptorResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public static function resolve(array $argTypes, ParametersAcceptor $parametersAc
131131
$originalParametersAcceptor->acceptsNamedArguments(),
132132
$originalParametersAcceptor->mustUseReturnValue(),
133133
$originalParametersAcceptor->getAsserts(),
134+
$originalParametersAcceptor->isBuiltin(),
134135
);
135136
}
136137

src/Reflection/InaccessibleMethod.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ public function getAsserts(): Assertions
9898
return Assertions::createEmpty();
9999
}
100100

101+
public function isBuiltin(): TrinaryLogic
102+
{
103+
return TrinaryLogic::createNo();
104+
}
105+
101106
}

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ public static function combineAcceptors(array $acceptors): ExtendedParametersAcc
736736
$usedVariables = [];
737737
$acceptsNamedArguments = TrinaryLogic::createNo();
738738
$mustUseReturnValue = TrinaryLogic::createMaybe();
739+
$isBuiltin = TrinaryLogic::createNo();
739740

740741
foreach ($acceptors as $acceptor) {
741742
$returnTypes[] = $acceptor->getReturnType();
@@ -753,6 +754,7 @@ public static function combineAcceptors(array $acceptors): ExtendedParametersAcc
753754
$usedVariables = array_merge($usedVariables, $acceptor->getUsedVariables());
754755
$acceptsNamedArguments = $acceptsNamedArguments->or($acceptor->acceptsNamedArguments());
755756
$mustUseReturnValue = $mustUseReturnValue->or($acceptor->mustUseReturnValue());
757+
$isBuiltin = $isBuiltin->or($acceptor->isBuiltin());
756758
}
757759
$isVariadic = $isVariadic || $acceptor->isVariadic();
758760

@@ -860,6 +862,7 @@ public static function combineAcceptors(array $acceptors): ExtendedParametersAcc
860862
$usedVariables,
861863
$acceptsNamedArguments,
862864
$mustUseReturnValue,
865+
isBuiltinCallable: $isBuiltin,
863866
);
864867
}
865868

@@ -898,6 +901,7 @@ private static function wrapAcceptor(ParametersAcceptor $acceptor): ExtendedPara
898901
$acceptor->acceptsNamedArguments(),
899902
$acceptor->mustUseReturnValue(),
900903
$acceptor->getAsserts(),
904+
$acceptor->isBuiltin(),
901905
);
902906
}
903907

src/Reflection/ResolvedFunctionVariantWithCallable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
private TrinaryLogic $acceptsNamedArguments,
3131
private TrinaryLogic $mustUseReturnValue,
3232
private ?Assertions $assertions = null,
33+
private ?TrinaryLogic $isBuiltinCallable = null,
3334
)
3435
{
3536
}
@@ -124,4 +125,9 @@ public function getAsserts(): Assertions
124125
return $this->assertions ?? Assertions::createEmpty();
125126
}
126127

128+
public function isBuiltin(): TrinaryLogic
129+
{
130+
return $this->isBuiltinCallable ?? TrinaryLogic::createNo();
131+
}
132+
127133
}

src/Reflection/TrivialParametersAcceptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ public function getAsserts(): Assertions
108108
return Assertions::createEmpty();
109109
}
110110

111+
public function isBuiltin(): TrinaryLogic
112+
{
113+
return TrinaryLogic::createNo();
114+
}
115+
111116
}

src/Type/CallableType.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPStan\PhpDocParser\Printer\Printer;
1515
use PHPStan\Reflection\Assertions;
1616
use PHPStan\Reflection\Callables\CallableParametersAcceptor;
17-
use PHPStan\Reflection\Callables\FunctionCallableVariant;
1817
use PHPStan\Reflection\Callables\SimpleImpurePoint;
1918
use PHPStan\Reflection\Callables\SimpleThrowPoint;
2019
use PHPStan\Reflection\ClassMemberAccessAnswerer;
@@ -181,7 +180,7 @@ private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny): IsSup
181180

182181
$variantsResult = null;
183182
foreach ($type->getCallableParametersAcceptors($scope) as $variant) {
184-
$isBuiltinCallable = $variant instanceof FunctionCallableVariant && $variant->isBuiltin()->yes();
183+
$isBuiltinCallable = $variant->isBuiltin()->yes();
185184
$variant = ParametersAcceptorSelector::selectFromTypes($parameterTypes, [$variant], false);
186185
if (!$variant instanceof CallableParametersAcceptor) {
187186
return IsSuperTypeOfResult::createNo([]);
@@ -406,6 +405,11 @@ public function getAsserts(): Assertions
406405
return Assertions::createEmpty();
407406
}
408407

408+
public function isBuiltin(): TrinaryLogic
409+
{
410+
return TrinaryLogic::createNo();
411+
}
412+
409413
public function toNumber(): Type
410414
{
411415
return new ErrorType();

src/Type/ClosureType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function getAsserts(): Assertions
138138
return $this->assertions;
139139
}
140140

141+
public function isBuiltin(): TrinaryLogic
142+
{
143+
return TrinaryLogic::createNo();
144+
}
145+
141146
/**
142147
* @return array<non-empty-string, TemplateTag>
143148
*/

0 commit comments

Comments
 (0)