From 9157feae045397851109932ce433ddce9430fb62 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 6 Mar 2023 13:31:15 +0100 Subject: [PATCH] NGGW-94 rename class, extend list of default extensions, refactor duplicated function --- src/Action/Action.php | 13 +++++++++++++ src/Action/CheckForTabs.php | 15 +-------------- ...cesInEOL.php => CheckForWhiteSpaceAtEOL.php} | 17 ++--------------- 3 files changed, 16 insertions(+), 29 deletions(-) rename src/Action/{CheckForSpacesInEOL.php => CheckForWhiteSpaceAtEOL.php} (59%) diff --git a/src/Action/Action.php b/src/Action/Action.php index ce682b0..6db1086 100644 --- a/src/Action/Action.php +++ b/src/Action/Action.php @@ -45,4 +45,17 @@ private function isEnabled(ActionConfig $action): bool { return $action->getOptions()->get('enabled', true); } + + public function getChangedFiles(Config\Action $action, Repository $repository): array + { + $excludedFiles = $action->getOptions()->get('excluded_files'); + $extensions = $action->getOptions()->get('extensions', ['php', 'twig']); + + $changedFiles = []; + foreach ($extensions as $extension) { + $changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)]; + } + + return array_diff($changedFiles, $excludedFiles); + } } diff --git a/src/Action/CheckForTabs.php b/src/Action/CheckForTabs.php index e25a7f8..c9669c9 100644 --- a/src/Action/CheckForTabs.php +++ b/src/Action/CheckForTabs.php @@ -25,7 +25,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con $arguments = array_merge( [ 'grep', - '\t', + '$\t', ], $files ); @@ -40,17 +40,4 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con $this->throwError($action, $io); } } - - private function getChangedFiles(Config\Action $action, Repository $repository): array - { - $excludedFiles = $action->getOptions()->get('excluded_files'); - $extensions = $action->getOptions()->get('extensions', ['php']); - - $changedFiles = []; - foreach ($extensions as $extension) { - $changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)]; - } - - return array_diff($changedFiles, $excludedFiles); - } } diff --git a/src/Action/CheckForSpacesInEOL.php b/src/Action/CheckForWhiteSpaceAtEOL.php similarity index 59% rename from src/Action/CheckForSpacesInEOL.php rename to src/Action/CheckForWhiteSpaceAtEOL.php index dcdba83..92c2458 100644 --- a/src/Action/CheckForSpacesInEOL.php +++ b/src/Action/CheckForWhiteSpaceAtEOL.php @@ -11,9 +11,9 @@ use function array_diff; use function implode; -final class CheckForSpacesInEOL extends Action +final class CheckForWhiteSpaceAtEOL extends Action { - protected const ERROR_MESSAGE = 'You have spaces at EOL!'; + protected const ERROR_MESSAGE = 'You have white spaces at EOL!'; protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void { @@ -40,17 +40,4 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con $this->throwError($action, $io); } } - - private function getChangedFiles(Config\Action $action, Repository $repository): array - { - $excludedFiles = $action->getOptions()->get('excluded_files'); - $extensions = $action->getOptions()->get('extensions', ['php']); - - $changedFiles = []; - foreach ($extensions as $extension) { - $changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)]; - } - - return array_diff($changedFiles, $excludedFiles); - } }