diff --git a/PhpcsChanged/Cli.php b/PhpcsChanged/Cli.php index b68bb39..dfe5b63 100644 --- a/PhpcsChanged/Cli.php +++ b/PhpcsChanged/Cli.php @@ -410,11 +410,11 @@ function reportMessagesAndExit(PhpcsMessages $messages, CliOptions $options, She exit($reporter->getExitCode($messages)); } -function fileHasValidExtension(\SplFileInfo $file, CliOptions $options = null): bool { +function fileHasValidExtension(\SplFileInfo $file, string $phpcsExtensions = ''): bool { // The following logic is copied from PHPCS itself. See https://github.com/squizlabs/PHP_CodeSniffer/blob/2ecd8dc15364cdd6e5089e82ffef2b205c98c412/src/Filters/Filter.php#L161 // phpcs:disable - if (empty($options->phpcsExtensions)) { + if (empty($phpcsExtensions)) { $AllowedExtensions = [ 'php', 'inc', @@ -422,7 +422,7 @@ function fileHasValidExtension(\SplFileInfo $file, CliOptions $options = null): 'css', ]; } else { - $AllowedExtensions = explode(',', $options->phpcsExtensions); + $AllowedExtensions = explode(',', $phpcsExtensions); } // Extensions can only be checked for files. diff --git a/PhpcsChanged/CliOptions.php b/PhpcsChanged/CliOptions.php index a3bb12d..12980ee 100644 --- a/PhpcsChanged/CliOptions.php +++ b/PhpcsChanged/CliOptions.php @@ -10,7 +10,9 @@ class CliOptions { * * Use the `Modes` constants for this purpose rather than the strings. * - * @var 'svn'|'manual'|'git-staged'|'git-unstaged'|'git-base'|null + * If this is null, validation will fail. + * + * @var 'svn'|'manual'|'git-staged'|'git-unstaged'|'git-base'|'info'|null */ public $mode; @@ -254,6 +256,9 @@ public static function fromArray(array $options): self { if (isset($options['error-severity'])) { $cliOptions->errorSeverity = $options['error-severity']; } + if (isset($options['i'])) { + $cliOptions->mode = Modes::INFO_ONLY; + } $cliOptions->validate(); return $cliOptions; } diff --git a/PhpcsChanged/Modes.php b/PhpcsChanged/Modes.php index bb07f80..1b6f626 100644 --- a/PhpcsChanged/Modes.php +++ b/PhpcsChanged/Modes.php @@ -4,6 +4,7 @@ namespace PhpcsChanged; class Modes { + const INFO_ONLY = 'info'; const SVN = 'svn'; const MANUAL = 'manual'; const GIT_STAGED = 'git-staged'; diff --git a/bin/phpcs-changed b/bin/phpcs-changed index 4a6eb49..f1f1705 100755 --- a/bin/phpcs-changed +++ b/bin/phpcs-changed @@ -75,7 +75,7 @@ foreach( $fileNames as $file ) { continue; } $iterator = new \RecursiveIteratorIterator(new \RecursiveCallbackFilterIterator(new \RecursiveDirectoryIterator($file, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)), function($file, $key, $iterator) use($options) { - if ($file->isFile() && !fileHasValidExtension($file, CliOptions::fromArray($options))) { + if ($file->isFile() && !fileHasValidExtension($file, isset($options['extensions']) && is_string($options['extensions']) ? $options['extensions'] : '')) { return false; } return $iterator->hasChildren() || $file->isFile() ? true : false;