From c4f5fe8ced7e8cc1d3e19d7ba09a13cca0c4155a Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Wed, 18 May 2016 08:51:50 +0200 Subject: [PATCH] Handler its_ with phpspec --- .../Contrib/PhpspecScenarioScopeFixerSpec.php | 8 ++++++++ .../Contrib/PhpspecScenarioScopeFixer.php | 18 +++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixerSpec.php b/spec/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixerSpec.php index 2f8ad07..b3c5194 100644 --- a/spec/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixerSpec.php +++ b/spec/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixerSpec.php @@ -42,6 +42,10 @@ public function it_is_a_spec(\$file) { public function itIsNotASpec(\$file) { return; } + + public function its_other_function(\$file) { + return; + } } SPEC; @@ -69,6 +73,10 @@ function it_is_a_spec(\$file) { public function itIsNotASpec(\$file) { return; } + + function its_other_function(\$file) { + return; + } } SPEC; diff --git a/src/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixer.php b/src/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixer.php index 9b850de..e3246de 100644 --- a/src/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixer.php +++ b/src/PedroTroller/CS/Fixer/Contrib/PhpspecScenarioScopeFixer.php @@ -33,17 +33,17 @@ public function fix(\SplFileInfo $file, $content) $name = $tokens[$next]; $scope = $tokens[$previous]; - if (false === in_array($name->getContent(), array('let', 'letGo')) - && false === $this->startsWith($name->getContent(), 'it_')) { - continue; - } + switch (true) { + case in_array($name->getContent(), array('let', 'letGo')): + case $this->startsWith($name->getContent(), 'it_'): + case $this->startsWith($name->getContent(), 'its_'): + if (T_PUBLIC !== $scope->getId()) { + continue; + } - if (T_PUBLIC !== $scope->getId()) { - continue; + $tokens->overrideAt($previous, ''); + $tokens->removeTrailingWhitespace($previous); } - - $tokens->overrideAt($previous, ''); - $tokens->removeTrailingWhitespace($previous); } return $tokens->generateCode();