diff --git a/src/Analyser.php b/src/Analyser.php index f723d56..3bbfebf 100644 --- a/src/Analyser.php +++ b/src/Analyser.php @@ -38,7 +38,7 @@ final class Analyser /** * @psalm-param list $files */ - public function analyse(array $files): Result + public function analyse(array $files, bool $debug): Result { $errors = []; $directories = []; @@ -48,6 +48,10 @@ public function analyse(array $files): Result $linesOfCode = new LinesOfCode(0, 0, 0, 0); foreach ($files as $file) { + if ($debug) { + print $file . PHP_EOL; + } + $directories[] = dirname($file); try { diff --git a/src/CLI/Application.php b/src/CLI/Application.php index f3a9733..5a2c3e2 100644 --- a/src/CLI/Application.php +++ b/src/CLI/Application.php @@ -59,7 +59,7 @@ public function run(array $argv): int return 1; } - $result = (new Analyser)->analyse($files); + $result = (new Analyser)->analyse($files, $arguments->debug()); print (new TextResultFormatter)->format($result); @@ -87,6 +87,8 @@ private function help(): void --exclude Exclude files with in their path from the analysis (can be given multiple times) + --debug Print debugging information + EOT; } } diff --git a/src/CLI/Arguments.php b/src/CLI/Arguments.php index 5ab5619..565f63c 100644 --- a/src/CLI/Arguments.php +++ b/src/CLI/Arguments.php @@ -25,6 +25,7 @@ final class Arguments * @psalm-var list */ private array $exclude; + private bool $debug; private bool $help; private bool $version; @@ -33,11 +34,12 @@ final class Arguments * @psalm-param list $suffixes * @psalm-param list $exclude */ - public function __construct(array $directories, array $suffixes, array $exclude, bool $help, bool $version) + public function __construct(array $directories, array $suffixes, array $exclude, bool $debug, bool $help, bool $version) { $this->directories = $directories; $this->suffixes = $suffixes; $this->exclude = $exclude; + $this->debug = $debug; $this->help = $help; $this->version = $version; } @@ -66,6 +68,11 @@ public function exclude(): array return $this->exclude; } + public function debug(): bool + { + return $this->debug; + } + public function help(): bool { return $this->help; diff --git a/src/CLI/ArgumentsBuilder.php b/src/CLI/ArgumentsBuilder.php index 89ba18a..ea6d299 100644 --- a/src/CLI/ArgumentsBuilder.php +++ b/src/CLI/ArgumentsBuilder.php @@ -29,6 +29,7 @@ public function build(array $argv): Arguments [ 'suffix=', 'exclude=', + 'debug', 'help', 'version', ], @@ -44,6 +45,7 @@ public function build(array $argv): Arguments $directories = $options[1]; $exclude = []; $suffixes = ['.php']; + $debug = false; $help = false; $version = false; @@ -59,6 +61,11 @@ public function build(array $argv): Arguments break; + case '--debug': + $debug = true; + + break; + case 'h': case '--help': $help = true; @@ -83,6 +90,7 @@ public function build(array $argv): Arguments array_values($directories), $suffixes, $exclude, + $debug, $help, $version, ); diff --git a/tests/end-to-end/help.phpt b/tests/end-to-end/help.phpt index 59a8146..5fbd01a 100644 --- a/tests/end-to-end/help.phpt +++ b/tests/end-to-end/help.phpt @@ -19,3 +19,5 @@ Options for selecting files: (default: .php; can be given multiple times) --exclude Exclude files with in their path from the analysis (can be given multiple times) + + --debug Print debugging information diff --git a/tests/unit/AnalyserTest.php b/tests/unit/AnalyserTest.php index 398cea7..bd7e41d 100644 --- a/tests/unit/AnalyserTest.php +++ b/tests/unit/AnalyserTest.php @@ -28,6 +28,7 @@ public function testAnalysesFiles(): void __DIR__ . '/../_fixture/ExampleInterface.php', __DIR__ . '/../_fixture/ExampleTrait.php', ], + false, ); $this->assertFalse($result->hasErrors());