Skip to content

Commit ad06900

Browse files
committed
update something..
1 parent 942029e commit ad06900

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/IO/FixedInput.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public function __construct($argv = null)
5050
$copy = $argv;
5151

5252
// command name
53-
if (!empty($copy[1]) && $copy[1][0] !== '-' && false === strpos($copy[1], '=')) {
53+
if (!empty($copy[1]) && $copy[1][0] !== '-' && false === \strpos($copy[1], '=')) {
5454
$this->setCommand($copy[1]);
5555

5656
// unset command
5757
unset($copy[1]);
5858
}
5959

6060
// pop script name
61-
array_shift($copy);
61+
\array_shift($copy);
6262

6363
$this->cleanedTokens = $copy;
6464
$this->collectPreParsed($copy);
@@ -78,7 +78,7 @@ private function collectPreParsed(array $tokens)
7878
public function parseTokens(array $allowArray = [], array $noValues = [])
7979
{
8080
$params = $this->getTokens();
81-
array_shift($params); // pop script name
81+
\array_shift($params); // pop script name
8282
}
8383

8484
/**

src/IO/Input.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ public function __construct($argv = null, $parsing = true)
8383

8484
$this->pwd = $this->getPwd();
8585
$this->tokens = $argv;
86-
$this->script = array_shift($argv);
87-
$this->fullScript = implode(' ', $argv);
86+
$this->script = \array_shift($argv);
87+
$this->fullScript = \implode(' ', $argv);
8888

8989
if ($parsing) {
9090
list($this->args, $this->sOpts, $this->lOpts) = InputParser::fromArgv($argv);
9191

9292
// collect command. it is first argument.
93-
$this->command = isset($this->args[0]) ? array_shift($this->args) : null;
93+
$this->command = isset($this->args[0]) ? \array_shift($this->args) : null;
9494
}
9595
}
9696

@@ -99,8 +99,8 @@ public function __construct($argv = null, $parsing = true)
9999
*/
100100
public function __toString()
101101
{
102-
$tokens = array_map(function ($token) {
103-
if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
102+
$tokens = \array_map(function ($token) {
103+
if (\preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
104104
return $match[1] . InputParser::escapeToken($match[2]);
105105
}
106106

@@ -111,7 +111,7 @@ public function __toString()
111111
return $token;
112112
}, $this->tokens);
113113

114-
return implode(' ', $tokens);
114+
return \implode(' ', $tokens);
115115
}
116116

117117
/**

src/Utils/InputParser.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,57 +46,59 @@ final class InputParser
4646
*/
4747
public static function fromArgv(array $params, array $config = []): array
4848
{
49-
$config = array_merge([
49+
$config = \array_merge([
5050
// List of parameters without values(bool option keys)
5151
'noValues' => [], // ['debug', 'h']
5252
// Whether merge short-opts and long-opts
5353
'mergeOpts' => false,
54+
// want parsed opts
55+
'wantParsedOpts' => [],
5456
// list of params allow array.
5557
'arrayValues' => [], // ['names', 'status']
5658
], $config);
5759

5860
$args = $sOpts = $lOpts = [];
59-
$noValues = array_flip((array)$config['noValues']);
60-
$arrayValues = array_flip((array)$config['arrayValues']);
61+
$noValues = \array_flip((array)$config['noValues']);
62+
$arrayValues = \array_flip((array)$config['arrayValues']);
6163

6264
// each() will deprecated at 7.2. so,there use current and next instead it.
6365
// while (list(,$p) = each($params)) {
64-
while (false !== ($p = current($params))) {
65-
next($params);
66+
while (false !== ($p = \current($params))) {
67+
\next($params);
6668

6769
// is options
6870
if ($p{0} === '-') {
6971
$val = true;
70-
$opt = substr($p, 1);
72+
$opt = \substr($p, 1);
7173
$isLong = false;
7274

7375
// long-opt: (--<opt>)
7476
if ($opt{0} === '-') {
75-
$opt = substr($opt, 1);
77+
$opt = \substr($opt, 1);
7678
$isLong = true;
7779

7880
// long-opt: value specified inline (--<opt>=<value>)
79-
if (strpos($opt, '=') !== false) {
80-
list($opt, $val) = explode('=', $opt, 2);
81+
if (\strpos($opt, '=') !== false) {
82+
list($opt, $val) = \explode('=', $opt, 2);
8183
}
8284

8385
// short-opt: value specified inline (-<opt>=<value>)
8486
} elseif (isset($opt{1}) && $opt{1} === '=') {
85-
list($opt, $val) = explode('=', $opt, 2);
87+
list($opt, $val) = \explode('=', $opt, 2);
8688
}
8789

8890
// check if next parameter is a descriptor or a value
89-
$nxt = current($params);
91+
$nxt = \current($params);
9092

9193
// next elem is value. fix: allow empty string ''
9294
if ($val === true && !isset($noValues[$opt]) && self::nextIsValue($nxt)) {
9395
// list(,$val) = each($params);
9496
$val = $nxt;
95-
next($params);
97+
\next($params);
9698

9799
// short-opt: bool opts. like -e -abc
98100
} elseif (!$isLong && $val === true) {
99-
foreach (str_split($opt) as $char) {
101+
foreach (\str_split($opt) as $char) {
100102
$sOpts[$char] = true;
101103
}
102104

@@ -123,8 +125,8 @@ public static function fromArgv(array $params, array $config = []): array
123125
// arguments: param doesn't belong to any option, define it is args
124126
} else {
125127
// value specified inline (<arg>=<value>)
126-
if (strpos($p, '=') !== false) {
127-
list($name, $val) = explode('=', $p, 2);
128+
if (\strpos($p, '=') !== false) {
129+
list($name, $val) = \explode('=', $p, 2);
128130
$args[$name] = self::filterBool($val);
129131
} else {
130132
$args[] = $p;
@@ -133,7 +135,7 @@ public static function fromArgv(array $params, array $config = []): array
133135
}
134136

135137
if ($config['mergeOpts']) {
136-
return [$args, array_merge($sOpts, $lOpts)];
138+
return [$args, \array_merge($sOpts, $lOpts)];
137139
}
138140

139141
return [$args, $sOpts, $lOpts];

0 commit comments

Comments
 (0)