diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 76ff7ece6b..c9445f1dac 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -3164,8 +3164,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto $scope = $result->getScope(); if ($methodReflection !== null) { - $hasSideEffects = $methodReflection->hasSideEffects(); - if ($hasSideEffects->yes() || $methodReflection->getName() === '__construct') { + if ($methodReflection->getName() === '__construct' || $methodReflection->hasSideEffects()->yes()) { $this->callNodeCallback($nodeCallback, new InvalidateExprNode($normalizedExpr->var), $scope, $storage); $scope = $scope->invalidateExpression($normalizedExpr->var, true); } @@ -3376,11 +3375,11 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto if ( $methodReflection !== null && ( - $methodReflection->hasSideEffects()->yes() - || ( + ( !$methodReflection->isStatic() && $methodReflection->getName() === '__construct' ) + || $methodReflection->hasSideEffects()->yes() ) && $scope->isInClass() && $scope->getClassReflection()->is($methodReflection->getDeclaringClass()->getName()) diff --git a/src/Reflection/Native/NativeMethodReflection.php b/src/Reflection/Native/NativeMethodReflection.php index 7850ed1b5d..9a167e9862 100644 --- a/src/Reflection/Native/NativeMethodReflection.php +++ b/src/Reflection/Native/NativeMethodReflection.php @@ -166,10 +166,9 @@ public function getThrowType(): ?Type public function hasSideEffects(): TrinaryLogic { $name = strtolower($this->getName()); - $isVoid = $this->isVoid(); if ( $name !== '__construct' - && $isVoid + && $this->isVoid() ) { return TrinaryLogic::createYes(); } diff --git a/src/Rules/Api/ApiStaticCallRule.php b/src/Rules/Api/ApiStaticCallRule.php index 5441c16572..43a01e1d09 100644 --- a/src/Rules/Api/ApiStaticCallRule.php +++ b/src/Rules/Api/ApiStaticCallRule.php @@ -78,12 +78,14 @@ public function processNode(Node $node, Scope $scope): array private function isCovered(MethodReflection $methodReflection): bool { $declaringClass = $methodReflection->getDeclaringClass(); - $classDocBlock = $declaringClass->getResolvedPhpDoc(); - if ($methodReflection->getName() !== '__construct' && $classDocBlock !== null) { - foreach ($classDocBlock->getPhpDocNodes() as $phpDocNode) { - $apiTags = $phpDocNode->getTagsByName('@api'); - if (count($apiTags) > 0) { - return true; + if ($methodReflection->getName() !== '__construct') { + $classDocBlock = $declaringClass->getResolvedPhpDoc(); + if ($classDocBlock !== null) { + foreach ($classDocBlock->getPhpDocNodes() as $phpDocNode) { + $apiTags = $phpDocNode->getTagsByName('@api'); + if (count($apiTags) > 0) { + return true; + } } } } diff --git a/src/Rules/Methods/FinalPrivateMethodRule.php b/src/Rules/Methods/FinalPrivateMethodRule.php index 20ea6ab6fa..c2f10d9cac 100644 --- a/src/Rules/Methods/FinalPrivateMethodRule.php +++ b/src/Rules/Methods/FinalPrivateMethodRule.php @@ -23,11 +23,11 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { $method = $node->getMethodReflection(); - if ($scope->getPhpVersion()->producesWarningForFinalPrivateMethods()->no()) { + if ($method->getName() === '__construct') { return []; } - if ($method->getName() === '__construct') { + if ($scope->getPhpVersion()->producesWarningForFinalPrivateMethods()->no()) { return []; }