Skip to content

Commit 98b0717

Browse files
committed
reformatting codes
1 parent 2de72fe commit 98b0717

18 files changed

+332
-304
lines changed

examples/HomeController.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function indexCommand()
2929
*/
3030
public function colorCommand()
3131
{
32-
if ( !$this->output->supportColor() ) {
32+
if (!$this->output->supportColor()) {
3333
$this->write('Current terminal is not support output color text.');
3434

3535
return 0;
@@ -71,17 +71,16 @@ public function fmtMsgCommand()
7171
'Word wrap text with indentation to fit the screen size,' .
7272
'Word wrap text with indentation to fit the screen size,' .
7373
'Word wrap text with indentation to fit the screen size,' .
74-
'Word wrap text with indentation to fit the screen size,'
75-
;
74+
'Word wrap text with indentation to fit the screen size,';
7675

7776
$this->output->section('section title', $body, [
7877
'pos' => 'l'
7978
]);
8079

8180
$commands = [
8281
'version' => 'Show application version information',
83-
'help' => 'Show application help information',
84-
'list' => 'List all group and independent commands',
82+
'help' => 'Show application help information',
83+
'list' => 'List all group and independent commands',
8584
];
8685
Interact::panel($commands, 'Internal Commands', '');
8786
Interact::aList($commands, 'Internal Commands');
@@ -113,7 +112,7 @@ public function confirmCommand()
113112
{
114113
$a = Interact::confirm('continue');
115114

116-
$this->write('you answer is: ' . ($a ? 'yes' : 'no') );
115+
$this->write('you answer is: ' . ($a ? 'yes' : 'no'));
117116
}
118117

119118
/**
@@ -122,10 +121,10 @@ public function confirmCommand()
122121
*/
123122
public function selectCommand()
124123
{
125-
$opts = ['john','simon','rose'];
124+
$opts = ['john', 'simon', 'rose'];
126125
$a = Interact::select('you name is', $opts);
127126

128-
$this->write('you answer is: ' . $opts[$a] );
127+
$this->write('you answer is: ' . $opts[$a]);
129128
}
130129

131130
/**
@@ -135,8 +134,8 @@ public function envCommand()
135134
{
136135
$info = [
137136
'phpVersion' => PHP_VERSION,
138-
'env' => 'test',
139-
'debug' => true,
137+
'env' => 'test',
138+
'debug' => true,
140139
];
141140

142141
Interact::panel($info);

examples/cli-routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require 'TestCommand.php';
1212
require 'HomeController.php';
1313

14-
$app->command('demo',function(\inhere\console\io\Input $in, \inhere\console\io\Output $out){
14+
$app->command('demo', function (\inhere\console\io\Input $in, \inhere\console\io\Output $out) {
1515
$cmd = $in->getCommand();
1616

1717
$out->info('hello, this is a test command: ' . $cmd);

src/AbstractApp.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ abstract class AbstractApp
2222

2323
// event name list
2424
const ON_BEFORE_RUN = 'beforeRun';
25-
const ON_AFTER_RUN = 'afterRun';
26-
const ON_APP_STOP = 'appStop';
27-
const ON_NOT_FOUND = 'notFound';
25+
const ON_AFTER_RUN = 'afterRun';
26+
const ON_APP_STOP = 'appStop';
27+
const ON_NOT_FOUND = 'notFound';
2828

2929
/**
3030
* @var array
@@ -42,7 +42,7 @@ abstract class AbstractApp
4242
* @var array
4343
*/
4444
protected $config = [
45-
'env' => 'pdt', // dev test pdt
45+
'env' => 'pdt', // dev test pdt
4646
'debug' => false,
4747
'name' => 'My Console',
4848
'version' => '0.5.1',
@@ -55,8 +55,8 @@ abstract class AbstractApp
5555
*/
5656
protected $internalCommands = [
5757
'version' => 'Show application version information',
58-
'help' => 'Show application help information',
59-
'list' => 'List all group and independent commands',
58+
'help' => 'Show application help information',
59+
'list' => 'List all group and independent commands',
6060
];
6161

6262
/**
@@ -104,20 +104,20 @@ protected function prepareRun()
104104
* run app
105105
* @param bool $exit
106106
*/
107-
public function run($exit=true)
107+
public function run($exit = true)
108108
{
109109
$this->prepareRun();
110110

111111
// call 'onBeforeRun' service, if it is registered.
112-
if ( $cb = self::$hooks[self::ON_BEFORE_RUN] ) {
112+
if ($cb = self::$hooks[self::ON_BEFORE_RUN]) {
113113
$cb($this);
114114
}
115115

116116
// do run ...
117117
$returnCode = $this->doRun();
118118

119119
// call 'onAfterRun' service, if it is registered.
120-
if ( $cb = self::$hooks[self::ON_AFTER_RUN] ) {
120+
if ($cb = self::$hooks[self::ON_AFTER_RUN]) {
121121
$cb($this);
122122
}
123123

@@ -137,7 +137,7 @@ abstract public function doRun();
137137
public function stop($code = 0)
138138
{
139139
// call 'onAppStop' service, if it is registered.
140-
if ( $cb = self::$hooks[self::ON_APP_STOP] ) {
140+
if ($cb = self::$hooks[self::ON_APP_STOP]) {
141141
$cb($this);
142142
}
143143

@@ -162,7 +162,7 @@ public function controller(string $name, string $controller)
162162

163163
$this->checkName($name, true);
164164

165-
if ( !class_exists($controller) ) {
165+
if (!class_exists($controller)) {
166166
throw new \InvalidArgumentException("The console controller class [$controller] not exists!");
167167
}
168168

@@ -270,10 +270,10 @@ public function config($name, $default = null)
270270
}
271271

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

276-
if ( isset($this->config[$topKey]) && isset($this->config[$topKey][$subKey])) {
276+
if (isset($this->config[$topKey]) && isset($this->config[$topKey][$subKey])) {
277277
return $this->config[$topKey][$subKey];
278278
}
279279
}
@@ -322,7 +322,7 @@ protected function checkName(string $name, $isGroup = false)
322322
throw new \InvalidArgumentException('The command name is must match: ' . $pattern);
323323
}
324324

325-
if ( $this->isInternalCommand($name) ) {
325+
if ($this->isInternalCommand($name)) {
326326
throw new \InvalidArgumentException("The command name [$name] is not allowed. It is a built in command.");
327327
}
328328
}

src/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class AbstractCommand
4545
*/
4646
public function __construct(Input $input, Output $output)
4747
{
48-
$this->input = $input;
48+
$this->input = $input;
4949
$this->output = $output;
5050
}
5151

src/App.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function doRun()
2626
try {
2727
$status = $this->dispatch();
2828
} catch (\Exception $e) {
29-
$status = - $e->getCode();
29+
$status = -$e->getCode();
3030
$this->dispatchExHandler($e);
3131
}
3232

@@ -49,7 +49,7 @@ public function dispatch()
4949

5050
//// is a command name
5151

52-
if ( isset($this->commands[$name]) ) {
52+
if (isset($this->commands[$name])) {
5353
return $this->runCommand($name, true);
5454
}
5555

@@ -58,16 +58,16 @@ public function dispatch()
5858
$action = '';
5959

6060
// like 'home/index'
61-
if ( strpos($name, $sep) > 0 ) {
61+
if (strpos($name, $sep) > 0) {
6262
$input = array_filter(explode($sep, $name));
6363
[$name, $action] = count($input) > 2 ? array_splice($input, 2) : $input;
6464
}
6565

66-
if ( isset($this->controllers[$name]) ) {
66+
if (isset($this->controllers[$name])) {
6767
return $this->runAction($name, $action, true);
6868
}
6969

70-
if ( $cb = self::$hooks[self::ON_NOT_FOUND] ) {
70+
if ($cb = self::$hooks[self::ON_NOT_FOUND]) {
7171
$cb($command, $this);
7272
} else {
7373
// not match, output error message
@@ -80,31 +80,31 @@ public function dispatch()
8080

8181
/**
8282
* run a command
83-
* @param string $name Command name
84-
* @param bool $believable The `$name` is believable
83+
* @param string $name Command name
84+
* @param bool $believable The `$name` is believable
8585
* @return mixed
8686
*/
8787
public function runCommand($name, $believable = false)
8888
{
8989
// if $believable = true, will skip check.
90-
if ( !$believable && !isset($this->commands[$name]) ) {
90+
if (!$believable && !isset($this->commands[$name])) {
9191
throw new \InvalidArgumentException("The console independent-command [$name] not exists!");
9292
}
9393

9494
// Command class
9595
$handler = $this->commands[$name];
9696

97-
if ( is_object($handler) && ($handler instanceof \Closure) ) {
97+
if (is_object($handler) && ($handler instanceof \Closure)) {
9898
$status = $handler($this->input, $this->output);
9999
} else {
100-
if ( !class_exists($handler) ) {
100+
if (!class_exists($handler)) {
101101
throw new \InvalidArgumentException("The console command class [$handler] not exists!");
102102
}
103103

104104
/** @var Command $object */
105105
$object = new $handler($this->input, $this->output);
106106

107-
if ( !($object instanceof Command ) ) {
107+
if (!($object instanceof Command)) {
108108
throw new \InvalidArgumentException("The console command class [$handler] must instanceof the " . Command::class);
109109
}
110110

@@ -115,30 +115,30 @@ public function runCommand($name, $believable = false)
115115
}
116116

117117
/**
118-
* @param string $name Controller name
118+
* @param string $name Controller name
119119
* @param string $action
120-
* @param bool $believable The `$name` is believable
120+
* @param bool $believable The `$name` is believable
121121
* @return mixed
122122
*/
123123
public function runAction($name, $action, $believable = false)
124124
{
125125
// if $believable = true, will skip check.
126-
if ( !$believable && !isset($this->controllers[$name]) ) {
126+
if (!$believable && !isset($this->controllers[$name])) {
127127
throw new \InvalidArgumentException("The console controller-command [$name] not exists!");
128128
}
129129

130130
// Controller class
131131
$controller = $this->controllers[$name];
132132

133-
if ( !class_exists($controller) ) {
133+
if (!class_exists($controller)) {
134134
throw new \InvalidArgumentException("The console controller class [$controller] not exists!");
135135
}
136136

137137
/** @var Controller $object */
138138
$object = new $controller($this->input, $this->output);
139139
$object->setName($name);
140140

141-
if ( !($object instanceof Controller) ) {
141+
if (!($object instanceof Controller)) {
142142
throw new \InvalidArgumentException("The console controller class [$object] must instanceof the " . Controller::class);
143143
}
144144

@@ -150,12 +150,12 @@ public function runAction($name, $action, $believable = false)
150150
* @param \Exception $e
151151
* @throws \Exception
152152
*/
153-
public function dispatchExHandler(\Exception $e )
153+
public function dispatchExHandler(\Exception $e)
154154
{
155155
// $this->logger->ex($e);
156156

157157
// open debug, throw exception
158-
if ( $this->isDebug() ) {
158+
if ($this->isDebug()) {
159159
throw $e;
160160
}
161161

@@ -243,7 +243,7 @@ public function showCommandList($quit = true)
243243
$controllers = $this->controllers;
244244
ksort($controllers);
245245
foreach ($controllers as $name => $controller) {
246-
$controllerArr[$name] = $controller::DESCRIPTION ? : 'No description';
246+
$controllerArr[$name] = $controller::DESCRIPTION ?: 'No description';
247247
}
248248

249249
// all independent commands
@@ -252,11 +252,11 @@ public function showCommandList($quit = true)
252252
foreach ($commands as $name => $command) {
253253
$desc = 'No description';
254254

255-
if ( is_subclass_of($command, Command::class) ) {
256-
$desc = $command::DESCRIPTION ? : 'No description';
257-
} else if ( is_string($command) ) {
255+
if (is_subclass_of($command, Command::class)) {
256+
$desc = $command::DESCRIPTION ?: 'No description';
257+
} else if (is_string($command)) {
258258
$desc = 'A handler: ' . $command;
259-
} else if ( is_object($command) ) {
259+
} else if (is_object($command)) {
260260
$desc = $command instanceof \Closure ? 'A Closure' : 'A Object';
261261
}
262262

src/Command.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
abstract class Command extends AbstractCommand
1616
{
1717
// command usage message
18-
protected $usage = '';
18+
protected $usage = '';
1919

2020
// command arguments message
21-
protected $arguments = [];
21+
protected $arguments = [];
2222

2323
// command arguments message
24-
protected $options = [];
24+
protected $options = [];
2525

2626
// command example message
27-
protected $example = '';
27+
protected $example = '';
2828

2929
// run command
3030
public function run($name = '')
@@ -64,10 +64,12 @@ protected function handleRuntimeException(\Exception $e)
6464
}
6565

6666
protected function beforeRun()
67-
{}
67+
{
68+
}
6869

6970
protected function afterRun()
70-
{}
71+
{
72+
}
7173

7274
protected function configure()
7375
{
@@ -84,7 +86,7 @@ public function showHelp()
8486
{
8587
$configure = $this->configure();
8688

87-
if ( !$configure ) {
89+
if (!$configure) {
8890
return 91;
8991
}
9092

0 commit comments

Comments
 (0)