diff --git a/src/CommandLine/Console.php b/src/CommandLine/Console.php index c2871df..d64f1c3 100644 --- a/src/CommandLine/Console.php +++ b/src/CommandLine/Console.php @@ -20,24 +20,24 @@ class Console public function __construct() { $this->useColors = PHP_SAPI === 'cli' && ((function_exists('posix_isatty') && posix_isatty(STDOUT)) - || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE || getenv('term') === 'xterm-256color'); + || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== false || getenv('term') === 'xterm-256color'); } - public function useColors($state = TRUE) + public function useColors($state = true) { $this->useColors = (bool) $state; } - public function color($color = NULL, $s = NULL) + public function color($color = null, $s = null) { static $colors = [ 'black' => '0;30', 'gray' => '1;30', 'silver' => '0;37', 'white' => '1;37', 'navy' => '0;34', 'blue' => '1;34', 'green' => '0;32', 'lime' => '1;32', 'teal' => '0;36', 'aqua' => '1;36', 'maroon' => '0;31', 'red' => '1;31', 'purple' => '0;35', 'fuchsia' => '1;35', 'olive' => '0;33', 'yellow' => '1;33', - NULL => '0', + null => '0', ]; if ($this->useColors) { $c = explode('/', $color); @@ -45,7 +45,7 @@ public function color($color = NULL, $s = NULL) . ($c[0] ? $colors[$c[0]] : '') . (empty($c[1]) ? '' : ';4' . substr($colors[$c[1]], -1)) . 'm' . $s - . ($s === NULL ? '' : "\033[0m"); + . ($s === null ? '' : "\033[0m"); } return $s; } diff --git a/src/CommandLine/Parser.php b/src/CommandLine/Parser.php index c830ba2..64df047 100644 --- a/src/CommandLine/Parser.php +++ b/src/CommandLine/Parser.php @@ -52,8 +52,8 @@ public function __construct($help, array $defaults = []) self::ARGUMENT => (bool) end($m[2]), self::OPTIONAL => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::VALUE]), self::REPEATABLE => (bool) end($m[3]), - self::ENUM => count($enums = explode('|', trim(end($m[2]), '<[]>'))) > 1 ? $enums : NULL, - self::VALUE => isset($line[2]) ? $line[2] : NULL, + self::ENUM => count($enums = explode('|', trim(end($m[2]), '<[]>'))) > 1 ? $enums : null, + self::VALUE => isset($line[2]) ? $line[2] : null, ]; if ($name !== $m[1][0]) { $this->aliases[$m[1][0]] = $name; @@ -68,9 +68,9 @@ public function __construct($help, array $defaults = []) } - public function parse(array $args = NULL) + public function parse(array $args = null) { - if ($args === NULL) { + if ($args === null) { $args = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : []; } $params = []; @@ -93,7 +93,7 @@ public function parse(array $args = NULL) continue; } - list($name, $arg) = strpos($arg, '=') ? explode('=', $arg, 2) : [$arg, TRUE]; + list($name, $arg) = strpos($arg, '=') ? explode('=', $arg, 2) : [$arg, true]; if (isset($this->aliases[$name])) { $name = $this->aliases[$name]; @@ -104,10 +104,10 @@ public function parse(array $args = NULL) $opt = $this->options[$name]; - if ($arg !== TRUE && empty($opt[self::ARGUMENT])) { + if ($arg !== true && empty($opt[self::ARGUMENT])) { throw new \Exception("Option $name has not argument."); - } elseif ($arg === TRUE && !empty($opt[self::ARGUMENT])) { + } elseif ($arg === true && !empty($opt[self::ARGUMENT])) { if (isset($args[$i]) && $args[$i][0] !== '-') { $arg = $args[$i++]; } elseif (empty($opt[self::OPTIONAL])) { @@ -115,7 +115,7 @@ public function parse(array $args = NULL) } } - if (!empty($opt[self::ENUM]) && !in_array($arg, $opt[self::ENUM], TRUE) && !($opt[self::OPTIONAL] && $arg === TRUE)) { + if (!empty($opt[self::ENUM]) && !in_array($arg, $opt[self::ENUM], true) && !($opt[self::OPTIONAL] && $arg === true)) { throw new \Exception("Value of option $name must be " . implode(', or ', $opt[self::ENUM]) . '.'); } $this->checkArg($opt, $arg); @@ -135,7 +135,7 @@ public function parse(array $args = NULL) } elseif ($name[0] !== '-' && empty($opt[self::OPTIONAL])) { throw new \Exception("Missing required argument <$name>."); } else { - $params[$name] = NULL; + $params[$name] = null; } if (!empty($opt[self::REPEATABLE])) { $params[$name] = (array) $params[$name]; @@ -155,7 +155,7 @@ public function checkArg(array $opt, &$arg) { if (!empty($opt[self::REALPATH])) { $path = realpath($arg); - if ($path === FALSE) { + if ($path === false) { throw new \Exception("File path '$arg' not found."); } $arg = $path; diff --git a/tests/Console.color.phpt b/tests/Console.color.phpt index 00eace1..d692dea 100644 --- a/tests/Console.color.phpt +++ b/tests/Console.color.phpt @@ -8,12 +8,12 @@ require __DIR__ . '/bootstrap.php'; $console = new Console; $console->useColors(); -Assert::same("\x1b[m", $console->color(NULL)); +Assert::same("\x1b[m", $console->color(null)); Assert::same("\x1b[1;31m", $console->color('red')); Assert::same("\x1b[1;31;42m", $console->color('red/green')); Assert::same("\x1b[1;31;42m", $console->color('red/lime')); -Assert::same("\x1b[mhello\x1b[0m", $console->color(NULL, 'hello')); +Assert::same("\x1b[mhello\x1b[0m", $console->color(null, 'hello')); Assert::same("\x1b[1;31mhello\x1b[0m", $console->color('red', 'hello')); Assert::same("\x1b[1;31;42mhello\x1b[0m", $console->color('red/green', 'hello')); Assert::same("\x1b[1;31;42mhello\x1b[0m", $console->color('red/lime', 'hello')); diff --git a/tests/Parser.phpt b/tests/Parser.phpt index 87b3c22..fdb0c4b 100644 --- a/tests/Parser.phpt +++ b/tests/Parser.phpt @@ -14,15 +14,15 @@ test(function () { --a-b '); - Assert::same(['-p' => NULL, '--p' => NULL, '--a-b' => NULL], $cmd->parse([])); - Assert::same(['-p' => TRUE, '--p' => NULL, '--a-b' => NULL], $cmd->parse(['-p'])); + Assert::same(['-p' => null, '--p' => null, '--a-b' => null], $cmd->parse([])); + Assert::same(['-p' => true, '--p' => null, '--a-b' => null], $cmd->parse(['-p'])); $cmd = new Parser(' -p description '); - Assert::same(['-p' => NULL], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => null], $cmd->parse([])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); }); @@ -32,7 +32,7 @@ test(function () { // default value '); Assert::same(['-p' => '123'], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); $cmd = new Parser(' @@ -42,7 +42,7 @@ test(function () { // default value ]); Assert::same(['-p' => 123], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); }); @@ -51,10 +51,10 @@ test(function () { // alias -p | --param '); - Assert::same(['--param' => NULL], $cmd->parse([])); - Assert::same(['--param' => TRUE], $cmd->parse(['-p'])); - Assert::same(['--param' => TRUE], $cmd->parse(['--param'])); - Assert::same(['--param' => TRUE], $cmd->parse(explode(' ', '-p --param'))); + Assert::same(['--param' => null], $cmd->parse([])); + Assert::same(['--param' => true], $cmd->parse(['-p'])); + Assert::same(['--param' => true], $cmd->parse(['--param'])); + Assert::same(['--param' => true], $cmd->parse(explode(' ', '-p --param'))); Assert::exception(function () use ($cmd) { $cmd->parse(['-p=val']); }, 'Exception', 'Option --param has not argument.'); @@ -63,13 +63,13 @@ test(function () { // alias -p --param '); - Assert::same(['--param' => TRUE], $cmd->parse(['-p'])); + Assert::same(['--param' => true], $cmd->parse(['-p'])); $cmd = new Parser(' -p, --param '); - Assert::same(['--param' => TRUE], $cmd->parse(['-p'])); + Assert::same(['--param' => true], $cmd->parse(['-p'])); }); @@ -78,7 +78,7 @@ test(function () { // argument -p param '); - Assert::same(['-p' => NULL], $cmd->parse([])); + Assert::same(['-p' => null], $cmd->parse([])); Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p val'))); Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p=val'))); Assert::same(['-p' => 'val2'], $cmd->parse(explode(' ', '-p val1 -p val2'))); @@ -106,8 +106,8 @@ test(function () { // optional argument -p [param] '); - Assert::same(['-p' => NULL], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => null], $cmd->parse([])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p val'))); @@ -118,18 +118,18 @@ test(function () { // optional argument ]); Assert::same(['-p' => 123], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p val'))); $cmd = new Parser(' -p param ', [ - '-p' => [Parser::OPTIONAL => TRUE], + '-p' => [Parser::OPTIONAL => true], ]); - Assert::same(['-p' => NULL], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => null], $cmd->parse([])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p val'))); }); @@ -141,7 +141,7 @@ test(function () { // repeatable argument '); Assert::same(['-p' => []], $cmd->parse([])); - Assert::same(['-p' => [TRUE]], $cmd->parse(['-p'])); + Assert::same(['-p' => [true]], $cmd->parse(['-p'])); Assert::same(['-p' => ['val']], $cmd->parse(explode(' ', '-p val'))); Assert::same(['-p' => ['val1', 'val2']], $cmd->parse(explode(' ', '-p val1 -p val2'))); }); @@ -153,7 +153,7 @@ test(function () { // enumerates -p '); - Assert::same(['-p' => NULL], $cmd->parse([])); + Assert::same(['-p' => null], $cmd->parse([])); Assert::exception(function () use ($cmd) { $cmd->parse(['-p']); }, 'Exception', 'Option -p requires argument.'); @@ -167,8 +167,8 @@ test(function () { // enumerates -p [a|b|c] '); - Assert::same(['-p' => NULL], $cmd->parse([])); - Assert::same(['-p' => TRUE], $cmd->parse(['-p'])); + Assert::same(['-p' => null], $cmd->parse([])); + Assert::same(['-p' => true], $cmd->parse(['-p'])); Assert::same(['-p' => 'a'], $cmd->parse(explode(' ', '-p a'))); Assert::exception(function () use ($cmd) { $cmd->parse(explode(' ', '-p foo')); @@ -181,7 +181,7 @@ test(function () { // realpath $cmd = new Parser(' -p ', [ - '-p' => [Parser::REALPATH => TRUE], + '-p' => [Parser::REALPATH => true], ]); Assert::exception(function () use ($cmd) { @@ -208,21 +208,21 @@ test(function () { // positional arguments }, 'Exception', 'Unexpected parameter val2.'); $cmd = new Parser('', [ - 'pos' => [Parser::REPEATABLE => TRUE], + 'pos' => [Parser::REPEATABLE => true], ]); Assert::same(['pos' => ['val1', 'val2']], $cmd->parse(['val1', 'val2'])); $cmd = new Parser('', [ - 'pos' => [Parser::OPTIONAL => TRUE], + 'pos' => [Parser::OPTIONAL => true], ]); - Assert::same(['pos' => NULL], $cmd->parse([])); + Assert::same(['pos' => null], $cmd->parse([])); $cmd = new Parser('', [ - 'pos' => [Parser::VALUE => 'default', Parser::REPEATABLE => TRUE], + 'pos' => [Parser::VALUE => 'default', Parser::REPEATABLE => true], ]); Assert::same(['pos' => ['default']], $cmd->parse([]));