Skip to content

Commit 8195fbd

Browse files
committed
style: run code inspect for src/IO src/Concern
1 parent cc52396 commit 8195fbd

19 files changed

+113
-107
lines changed

src/Concern/ApplicationHelpTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ trait ApplicationHelpTrait
5050
/**
5151
* @var string|array
5252
*/
53-
protected $moreHelpInfo = '';
53+
protected string|array $moreHelpInfo = '';
5454

5555
/***************************************************************************
5656
* Show information for the application

src/Concern/AttachApplicationTrait.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Inhere\Console\AbstractApplication;
1313
use Inhere\Console\Application;
1414
use Inhere\Console\Console;
15-
use Inhere\Console\GlobalOption;
1615
use Toolkit\Stdlib\OS;
1716

1817
/**
@@ -28,16 +27,16 @@ trait AttachApplicationTrait
2827
}
2928

3029
/**
31-
* @var Application
30+
* @var Application|null
3231
*/
33-
protected $app;
32+
protected ?Application $app = null;
3433

3534
/**
3635
* Mark the command/controller is attached in console application.
3736
*
3837
* @var bool
3938
*/
40-
private $attached = false;
39+
private bool $attached = false;
4140

4241
/**
4342
* @return AbstractApplication

src/Concern/CommandHelpTrait.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Toolkit\PFlag\FlagsParser;
1616
use function implode;
1717
use function sprintf;
18-
use function strpos;
1918
use function strtr;
2019
use function ucfirst;
2120

@@ -30,14 +29,14 @@ trait CommandHelpTrait
3029
* @var array [name => value]
3130
* @see AbstractHandler::annotationVars()
3231
*/
33-
private $commentsVars;
32+
private array $commentsVars = [];
3433

3534
/**
3635
* on display command help
3736
*
3837
* @var bool
3938
*/
40-
protected $renderGlobalOption = false;
39+
protected bool $renderGlobalOption = false;
4140

4241
/**
4342
* @return array
@@ -57,9 +56,9 @@ public function setCommentsVars(array $commentsVars): void
5756

5857
/**
5958
* @param string $name
60-
* @param string|array $value
59+
* @param array|string $value
6160
*/
62-
protected function addCommentsVar(string $name, $value): void
61+
protected function addCommentsVar(string $name, array|string $value): void
6362
{
6463
if (!isset($this->commentsVars[$name])) {
6564
$this->setCommentsVar($name, $value);
@@ -78,9 +77,9 @@ protected function addCommentsVars(array $map): void
7877

7978
/**
8079
* @param string $name
81-
* @param string|array $value
80+
* @param array|string $value
8281
*/
83-
protected function setCommentsVar(string $name, $value): void
82+
protected function setCommentsVar(string $name, array|string $value): void
8483
{
8584
$this->commentsVars[$name] = is_array($value) ? implode(',', $value) : (string)$value;
8685
}

src/Concern/ControllerHelpTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use function ksort;
2222
use function lcfirst;
2323
use function sprintf;
24-
use function strpos;
2524
use function ucfirst;
2625
use const PHP_EOL;
2726

src/Concern/FormatOutputAwareTrait.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ public function echoln(...$args): void
6666

6767
/**
6868
* @param string $format
69-
* @param mixed ...$args
69+
* @param mixed ...$args
70+
*
71+
* @return int
7072
*/
71-
public function writef(string $format, ...$args): void
73+
public function writef(string $format, ...$args): int
7274
{
73-
Console::printf($format, ...$args);
75+
return Console::printf($format, ...$args);
7476
}
7577

7678
/**
@@ -84,12 +86,12 @@ public function printf(string $format, ...$args): void
8486

8587
/**
8688
* @param string|mixed $text
87-
* @param bool|int $quit
88-
* @param array $opts
89+
* @param bool|int $quit
90+
* @param array $opts
8991
*
9092
* @return int
9193
*/
92-
public function writeln($text, $quit = false, array $opts = []): int
94+
public function writeln($text, bool $quit = false, array $opts = []): int
9395
{
9496
return Console::writeln($text, $quit, $opts);
9597
}
@@ -101,20 +103,20 @@ public function writeln($text, $quit = false, array $opts = []): int
101103
*
102104
* @return int
103105
*/
104-
public function println($text, bool $quit = false, array $opts = []): int
106+
public function println(mixed $text, bool $quit = false, array $opts = []): int
105107
{
106108
return Console::writeln($text, $quit, $opts);
107109
}
108110

109111
/**
110112
* @param string|mixed $text
111113
* @param bool $nl
112-
* @param bool|int $quit
114+
* @param bool|int $quit
113115
* @param array $opts
114116
*
115117
* @return int
116118
*/
117-
public function writeRaw($text, bool $nl = true, $quit = false, array $opts = []): int
119+
public function writeRaw(mixed $text, bool $nl = true, bool $quit = false, array $opts = []): int
118120
{
119121
return Console::writeRaw($text, $nl, $quit, $opts);
120122
}
@@ -127,10 +129,10 @@ public function writeRaw($text, bool $nl = true, $quit = false, array $opts = []
127129
* @return int|string
128130
*/
129131
public function json(
130-
$data,
132+
mixed $data,
131133
bool $echo = true,
132134
int $flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
133-
) {
135+
): int|string {
134136
$string = json_encode($data, $flags);
135137

136138
if ($echo) {
@@ -144,7 +146,7 @@ public function json(
144146
* @param mixed $data
145147
* @param string $title
146148
*/
147-
public function prettyJSON($data, string $title = 'JSON:'): void
149+
public function prettyJSON(mixed $data, string $title = 'JSON:'): void
148150
{
149151
if ($title) {
150152
Console::colored($title, 'ylw0');

src/Concern/InputOutputAwareTrait.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
trait InputOutputAwareTrait
2525
{
2626
/**
27-
* @var SFlags|FlagsParser
27+
* @var FlagsParser|null
2828
*/
29-
protected $flags;
29+
protected ?FlagsParser $flags;
3030

3131
/**
32-
* @var Input|InputInterface
32+
* @var InputInterface|null
3333
*/
34-
protected $input;
34+
protected ?InputInterface $input;
3535

3636
/**
37-
* @var Output|OutputInterface
37+
* @var OutputInterface|null
3838
*/
39-
protected $output;
39+
protected ?OutputInterface $output;
4040

4141
/**
4242
* @return string
@@ -74,26 +74,23 @@ public function readln(string $question = '', bool $nl = false): string
7474
}
7575

7676
/**
77-
* @param mixed $message
78-
* @param bool $nl
79-
* @param bool|int $quit
77+
* @param mixed $message
8078
*
8179
* @return int
8280
*/
83-
public function write($message, bool $nl = true, $quit = false): int
81+
public function write(mixed $message): int
8482
{
85-
return $this->output->write($message, $nl, $quit);
83+
return $this->output->write($message);
8684
}
8785

8886
/**
89-
* @param mixed $message
90-
* @param bool|int $quit
87+
* @param mixed $message
9188
*
9289
* @return int
9390
*/
94-
public function writeln($message, $quit = false): int
91+
public function writeln(mixed $message): int
9592
{
96-
return $this->output->write($message, true, $quit);
93+
return $this->output->writeln($message);
9794
}
9895

9996
/**

src/Concern/RuntimeProfileTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait RuntimeProfileTrait
2929
*
3030
* @var array
3131
*/
32-
private static $profiles = [];
32+
private static array $profiles = [];
3333

3434
/**
3535
* @var array
@@ -40,7 +40,7 @@ trait RuntimeProfileTrait
4040
* ...
4141
* ]
4242
*/
43-
private static $keyQueue = [];
43+
private static array $keyQueue = [];
4444

4545
/**
4646
* mark data analysis start
@@ -51,7 +51,7 @@ trait RuntimeProfileTrait
5151
*
5252
* @throws InvalidArgumentException
5353
*/
54-
public static function profile($name, array $context = [], $category = 'application'): void
54+
public static function profile($name, array $context = [], string $category = 'application'): void
5555
{
5656
$data = [
5757
'_profile_stats' => [
@@ -65,7 +65,7 @@ public static function profile($name, array $context = [], $category = 'applicat
6565

6666
$profileKey = $category . '|' . $name;
6767

68-
if (in_array($profileKey, self::$keyQueue, 1)) {
68+
if (in_array($profileKey, self::$keyQueue, true)) {
6969
throw new InvalidArgumentException("Your added profile name [$name] have been exists!");
7070
}
7171

@@ -81,7 +81,7 @@ public static function profile($name, array $context = [], $category = 'applicat
8181
*
8282
* @return bool|array
8383
*/
84-
public static function profileEnd(string $msg = null, array $context = [])
84+
public static function profileEnd(string $msg = null, array $context = []): bool|array
8585
{
8686
if (!$latestKey = array_pop(self::$keyQueue)) {
8787
return false;

src/Concern/SimpleEventAwareTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait SimpleEventAwareTrait
2525
*
2626
* @var array
2727
*/
28-
protected static $supportedEvents = [];
28+
protected static array $supportedEvents = [];
2929

3030
/**
3131
* registered Events
@@ -35,7 +35,7 @@ trait SimpleEventAwareTrait
3535
* 'event' => bool, // is once event
3636
* ]
3737
*/
38-
private static $events = [];
38+
private static array $events = [];
3939

4040
/**
4141
* events and handlers
@@ -45,7 +45,7 @@ trait SimpleEventAwareTrait
4545
* 'event' => callable, // event handler
4646
* ]
4747
*/
48-
private static $eventHandlers = [];
48+
private static array $eventHandlers = [];
4949

5050
/**
5151
* register a event handler

src/Concern/StyledOutputAwareTrait.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Toolkit\Cli\Style;
2525
use function method_exists;
2626
use function sprintf;
27-
use function strpos;
2827
use function substr;
2928

3029
/**
@@ -85,11 +84,11 @@ public function colored(string $text, string $tag = 'info'): int
8584
* @param array|mixed $messages
8685
* @param string $type
8786
* @param string $style
88-
* @param bool $quit
87+
* @param bool $quit
8988
*
9089
* @return int
9190
*/
92-
public function block($messages, string $type = 'MESSAGE', string $style = Style::NORMAL, $quit = false): int
91+
public function block(mixed $messages, string $type = 'MESSAGE', string $style = Style::NORMAL, bool $quit = false): int
9392
{
9493
return Show::block($messages, $type, $style, $quit);
9594
}
@@ -98,11 +97,11 @@ public function block($messages, string $type = 'MESSAGE', string $style = Style
9897
* @param array|mixed $messages
9998
* @param string $type
10099
* @param string $style
101-
* @param bool $quit
100+
* @param bool $quit
102101
*
103102
* @return int
104103
*/
105-
public function liteBlock($messages, string $type = 'MESSAGE', string $style = Style::NORMAL, $quit = false): int
104+
public function liteBlock(mixed $messages, string $type = 'MESSAGE', string $style = Style::NORMAL, bool $quit = false): int
106105
{
107106
return Show::liteBlock($messages, $type, $style, $quit);
108107
}
@@ -118,10 +117,10 @@ public function title(string $title, array $opts = []): void
118117

119118
/**
120119
* @param string $title
121-
* @param string|array $body The section body message
120+
* @param array|string $body The section body message
122121
* @param array $opts
123122
*/
124-
public function section(string $title, $body, array $opts = []): void
123+
public function section(string $title, array|string $body, array $opts = []): void
125124
{
126125
Section::show($title, $body, $opts);
127126
}
@@ -131,7 +130,7 @@ public function section(string $title, $body, array $opts = []): void
131130
* @param string $title
132131
* @param array $opts
133132
*/
134-
public function aList($data, string $title = 'Information', array $opts = []): void
133+
public function aList(mixed $data, string $title = 'Information', array $opts = []): void
135134
{
136135
SingleList::show($data, $title, $opts);
137136
}
@@ -201,7 +200,7 @@ public function progressTxt(int $total, string $msg, string $doneMsg = ''): Gene
201200
* @return Generator
202201
* @see Show::progressBar()
203202
*/
204-
public function progressBar($total, array $opts = []): Generator
203+
public function progressBar(int $total, array $opts = []): Generator
205204
{
206205
return Show::progressBar($total, $opts);
207206
}
@@ -222,7 +221,7 @@ public function __call(string $method, array $args = [])
222221
$quit = $args[1] ?? false;
223222
$style = $map[$method];
224223

225-
if (0 === strpos($method, 'lite')) {
224+
if (str_starts_with($method, 'lite')) {
226225
$type = substr($method, 4);
227226
return Show::liteBlock($msg, $type === 'Primary' ? 'IMPORTANT' : $type, $style, $quit);
228227
}

0 commit comments

Comments
 (0)