Skip to content

Commit 9157fea

Browse files
author
Marijan Klaric
committed
NGGW-94 rename class, extend list of default extensions, refactor duplicated function
1 parent a9a1c1a commit 9157fea

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/Action/Action.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,17 @@ private function isEnabled(ActionConfig $action): bool
4545
{
4646
return $action->getOptions()->get('enabled', true);
4747
}
48+
49+
public function getChangedFiles(Config\Action $action, Repository $repository): array
50+
{
51+
$excludedFiles = $action->getOptions()->get('excluded_files');
52+
$extensions = $action->getOptions()->get('extensions', ['php', 'twig']);
53+
54+
$changedFiles = [];
55+
foreach ($extensions as $extension) {
56+
$changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)];
57+
}
58+
59+
return array_diff($changedFiles, $excludedFiles);
60+
}
4861
}

src/Action/CheckForTabs.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
2525
$arguments = array_merge(
2626
[
2727
'grep',
28-
'\t',
28+
'$\t',
2929
],
3030
$files
3131
);
@@ -40,17 +40,4 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
4040
$this->throwError($action, $io);
4141
}
4242
}
43-
44-
private function getChangedFiles(Config\Action $action, Repository $repository): array
45-
{
46-
$excludedFiles = $action->getOptions()->get('excluded_files');
47-
$extensions = $action->getOptions()->get('extensions', ['php']);
48-
49-
$changedFiles = [];
50-
foreach ($extensions as $extension) {
51-
$changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)];
52-
}
53-
54-
return array_diff($changedFiles, $excludedFiles);
55-
}
5643
}

src/Action/CheckForSpacesInEOL.php renamed to src/Action/CheckForWhiteSpaceAtEOL.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use function array_diff;
1212
use function implode;
1313

14-
final class CheckForSpacesInEOL extends Action
14+
final class CheckForWhiteSpaceAtEOL extends Action
1515
{
16-
protected const ERROR_MESSAGE = 'You have spaces at EOL!';
16+
protected const ERROR_MESSAGE = 'You have white spaces at EOL!';
1717

1818
protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void
1919
{
@@ -40,17 +40,4 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
4040
$this->throwError($action, $io);
4141
}
4242
}
43-
44-
private function getChangedFiles(Config\Action $action, Repository $repository): array
45-
{
46-
$excludedFiles = $action->getOptions()->get('excluded_files');
47-
$extensions = $action->getOptions()->get('extensions', ['php']);
48-
49-
$changedFiles = [];
50-
foreach ($extensions as $extension) {
51-
$changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)];
52-
}
53-
54-
return array_diff($changedFiles, $excludedFiles);
55-
}
5643
}

0 commit comments

Comments
 (0)