Skip to content

Commit d1feb5a

Browse files
committed
update, some modify. more return type declared
1 parent f2f0ded commit d1feb5a

16 files changed

+262
-205
lines changed

README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
**注意:**
1818

1919
- master 分支是要求 `php >= 7` 的(推荐使用)。
20-
- php5 分支是支持 php 5 的代码分支,但有些时间没更新了(但是基本的功能都支持)
20+
- php5 分支是支持 php5 `php >= 5.5` 的代码分支。
2121

2222
## 安装
2323

src/AbstractApp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function config($name, $default = null)
271271

272272
// allow get $config['top']['sub'] by 'top.sub'
273273
if (strpos($name, '.') > 1) {
274-
[$topKey, $subKey] = explode('.', $name, 2);
274+
list($topKey, $subKey) = explode('.', $name, 2);
275275

276276
if (isset($this->config[$topKey], $this->config[$topKey][$subKey])) {
277277
return $this->config[$topKey][$subKey];

src/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function dispatch()
6060
// like 'home/index'
6161
if (strpos($name, $sep) > 0) {
6262
$input = array_filter(explode($sep, $name));
63-
[$name, $action] = count($input) > 2 ? array_splice($input, 2) : $input;
63+
list($name, $action) = count($input) > 2 ? array_splice($input, 2) : $input;
6464
}
6565

6666
if (isset($this->controllers[$name])) {

src/Controller.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public function run($action = '')
6666
// run action
6767
try {
6868
$this->beforeRun($action);
69-
7069
$result = $params ? call_user_func_array([$this, $method], $params) : $this->$method();
71-
7270
$this->afterRun($action);
7371

7472
} catch (\Exception $e) {
@@ -192,7 +190,7 @@ final protected function showCommandList()
192190
/**
193191
* @return string
194192
*/
195-
public function getDefaultAction()
193+
public function getDefaultAction(): string
196194
{
197195
return $this->defaultAction;
198196
}
@@ -208,7 +206,7 @@ public function setDefaultAction($defaultAction)
208206
/**
209207
* @return string
210208
*/
211-
public function getActionSuffix()
209+
public function getActionSuffix(): string
212210
{
213211
return $this->actionSuffix;
214212
}
@@ -266,6 +264,7 @@ protected function parseDocCommentTags($comment)
266264
}
267265
}
268266
}
267+
269268
return $tags;
270269
}
271270

@@ -275,7 +274,7 @@ protected function parseDocCommentTags($comment)
275274
* @param $comment
276275
* @return string
277276
*/
278-
protected function parseDocCommentSummary($comment)
277+
protected function parseDocCommentSummary($comment): string
279278
{
280279
$docLines = preg_split('~\R~u', $comment);
281280

@@ -292,7 +291,7 @@ protected function parseDocCommentSummary($comment)
292291
* @param $comment
293292
* @return string
294293
*/
295-
protected function parseDocCommentDetail($comment)
294+
protected function parseDocCommentDetail($comment): string
296295
{
297296
$comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))), "\r", '');
298297

src/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public static function spliceKeyValue(array $data, array $opts = [])
241241
* Returns true if the console is running on windows
242242
* @return boolean
243243
*/
244-
public static function isOnWindows()
244+
public static function isOnWindows(): bool
245245
{
246246
return DIRECTORY_SEPARATOR === '\\';
247247
}
@@ -310,7 +310,7 @@ public static function getScreenSize($refresh = false)
310310
* @param integer $indent number of spaces to use for indentation.
311311
* @param integer $width
312312
* @return string the wrapped text.
313-
* @since 2.0.4
313+
* @from yii2
314314
*/
315315
public static function wrapText($text, $indent = 0, $width = 0)
316316
{

src/io/Input.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public function __construct()
6868
{
6969
$this->pwd = $this->getPwd();
7070

71-
[
71+
list(
7272
$this->fullScript,
7373
$this->script,
7474
$this->args,
7575
$this->sOpts,
7676
$this->lOpts
77-
] = self::parseOptArgs();
77+
) = self::parseOptArgs();
7878

7979
// collect command `server`
8080
$this->command = isset($this->args[0]) ? array_shift($this->args) : '';
@@ -86,7 +86,7 @@ public function __construct()
8686
* @param bool $nl true 会添加换行符 false 原样输出,不添加换行符
8787
* @return string
8888
*/
89-
public function read($question = null, $nl = false)
89+
public function read($question = null, $nl = false): string
9090
{
9191
fwrite(STDOUT, $question . ($nl ? "\n" : ''));
9292

@@ -101,7 +101,7 @@ public function read($question = null, $nl = false)
101101
* @param string|int $name
102102
* @return bool
103103
*/
104-
public function hasArg($name)
104+
public function hasArg($name): bool
105105
{
106106
return isset($this->args[$name]);
107107
}
@@ -199,7 +199,7 @@ public function getOpt(string $name, $default = null)
199199
* @param bool $default
200200
* @return bool
201201
*/
202-
public function boolOpt(string $name, $default = false)
202+
public function boolOpt(string $name, $default = false): bool
203203
{
204204
return (bool)$this->getOpt($name, $default);
205205
}
@@ -209,7 +209,7 @@ public function boolOpt(string $name, $default = false)
209209
* @param $name
210210
* @return bool
211211
*/
212-
public function hasOpt(string $name)
212+
public function hasOpt(string $name): bool
213213
{
214214
return isset($this->sOpts[$name]) || isset($this->lOpts[$name]);
215215
}
@@ -255,7 +255,7 @@ public function sOpt($name, $default = null)
255255
* @param $name
256256
* @return bool
257257
*/
258-
public function hasSOpt(string $name)
258+
public function hasSOpt(string $name): bool
259259
{
260260
return isset($this->sOpts[$name]);
261261
}
@@ -266,7 +266,7 @@ public function hasSOpt(string $name)
266266
* @param bool $default
267267
* @return bool
268268
*/
269-
public function sBoolOpt(string $name, $default = false)
269+
public function sBoolOpt(string $name, $default = false): bool
270270
{
271271
$val = $this->sOpt($name);
272272

@@ -291,7 +291,7 @@ public function lOpt($name, $default = null)
291291
* @param $name
292292
* @return bool
293293
*/
294-
public function hasLOpt(string $name)
294+
public function hasLOpt(string $name): bool
295295
{
296296
return isset($this->lOpts[$name]);
297297
}
@@ -302,7 +302,7 @@ public function hasLOpt(string $name)
302302
* @param bool $default
303303
* @return bool
304304
*/
305-
public function lBoolOpt(string $name, $default = false)
305+
public function lBoolOpt(string $name, $default = false): bool
306306
{
307307
$val = $this->lOpt($name);
308308

@@ -428,7 +428,7 @@ public function getInputStream()
428428
/**
429429
* @return string
430430
*/
431-
public function getPwd()
431+
public function getPwd(): string
432432
{
433433
if (!$this->pwd) {
434434
$this->pwd =getcwd();
@@ -467,7 +467,7 @@ public function getPwd()
467467
* @param bool $mergeOpts Whether merge short-opts and long-opts
468468
* @return array
469469
*/
470-
public static function parseOptArgs(array $noValues = [], $mergeOpts = false)
470+
public static function parseOptArgs(array $noValues = [], $mergeOpts = false): array
471471
{
472472
$params = $GLOBALS['argv'];
473473
reset($params);
@@ -490,12 +490,12 @@ public static function parseOptArgs(array $noValues = [], $mergeOpts = false)
490490

491491
// long-opt: value specified inline (--<opt>=<value>)
492492
if (strpos($opt, '=') !== false) {
493-
[$opt, $value] = explode('=', $opt, 2);
493+
list($opt, $value) = explode('=', $opt, 2);
494494
}
495495

496496
// short-opt: value specified inline (-<opt>=<value>)
497497
} elseif (strlen($opt) > 2 && $opt{1} === '=') {
498-
[$opt, $value] = explode('=', $opt, 2);
498+
list($opt, $value) = explode('=', $opt, 2);
499499
}
500500

501501
// check if next parameter is a descriptor or a value
@@ -523,7 +523,7 @@ public static function parseOptArgs(array $noValues = [], $mergeOpts = false)
523523
} else {
524524
// value specified inline (<arg>=<value>)
525525
if (strpos($p, '=') !== false) {
526-
[$name, $value] = explode('=', $p, 2);
526+
list($name, $value) = explode('=', $p, 2);
527527
$args[$name] = self::filterBool($value);
528528
} else {
529529
$args[] = $p;
@@ -543,7 +543,7 @@ public static function parseOptArgs(array $noValues = [], $mergeOpts = false)
543543
/**
544544
* @param string|bool $val
545545
* @param bool $enable
546-
* @return bool
546+
* @return bool|mixed
547547
*/
548548
private static function filterBool($val, $enable = true)
549549
{

src/io/InputInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface InputInterface
2626
* @param bool $nl true 会添加换行符 false 原样输出,不添加换行符
2727
* @return string
2828
*/
29-
public function read($question = null, $nl = false);
29+
public function read($question = null, $nl = false): string;
3030

3131
public function getScript(): string;
3232

0 commit comments

Comments
 (0)