Skip to content

Commit

Permalink
Implement --debug CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 28, 2023
1 parent c9e1263 commit ec10d52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class Analyser
/**
* @psalm-param list<non-empty-string> $files
*/
public function analyse(array $files): Result
public function analyse(array $files, bool $debug): Result
{
$errors = [];
$directories = [];
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/CLI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -87,6 +87,8 @@ private function help(): void
--exclude <path> Exclude files with <path> in their path from the analysis
(can be given multiple times)
--debug Print debugging information

EOT;
}
}
9 changes: 8 additions & 1 deletion src/CLI/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class Arguments
* @psalm-var list<non-empty-string>
*/
private array $exclude;
private bool $debug;
private bool $help;
private bool $version;

Expand All @@ -33,11 +34,12 @@ final class Arguments
* @psalm-param list<non-empty-string> $suffixes
* @psalm-param list<non-empty-string> $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;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/CLI/ArgumentsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function build(array $argv): Arguments
[
'suffix=',
'exclude=',
'debug',
'help',
'version',
],
Expand All @@ -44,6 +45,7 @@ public function build(array $argv): Arguments
$directories = $options[1];
$exclude = [];
$suffixes = ['.php'];
$debug = false;
$help = false;
$version = false;

Expand All @@ -59,6 +61,11 @@ public function build(array $argv): Arguments

break;

case '--debug':
$debug = true;

break;

case 'h':
case '--help':
$help = true;
Expand All @@ -83,6 +90,7 @@ public function build(array $argv): Arguments
array_values($directories),
$suffixes,
$exclude,
$debug,
$help,
$version,
);
Expand Down

0 comments on commit ec10d52

Please sign in to comment.