diff --git a/README.md b/README.md index 9f9fa62..a4afcea 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Short | Long | Description -h | --help | Display help message. -x | --exclude=EXCLUDE | Files and directories to exclude. -d | --directory=DIRECTORY | Directory to scan. [default: "./"] +-f | --files=FILES | Files to scan. none | --skip-classes | Don't check classes for docblocks. none | --skip-methods | Don't check methods for docblocks. none | --skip-signatures | Don't check docblocks against method signatures. diff --git a/src/CheckerCommand.php b/src/CheckerCommand.php index a1aba0b..09ec014 100644 --- a/src/CheckerCommand.php +++ b/src/CheckerCommand.php @@ -29,6 +29,8 @@ class CheckerCommand extends Command protected array $warnings = []; protected array $exclude = []; + + protected array $files = []; protected OutputInterface $output; @@ -46,6 +48,7 @@ protected function configure(): void ->setDescription('Check PHP files within a directory for appropriate use of Docblocks.') ->addOption('exclude', 'x', InputOption::VALUE_REQUIRED, 'Files and directories to exclude.', null) ->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Directory to scan.', './') + ->addOption('files', 'f', InputOption::VALUE_REQUIRED, 'Files to scan.', null) ->addOption('skip-classes', null, InputOption::VALUE_NONE, 'Don\'t check classes for docblocks.') ->addOption('skip-methods', null, InputOption::VALUE_NONE, 'Don\'t check methods for docblocks.') ->addOption('skip-signatures', null, InputOption::VALUE_NONE, 'Don\'t check docblocks against method signatures.') @@ -68,6 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $exclude = $input->getOption('exclude'); $json = $input->getOption('json'); $this->basePath = $input->getOption('directory'); + $files = $input->getOption('files'); $this->verbose = !$json; $this->output = $output; $failOnWarnings = $input->getOption('fail-on-warnings'); @@ -88,6 +92,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!\is_null($exclude)) { $this->exclude = \array_map('trim', \explode(',', $exclude)); } + + // Set up files: + if (!\is_null($files)) { + $this->files = \array_map('trim', \explode(',', $files)); + } // Check base path ends with a slash: if (\substr($this->basePath, -1) != '/') { @@ -96,7 +105,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Get files to check: $files = []; - $this->processDirectory('', $files); + if (count($this->files) > 0) { + $this->processFiles('', $this->files, $files); + } else { + $this->processDirectory('', $files); + } // Check files: $filesPerLine = (int)$input->getOption('files-per-line'); @@ -232,6 +245,28 @@ protected function processDirectory(string $path = '', array &$workList = []): v } } } + + /** + * Iterate through the files and check them out + * + * @param string $path + * @param string[] $files + * @param string[] $workList + */ + protected function processFiles(string $path = '', array $files = [], array &$workList = []): void + { + foreach ($files as $item) { + $itemPath = $path . $item; + + if (\in_array($itemPath, $this->exclude)) { + continue; + } + + if (is_file($itemPath) && pathinfo($itemPath)["extension"] == 'php') { + $workList[] = $itemPath; + } + } + } /** * Check a specific PHP file for errors.