Skip to content

Commit

Permalink
Fixed Os util
Browse files Browse the repository at this point in the history
  • Loading branch information
ᏒᏊᏀᏋᏒ ᏕξᏐ committed Oct 1, 2019
1 parent 36d79e0 commit e4738a3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
12 changes: 7 additions & 5 deletions bin/super-giggle
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 6 additions & 2 deletions scripts/build-phar
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 18 additions & 17 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Util
*
* @var Os
*/
private $os;
public $os;


/**
Expand All @@ -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::',
];

Expand All @@ -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) .
Expand Down

0 comments on commit e4738a3

Please sign in to comment.