diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector/Fixture/used_via_self_reflection.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector/Fixture/used_via_self_reflection.php.inc new file mode 100644 index 00000000000..bf1d0f7bae7 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector/Fixture/used_via_self_reflection.php.inc @@ -0,0 +1,48 @@ +getInvocations() as $invocation) { + // asserts test_function_a / test_function_b are found + } + } + + private function deadend(): void + { + $a = $b = null; + test_function_a($this, $a + $b); + test_function_b("string", 123); + } +} + +?> +----- +getInvocations() as $invocation) { + // asserts test_function_a / test_function_b are found + } + } +} + +?> diff --git a/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_class_exists_after_eval.php.inc b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_class_exists_after_eval.php.inc new file mode 100644 index 00000000000..4393f6882c2 --- /dev/null +++ b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_class_exists_after_eval.php.inc @@ -0,0 +1,16 @@ +' . $compiled); + } + + return new $class(); + } +} diff --git a/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_function_exists_enum.php.inc b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_function_exists_enum.php.inc new file mode 100644 index 00000000000..eebd1676338 --- /dev/null +++ b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_function_exists_enum.php.inc @@ -0,0 +1,25 @@ + $enums + */ + public function expand(array $enums): array + { + $cases = []; + foreach ($enums as $enum) { + if (is_string($enum) && function_exists('enum_exists') && enum_exists($enum)) { + foreach ($enum::cases() as $case) { + $cases[] = $case; + } + } else { + $cases[] = $enum; + } + } + + return $cases; + } +} diff --git a/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_interface_exists_in_loop.php.inc b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_interface_exists_in_loop.php.inc new file mode 100644 index 00000000000..30f48844d83 --- /dev/null +++ b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_interface_exists_in_loop.php.inc @@ -0,0 +1,20 @@ +betterNodeFinder->findInstancesOf( + $hasNonStaticNode = (bool) $this->betterNodeFinder->findInstancesOf( $expr, [ PropertyFetch::class, @@ -180,6 +200,20 @@ private function shouldSkipExpr(Expr $expr): bool StaticCall::class, ] ); + + if ($hasNonStaticNode) { + return true; + } + + /** @var FuncCall[] $funcCalls */ + $funcCalls = $this->betterNodeFinder->findInstancesOf($expr, [FuncCall::class]); + foreach ($funcCalls as $funcCall) { + if ($this->isNames($funcCall, self::RUNTIME_STATE_FUNCTIONS)) { + return true; + } + } + + return false; } private function refactorIfWithBooleanAnd(If_ $if): ?If_