diff --git a/bin/super-giggle b/bin/super-giggle index bd44f12..fe46a72 100755 --- a/bin/super-giggle +++ b/bin/super-giggle @@ -16,15 +16,17 @@ if (file_exists(__DIR__ . '/../vendor/autoload.php') === true) { require __DIR__ . '/../src/Util.php'; } -use SuperGiggle\Main; -use SuperGiggle\Util; +use SuperGiggle\{Main, Util, Os}; $util = new Util; +$util->setOs(new Os()); $opts = $util->parseArgs(); if (isset($opts['help'])) { $util->printUsage(); } -$phpcs = new Main(); -$phpcs->setUtil($util); -$phpcs->run($opts); + + +$sg = new Main(); +$sg->setUtil($util); +$sg->run($opts); diff --git a/scripts/build-phar b/scripts/build-phar index 8c1208f..130b104 100755 --- a/scripts/build-phar +++ b/scripts/build-phar @@ -21,13 +21,17 @@ $phar->setStub( Phar::mapPhar("super-giggle.phar"); require_once "phar://super-giggle.phar/Main.php"; require_once "phar://super-giggle.phar/Util.php"; +require_once "phar://super-giggle.phar/Os.php"; -$opts = SuperGiggle\Util::parseArgs(); +$util = new SuperGiggle\Util(); +$util->setOs(new SuperGiggle\Os()); +$opts = $util->parseArgs(); if (isset($opts["help"])) { - SuperGiggle\Util::printUsage(); + $util->printUsage(); } $sg = new SuperGiggle\Main(); +$sg->setUtil($util); $sg->isPhar = true; $sg->run($opts); exit(0); diff --git a/src/Main.php b/src/Main.php index eb7afdf..34f887d 100644 --- a/src/Main.php +++ b/src/Main.php @@ -214,7 +214,7 @@ private function parsePHPCSErrors(string $file): array $phpcs = $this->options['phpcs']; $warnings = $this->options['warnings']; $phpVersion = (empty($this->options['php-version']) === true) ? '' : "--runtime-set php_version {$this->options['php-version']}"; - $execString = ($this->util->isWindows() === true) ? "$phpcs --report=json --standard=$stndr $file $warnings" : + $execString = ($this->util->os->isWindows() === true) ? "$phpcs --report=json --standard=$stndr $file $warnings" : "$php $phpcs --report=json --standard=$stndr '$file' $warnings $phpVersion"; $response = shell_exec($execString); diff --git a/src/Util.php b/src/Util.php index 499500c..dc3472a 100644 --- a/src/Util.php +++ b/src/Util.php @@ -24,7 +24,7 @@ class Util * * @var Os */ - private $os; + public $os; /** @@ -35,17 +35,17 @@ class Util public function parseArgs(): array { $alloweds = [ - 'commit::', + 'commit:', 'help', - 'all::', + 'all', 'verbose::', - 'diff::', - 'file::', + 'diff', + 'file:', 'php::', 'php-version::', - 'phpcs::', - 'repo::', - 'standard::', + 'phpcs:', + 'repo:', + 'standard:', 'warnings::', ]; @@ -67,15 +67,16 @@ public function printUsage(): void { echo " Usage: \033[0;35msuper-giggle [--commit]\033[0m\n\n"; $options = [ - 'standard' => 'The name or path of the coding standard to use', - 'diff' => 'Validate changes on the current repository, between commits or branches', - 'all' => 'Performs a full check and not only the changed lines', - 'repo' => 'Indicates the git working directory. Defaults to current cwd', - 'phpcs' => 'Indicates the php binary. Defaults to ENV', - 'type' => 'The type of check. Defaults to "show" changes of a given commit. ', - 'help' => 'Print this help', - 'verbose' => 'Prints additional information', - 'warnings' => 'Also displays warnings', + 'standard' => 'The name or path of the coding standard to use', + 'diff' => 'Validate changes on the current repository, between commits or branches', + 'all' => 'Performs a full check and not only the changed lines', + 'repo' => 'Indicates the git working directory. Defaults to current cwd', + 'phpcs' => 'Indicates the php binary. Defaults to ENV', + 'php-version' => 'allows to specify a PHP version to check the code accordingly', + 'type' => 'The type of check. Defaults to "show" changes of a given commit. ', + 'help' => 'Print this help', + 'verbose' => 'Prints additional information', + 'warnings' => 'Also displays warnings', ]; foreach ($options as $name => $description) { echo str_pad("\033[1;31m --$name ", 22, ' ', STR_PAD_RIGHT) .