diff --git a/src/ArgvParser.php b/src/ArgvParser.php index 263ba34..23bd136 100644 --- a/src/ArgvParser.php +++ b/src/ArgvParser.php @@ -20,22 +20,22 @@ class ArgvParser protected $_desc; - protected $_options = []; + protected $_options = []; - protected $_values = []; + protected $_values = []; - protected $_args = []; + protected $_args = []; - protected $_events = []; + protected $_events = []; protected $_allowUnknown = false; - protected $_wasVariadic = false; + protected $_wasVariadic = false; public function __construct($name, $desc = null, $allowUnknown = false) { - $this->_name = $name; - $this->_desc = $desc; + $this->_name = $name; + $this->_desc = $desc; $this->_allowUnknown = $allowUnknown; $this->addDefaultOptions(); @@ -65,7 +65,7 @@ public function option($cmd, $desc = '', callable $filter = null, $default = nul } $this->_values[$option->attributeName()] = $option->default(); - $this->_options[$option->long()] = $option; + $this->_options[$option->long()] = $option; return $this; } @@ -83,8 +83,8 @@ public function parse(array $argv) { \array_shift($argv); - $argv = $this->normalize($argv); - $count = \count($argv); + $argv = $this->normalize($argv); + $count = \count($argv); for ($i = 0; $i < $count; $i++) { list($arg, $nextArg) = [$argv[$i], isset($argv[$i + 1]) ? $argv[$i + 1] : null]; @@ -110,10 +110,10 @@ protected function parseArgs($arg) protected function parseOptions($arg, $nextArg, &$i) { - $value = \substr($nextArg, 0, 1) === '-' ? null : $nextArg; + $value = \substr($nextArg, 0, 1) === '-' ? null : $nextArg; $isValue = $value !== null; - $this->_lastOption = $option = $this->optionFor($arg); + $this->_lastOption = $option = $this->optionFor($arg); $this->_wasVariadic = $option ? $option->variadic() : false; if (!$option) { @@ -139,7 +139,7 @@ protected function handleUnknown($arg, $value) // Has some value, error! if ($this->_values) { throw new \RuntimeException( - \sprintf("Option %s not registered", $arg) + \sprintf('Option %s not registered', $arg) ); } @@ -262,8 +262,6 @@ protected function optionFor($arg) return $option; } } - - return null; } protected function emit($event) diff --git a/src/Color.php b/src/Color.php index a4989fc..47e4707 100644 --- a/src/Color.php +++ b/src/Color.php @@ -12,17 +12,17 @@ */ class Color { - const FG_RED = 31; - const FG_GREEN = 32; + const FG_RED = 31; + const FG_GREEN = 32; const FG_YELLOW = 33; - const FG_BLUE = 36; + const FG_BLUE = 36; // @todo protected static $format = "\033[:bold:;:fg:;:bg:m:text:\033[0m"; protected static $styles = []; - protected static $muted = false; + protected static $muted = false; public static function error($text, array $style = [], $eol = false) { diff --git a/src/Option.php b/src/Option.php index c529ff4..c553da5 100644 --- a/src/Option.php +++ b/src/Option.php @@ -32,9 +32,9 @@ class Option public function __construct($cmd, $desc = '', $default = null, callable $filter = null) { - $this->desc = $desc; - $this->default = $default; - $this->filter = $filter; + $this->desc = $desc; + $this->default = $default; + $this->filter = $filter; $this->required = \strpos($cmd, '<') !== false; $this->optional = \strpos($cmd, '[') !== false; diff --git a/tests/ArgvParserTest.php b/tests/ArgvParserTest.php index 0bee513..3412b41 100644 --- a/tests/ArgvParserTest.php +++ b/tests/ArgvParserTest.php @@ -11,7 +11,7 @@ public function test_new() { $p = new ArgvParser('ArgvParser'); - $p->version('0.0.' . rand(1, 10)); + $p->version('0.0.'.rand(1, 10)); $data = $this->data(); foreach ($data['options'] as $option) { @@ -36,6 +36,6 @@ public function test_new() public function data() { - return require __DIR__ . '/fixture.php'; + return require __DIR__.'/fixture.php'; } } diff --git a/tests/OptionTest.php b/tests/OptionTest.php index e2756cd..ecb67a8 100644 --- a/tests/OptionTest.php +++ b/tests/OptionTest.php @@ -51,7 +51,7 @@ public function test_filter() $this->assertSame(10, $o->filter('10')); $in = 'apple'; - $o = new Option('-f, --fruit', 'Age', 'orange', 'strtoupper'); + $o = new Option('-f, --fruit', 'Age', 'orange', 'strtoupper'); $this->assertNotSame($o->filter($in), $in); $this->assertSame('APPLE', $o->filter($in)); @@ -64,7 +64,7 @@ public function test_filter() public function data() { - $f = require __DIR__ . '/fixture.php'; + $f = require __DIR__.'/fixture.php'; return $f['options']; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6c8c4f5..e91cc12 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,3 @@ [ 'space req' => [ - 'cmd' => '-v --virtual ', + 'cmd' => '-v --virtual ', 'expect' => [ - 'long' => '--virtual', - 'short' => '-v', + 'long' => '--virtual', + 'short' => '-v', 'required' => true, 'variadic' => false, 'name' => 'virtual', @@ -14,10 +14,10 @@ ], ], 'comma opt' => [ - 'cmd' => '-f,--fruit [opt]', + 'cmd' => '-f,--fruit [opt]', 'expect' => [ - 'long' => '--fruit', - 'short' => '-f', + 'long' => '--fruit', + 'short' => '-f', 'required' => false, 'variadic' => false, 'name' => 'fruit', @@ -25,10 +25,10 @@ ], ], 'pipe ...' => [ - 'cmd' => '-a|--apple [opt...]', + 'cmd' => '-a|--apple [opt...]', 'expect' => [ - 'long' => '--apple', - 'short' => '-a', + 'long' => '--apple', + 'short' => '-a', 'required' => false, 'variadic' => true, 'name' => 'apple', @@ -37,10 +37,10 @@ ], ], '--no' => [ - 'cmd' => '-n|--no-shit', + 'cmd' => '-n|--no-shit', 'expect' => [ - 'long' => '--no-shit', - 'short' => '-n', + 'long' => '--no-shit', + 'short' => '-n', 'required' => false, 'variadic' => false, 'name' => 'shit', @@ -49,10 +49,10 @@ ], ], '--with' => [ - 'cmd' => '-w|--with-this', + 'cmd' => '-w|--with-this', 'expect' => [ - 'long' => '--with-this', - 'short' => '-w', + 'long' => '--with-this', + 'short' => '-w', 'required' => false, 'variadic' => false, 'name' => 'this', @@ -62,10 +62,10 @@ ], ], 'camel case' => [ - 'cmd' => '-C|--camel-case', + 'cmd' => '-C|--camel-case', 'expect' => [ - 'long' => '--camel-case', - 'short' => '-C', + 'long' => '--camel-case', + 'short' => '-C', 'required' => false, 'variadic' => false, 'name' => 'camel-case', @@ -98,6 +98,6 @@ [ 'argv' => ['--virtual'], 'throws' => [\RuntimeException::class, 'Option -v|--virtual is required'], - ] + ], ], ];