From acc604d7110e6b040418392849101d5d9b67858e Mon Sep 17 00:00:00 2001 From: Chris Shennan Date: Wed, 31 Oct 2018 15:01:41 +0000 Subject: [PATCH] Exclude folders option - Added a new option (o) to allow folders to be omitted (i.e. vendors) --- classes/options.php | 477 +++++++++++++++++++++++--------------------- classes/scanner.php | 299 +++++++++++++++------------ mar.php | 360 +++++++++++++++++---------------- 3 files changed, 600 insertions(+), 536 deletions(-) diff --git a/classes/options.php b/classes/options.php index 41daca5..698e051 100644 --- a/classes/options.php +++ b/classes/options.php @@ -10,235 +10,250 @@ namespace alexia\mar; -class options { - /** - * Option Optional - * - * @var constant - */ - const OPTION_OPTIONAL = 1; - - /** - * Option Required - * - * @var constant - */ - const OPTION_REQUIRED = 2; - - /** - * Value None - * - * @var constant - */ - const VALUE_NONE = 0; - - /** - * Value Optional - * - * @var constant - */ - const VALUE_OPTIONAL = 1; - - /** - * Value Required - * - * @var constant - */ - const VALUE_REQUIRED = 2; - - /** - * Short(One dash, single letter) Options - * - * @var array - */ - private $validShortOptions = [ - 'f' => [ - 'option' => self::OPTION_REQUIRED, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'Path to the file or folder to run against.', - 'description' => 'The location of the file or folder to use for generating the report. A fully qualified path is recommended. Relative paths will be based off the php7mar folder.', - 'example' => '-f="/path/to/folder"' - ], - 'r' => [ - 'option' => self::OPTION_OPTIONAL, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'Path to the folder to save the report.', - 'description' => 'The location to save the final report. By default this saves into the reports/ folder inside the php7mar folder. A fully qualified path is recommended. Relative paths will be based off the php7mar folder.', - 'example' => '-r="/path/to/folder"' - ], - 't' => [ - 'option' => self::OPTION_OPTIONAL, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'Types of tests to run.', - 'description' => 'By default all tests will run. This option allows tests to be selected using a comma delimited list. Allowable values: critical, nuance, and syntax.', - 'example' => '-t="syntax,nuance"', - 'allowed' => [ - 'critical', - 'nuance', - 'syntax' - ] - ], - 'x' => [ - 'option' => self::OPTION_OPTIONAL, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'File extensions to include when scanning a directory.', - 'description' => 'A comma separated list of file extensions to consider as PHP files. Defaults to "php"', - 'example' => '-x="php,inc"', - 'comma_delimited' => true - ] - ]; - - /** - * Long(Two dashes, multiple letter) Options - * - * @var array - */ - private $validLongOptions = [ - 'php' => [ - 'option' => self::OPTION_OPTIONAL, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'File path to the PHP binary to use for syntax checking.', - 'description' => 'If this option is not used syntax checking will use the default PHP installtion to test syntax.', - 'example' => '--php="/path/to/php/binary/php"' - ], - /*'format' => [ - 'option' => self::OPTION_OPTIONAL, - 'value' => self::VALUE_REQUIRED, - 'comment' => 'Format of the report output.', - 'description' => 'By default the report will be formatted with HTML. Valid formats are: plain, markdown, html', - 'example' => '--format="markdown"', - 'allowed' => [ - 'plain', - 'markdown', - 'html' - ] - ]*/ - ]; - - /** - * Validated Options - * - * @var array - */ - private $options = []; - - /** - * Main Constructor - * - * @access public - * @return void - */ - public function __construct() { - global $argv; - - //Temporary variable so we do not override the global. - $_argv = $argv; - array_shift($_argv); - $options = $_argv; - - if (empty($options)) { - $this->printOptionsAndExit(); - } - - foreach ($options as $option) { - $this->parseOption($option); - } - $this->enforceOptions(); - } - - /** - * Print out available options and exit. - * - * @access private - * @return void - */ - private function printOptionsAndExit() { - echo "Available Options:\n"; - foreach ($this->validShortOptions as $option => $info) { - echo "-\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n"; - } - foreach ($this->validLongOptions as $option => $info) { - echo "--\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n"; - } - exit; - } - - /** - * Parse a raw option - * - * @access private - * @param string Raw option from the command line. - * @return array Option name, value if provided. - */ - private function parseOption($rawOption) { - $regex = "#^(?P