From fb1bf1f5542c06202b5b932ba2428b98688d0ede Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 12 Feb 2021 02:02:28 +0100 Subject: [PATCH] [Privatization] Skip on open-source abstract (#5516) --- .../MakeOnlyUsedByChildrenProtectedRector.php | 4 +++ .../skip_abstract_class.php.inc | 14 +++++++++ .../OpenSourceRectorTest.php | 30 +++++++++++++++++++ .../config/configured_rule.php | 16 ++++++++++ 4 files changed, 64 insertions(+) create mode 100644 rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/FixtureOpenSource/skip_abstract_class.php.inc create mode 100644 rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/OpenSourceRectorTest.php create mode 100644 rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/config/configured_rule.php diff --git a/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php b/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php index 0b9c7857c37d..15ed9c982d16 100644 --- a/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php +++ b/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php @@ -143,6 +143,10 @@ private function shouldSkip(ClassMethod $classMethod): bool return true; } + if ($currentClass->isAbstract() && $this->isOpenSourceProjectType()) { + return true; + } + $className = $classMethod->getAttribute(AttributeKey::CLASS_NAME); if ($className === null) { return true; diff --git a/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/FixtureOpenSource/skip_abstract_class.php.inc b/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/FixtureOpenSource/skip_abstract_class.php.inc new file mode 100644 index 000000000000..38998eb45068 --- /dev/null +++ b/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/FixtureOpenSource/skip_abstract_class.php.inc @@ -0,0 +1,14 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource'); + } + + protected function provideConfigFileInfo(): ?SmartFileInfo + { + return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); + } +} diff --git a/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/config/configured_rule.php b/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/config/configured_rule.php new file mode 100644 index 000000000000..54eb1ceda2eb --- /dev/null +++ b/rules/privatization/tests/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector/config/configured_rule.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); + + $services = $containerConfigurator->services(); + $services->set(MakeOnlyUsedByChildrenProtectedRector::class); +};