From 907e371bba77d3c9d1e263e182863deeb74c9f17 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Fri, 7 Jul 2017 15:39:40 -0700 Subject: [PATCH] Add an option to print to stderr as files are being scanned This is helpful on large projects, to confirm that progress is being made and to allow users to guess how much time is left. --- README.md | 7 +++++++ classes/options.php | 9 ++++++++- mar.php | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d02598..a2c9063 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,13 @@ Give a try, use the included `testcases.php` to generate a report: *Example: -x="php,inc"* ``` +**-p** +``` + Print progress output. + Print a message to stderr as each file is being analyzed. + *Example: -p* +``` + **--php** ``` File path to the PHP binary to use for syntax checking. diff --git a/classes/options.php b/classes/options.php index 41daca5..f2e4b20 100644 --- a/classes/options.php +++ b/classes/options.php @@ -85,7 +85,14 @@ class options { 'description' => 'A comma separated list of file extensions to consider as PHP files. Defaults to "php"', 'example' => '-x="php,inc"', 'comma_delimited' => true - ] + ], + 'p' => [ + 'option' => self::OPTION_OPTIONAL, + 'value' => self::VALUE_NONE, + 'comment' => 'Print progress output.', + 'description' => 'Print a message to stderr as each file is being analyzed.', + 'example' => '-p', + ], ]; /** diff --git a/mar.php b/mar.php index 2bc879e..57013ad 100644 --- a/mar.php +++ b/mar.php @@ -113,8 +113,12 @@ private function run() { } else { $checkSyntax = false; } + $print_progress = $this->options->getOption('p'); while (($lines = $this->scanner->scanNextFile()) !== false) { + if ($print_progress) { + fprintf(STDERR, "Scanning '%s'\n", $filePath); + } $totalFiles++; //Check syntax and assign a line to grab if needed.