Skip to content

Commit 71ce27d

Browse files
committed
some update code syntax format for php7
1 parent bc92caa commit 71ce27d

File tree

7 files changed

+25
-31
lines changed

7 files changed

+25
-31
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.5.0"
16+
"php": ">=7.0.0"
1717
},
1818
"autoload": {
1919
"psr-4": {

src/AbstractApp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ public function config($name, $default = null)
278278

279279
// allow get $config['top']['sub'] by 'top.sub'
280280
if ( strpos($name, '.') > 1 ) {
281-
list($topKey, $subKey) = explode('.', $name, 2);
281+
[$topKey, $subKey] = explode('.', $name, 2);
282282

283283
if ( isset($this->config[$topKey]) && isset($this->config[$topKey][$subKey])) {
284284
return $this->config[$topKey][$subKey];
285285
}
286286
}
287287

288-
return isset($this->config[$name]) ? $this->config[$name]: $default;
288+
return $this->config[$name] ?? $default;
289289
}
290290

291291
/**

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-
list($name, $action) = count($input) > 2 ? array_splice($input, 2) : $input;
63+
[$name, $action] = count($input) > 2 ? array_splice($input, 2) : $input;
6464
}
6565

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

src/Command.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
namespace inhere\console;
1010

11-
use inhere\console\io\Input;
12-
use inhere\console\io\Output;
13-
1411
/**
1512
* Class Command
1613
* @package inhere\console
@@ -38,11 +35,11 @@ public function run($name = '')
3835
return $this->showHelp();
3936
}
4037

38+
$status = 0;
39+
4140
try {
4241
$this->beforeRun();
43-
4442
$status = $this->execute();
45-
4643
$this->afterRun();
4744

4845
} catch (\Exception $e) {

src/Controller.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
namespace inhere\console;
1010

11-
use inhere\console\io\Input;
12-
use inhere\console\io\Output;
13-
1411
/**
1512
* Class Command
1613
* @package inhere\console
@@ -122,7 +119,7 @@ protected function afterRun($action)
122119
*/
123120
final public function helpCommand($action = '')
124121
{
125-
if (!$action && !($action = $this->input->get(0)) ) {
122+
if (!$action && !($action = $this->input->getFirstArg()) ) {
126123
$this->showCommandList();
127124
return 0;
128125
}

src/color/Color.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function format($text)
175175
return $text;
176176
}
177177

178-
foreach ($matches[0] as $i => $m) {
178+
foreach ((array)$matches[0] as $i => $m) {
179179
if (array_key_exists($matches[1][$i], $this->styles)) {
180180
$text = $this->replaceColor($text, $matches[1][$i], $matches[2][$i], $this->styles[$matches[1][$i]]);
181181

@@ -198,8 +198,8 @@ public function format($text)
198198
*/
199199
protected function replaceColor($text, $tag, $match, Style $style)
200200
{
201-
$style = $style->toString();
202-
$replace = $this->noColor ? $match : "\033[{$style}m{$match}\033[0m";
201+
$styleStr = $style->toString();
202+
$replace = $this->noColor ? $match : "\033[{$styleStr}m{$match}\033[0m";
203203

204204
return str_replace("<$tag>$match</$tag>", $replace, $text);
205205
}
@@ -220,7 +220,9 @@ public function addStyle($name, $fg = '', $bg = '', array $options = [])
220220
{
221221
if (is_array($fg)) {
222222
return $this->addStyleByArray($name, $fg);
223-
} elseif (is_object($fg) && $fg instanceof Style) {
223+
}
224+
225+
if (is_object($fg) && $fg instanceof Style) {
224226
$this->styles[$name] = $fg;
225227
} else {
226228
$this->styles[$name] = Style::make($fg, $bg, $options);
@@ -249,7 +251,7 @@ public function addStyleByArray($name, array $styleConfig)
249251
];
250252

251253
$config = array_merge($style, $styleConfig);
252-
list($fg, $bg, $options) = array_values($config);
254+
[$fg, $bg, $options] = array_values($config);
253255

254256
$this->styles[$name] = Style::make($fg, $bg, $options);
255257

src/io/Input.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Input
4848
public function __construct($parseArgv = true, $fillToGlobal = false)
4949
{
5050
if ($parseArgv) {
51-
list($this->args, $this->opts) = self::parseGlobalArgv($fillToGlobal);
51+
[$this->args, $this->opts] = self::parseGlobalArgv($fillToGlobal);
5252
}
5353
}
5454

@@ -83,39 +83,37 @@ public function hasArg($name)
8383
* @param mixed $default
8484
* @return mixed
8585
*/
86-
public function getArgument($name=null, $default = null)
86+
public function getArgument($name, $default = null)
8787
{
8888
return $this->get($name, $default);
8989
}
90-
public function getArg($name=null, $default = null)
90+
public function getArg($name, $default = null)
9191
{
9292
return $this->get($name, $default);
9393
}
94-
public function get($name=null, $default = null)
94+
public function get($name, $default = null)
9595
{
96-
if (null === $name) {
97-
return $this->args;
98-
}
99-
100-
return isset($this->args[$name]) ? $this->args[$name] : $default;
96+
return $this->args[$name] ?? $default;
10197
}
10298

10399
/**
104100
* get first argument
101+
* @param string $default
105102
* @return string
106103
*/
107-
public function getFirstArg()
104+
public function getFirstArg($default = '')
108105
{
109-
return $this->get(0);
106+
return $this->get(0, $default);
110107
}
111108

112109
/**
113110
* get second argument
111+
* @param string $default
114112
* @return string
115113
*/
116-
public function getSecondArg()
114+
public function getSecondArg($default = '')
117115
{
118-
return $this->get(1);
116+
return $this->get(1, $default);
119117
}
120118

121119
/**

0 commit comments

Comments
 (0)