From c8e4f8bb309c01e339a06c6d4c0bfab27a0d6c08 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 1 Nov 2020 14:13:24 +0100 Subject: [PATCH] CallToStaticMethodStamentWithoutSideEffectsRule - skip parent::__construct() --- ...CallToStaticMethodStamentWithoutSideEffectsRule.php | 9 +++++++++ .../static-method-call-statement-no-side-effects.php | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Rules/Methods/CallToStaticMethodStamentWithoutSideEffectsRule.php b/src/Rules/Methods/CallToStaticMethodStamentWithoutSideEffectsRule.php index da9b105e72..0c96912f78 100644 --- a/src/Rules/Methods/CallToStaticMethodStamentWithoutSideEffectsRule.php +++ b/src/Rules/Methods/CallToStaticMethodStamentWithoutSideEffectsRule.php @@ -79,6 +79,15 @@ static function (Type $type) use ($methodName): bool { } $method = $calledOnType->getMethod($methodName, $scope); + if ( + ( + strtolower($method->getName()) === '__construct' + || strtolower($method->getName()) === strtolower($method->getDeclaringClass()->getName()) + ) + ) { + return []; + } + if ($method->hasSideEffects()->no()) { return [ RuleErrorBuilder::message(sprintf( diff --git a/tests/PHPStan/Rules/Methods/data/static-method-call-statement-no-side-effects.php b/tests/PHPStan/Rules/Methods/data/static-method-call-statement-no-side-effects.php index 3ebf084c28..9c4e984e42 100644 --- a/tests/PHPStan/Rules/Methods/data/static-method-call-statement-no-side-effects.php +++ b/tests/PHPStan/Rules/Methods/data/static-method-call-statement-no-side-effects.php @@ -25,3 +25,13 @@ public function doFoo() } } + +class FooException extends \Exception +{ + + public function __construct() + { + parent::__construct(); + } + +}