Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"require": {
"php": "^7.4|^8.0",
"phpstan/phpstan": "^2.2.6"
"phpstan/phpstan": "^2.2.10"
},
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"nikic/php-parser": "^5.8",
"ondram/ci-detector": "^4.2",
"phpstan/phpdoc-parser": "^2.3.3",
"phpstan/phpstan": "^2.2.6",
"phpstan/phpstan": "^2.2.10",
"react/child-process": "^0.6.5",
"react/event-loop": "^1.6",
"react/socket": "^1.17",
Expand Down
6 changes: 6 additions & 0 deletions rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Name;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\TypeCombinator;
use Rector\Enum\ObjectReference;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
Expand All @@ -34,6 +35,11 @@ public function isExists(array $calls, string $classMethodName, string $classNam
$callerRoot = $call instanceof StaticCall ? $call->class : $call->var;
$callerType = $this->nodeTypeResolver->getType($callerRoot);

// a nullsafe call caller is nullable by design; drop null to resolve the object class
if ($call instanceof NullsafeMethodCall) {
$callerType = TypeCombinator::removeNull($callerType);
}

$callerTypeClassName = ClassNameFromObjectTypeResolver::resolve($callerType);
if ($callerTypeClassName === null) {
// the caller scope is unreachable, e.g. behind mutual recursion, so the type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\InterpolatedString;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Fiber\FiberScope;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Native\ExtendedNativeParameterReflection;
use PHPStan\Reflection\ParametersAcceptor;
Expand Down Expand Up @@ -247,10 +246,6 @@ private function isAnErrorType(Expr $expr, Type $type, Scope $scope): bool
}

$parentScope = $scope->getParentScope();
if ($parentScope instanceof FiberScope) {
$parentScope = $parentScope->toMutatingScope();
}

if ($parentScope instanceof Scope) {
return $parentScope->getType($expr) instanceof ErrorType;
}
Expand Down
16 changes: 10 additions & 6 deletions src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
use PhpParser\Node\Stmt\While_;
use PhpParser\Node\UnionType;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Fiber\FiberScope;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\NodeCallbackScope;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeContext;
use PHPStan\Analyser\UndefinedVariableException;
Expand Down Expand Up @@ -157,8 +157,8 @@ public function processNodes(
&$nodeCallback,
$filePath,
): void {
if ($mutatingScope instanceof FiberScope) {
$mutatingScope = $mutatingScope->toMutatingScope();
if ($mutatingScope instanceof NodeCallbackScope) {
$mutatingScope = $mutatingScope->toWalkScope();
}

// the class reflection is resolved AFTER entering to class node
Expand Down Expand Up @@ -226,7 +226,6 @@ public function processNodes(
$node instanceof Eval_ ||
$node instanceof Print_ ||
$node instanceof Exit_ ||
$node instanceof ArrowFunction ||
$node instanceof Include_ ||
$node instanceof Instanceof_
) && $node->expr instanceof Expr) {
Expand Down Expand Up @@ -637,8 +636,13 @@ private function processProperty(Property $property, MutatingScope $mutatingScop

private function processBinaryOp(BinaryOp $binaryOp, MutatingScope $mutatingScope): void
{
$binaryOp->left->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$binaryOp->right->setAttribute(AttributeKey::SCOPE, $mutatingScope);
if (! $binaryOp->left->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) {
$binaryOp->left->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

if (! $binaryOp->right->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) {
$binaryOp->right->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
}

private function processTernary(Ternary $ternary, MutatingScope $mutatingScope): void
Expand Down
Loading