From ee7d42c43f9e841ae9266c64040bfcbb48e383a4 Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 19 Sep 2023 18:26:54 +0700 Subject: [PATCH] wip --- src/RuleSet/RuleSet.php | 3 +-- src/Utils.php | 5 +++++ tests/Unit/UtilsTest.php | 16 ++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 6e4bf94..ebf1cb2 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -70,8 +70,7 @@ private function getSetDefinitions($ruleSet) return new $relaxRuleSet; } - $pcfRuleSetClassName = Utils::pcsfRuleSetNameToClassName($ruleSet); - $pcfRuleSet = 'PhpCsFixer\\RuleSet\\Sets\\'.$pcfRuleSetClassName; + $pcfRuleSet = Utils::resolvePcsfRuleSetClass($ruleSet); if (class_exists($pcfRuleSet) && is_subclass_of($pcfRuleSet, PhpCsFixerRuleSetInterface::class)) { return new $pcfRuleSet; } diff --git a/src/Utils.php b/src/Utils.php index 3781b53..dfa2fa1 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -15,4 +15,9 @@ public static function pcsfRuleSetNameToClassName(string $ruleSetName): string return $className; } + + public static function resolvePcsfRuleSetClass(string $ruleSetName): string + { + return 'PhpCsFixer\\RuleSet\\Sets\\'.self::pcsfRuleSetNameToClassName($ruleSetName); + } } diff --git a/tests/Unit/UtilsTest.php b/tests/Unit/UtilsTest.php index ce09284..c822c63 100644 --- a/tests/Unit/UtilsTest.php +++ b/tests/Unit/UtilsTest.php @@ -21,10 +21,10 @@ public function pcsfRuleSetNameToClassName($actual, $expected): void public static function pcsfRuleSetNameToClassNameProvider() { return [ - '@PSR1' => ['@PSR1', 'PSR1Set'], + '@PSR1' => ['@PSR1', 'PSR1Set'], '@PhpCsFixer:risky' => ['@PhpCsFixer:risky', 'PhpCsFixerRiskySet'], - '@PER-CS1.0' => ['@PER-CS1.0', 'PERCS1x0Set'], - '@PER-CS1.0:risky' => ['@PER-CS1.0:risky', 'PERCS1x0RiskySet'], + '@PER-CS1.0' => ['@PER-CS1.0', 'PERCS1x0Set'], + '@PER-CS1.0:risky' => ['@PER-CS1.0:risky', 'PERCS1x0RiskySet'], ]; } @@ -34,7 +34,7 @@ public static function pcsfRuleSetNameToClassNameProvider() */ public function pcsfRuleSetClassExists($ruleSetName): void { - $class = 'PhpCsFixer\\RuleSet\\Sets\\'.Utils::pcsfRuleSetNameToClassName($ruleSetName); + $class = Utils::resolvePcsfRuleSetClass($ruleSetName); $this->assertTrue(class_exists($class)); } @@ -42,11 +42,11 @@ public function pcsfRuleSetClassExists($ruleSetName): void public static function pcsfRuleSetClassExistsProvider() { return [ - '@PSR1' => ['@PSR1'], + '@PSR1' => ['@PSR1'], '@PhpCsFixer:risky' => ['@PhpCsFixer:risky'], - '@PER-CS1.0' => ['@PER-CS1.0'], - '@PER-CS1.0:risky' => ['@PER-CS1.0:risky'], - '@PHP80Migration' => ['@PHP80Migration'], + '@PER-CS1.0' => ['@PER-CS1.0'], + '@PER-CS1.0:risky' => ['@PER-CS1.0:risky'], + '@PHP80Migration' => ['@PHP80Migration'], '@PHP80Migration:risky' => ['@PHP80Migration:risky'], ]; }