Skip to content

Commit

Permalink
NGGW-94 rename class, extend list of default extensions, refactor dup…
Browse files Browse the repository at this point in the history
…licated function
  • Loading branch information
Marijan Klaric committed Mar 6, 2023
1 parent a9a1c1a commit 9157fea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
13 changes: 13 additions & 0 deletions src/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@emodric

emodric Mar 6, 2023

Member

Should be protected.

{
$excludedFiles = $action->getOptions()->get('excluded_files');
$extensions = $action->getOptions()->get('extensions', ['php', 'twig']);

This comment has been minimized.

Copy link
@emodric

emodric Mar 6, 2023

Member

The default extension list should be provided by the function argument, so it can be overriden by the action.


$changedFiles = [];
foreach ($extensions as $extension) {
$changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)];
}

return array_diff($changedFiles, $excludedFiles);
}
}
15 changes: 1 addition & 14 deletions src/Action/CheckForTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
$arguments = array_merge(
[
'grep',
'\t',
'$\t',
],
$files
);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}

0 comments on commit 9157fea

Please sign in to comment.