Skip to content

Commit cc52396

Browse files
committed
style: run code inspect for src/Component
1 parent 001ca21 commit cc52396

27 files changed

+154
-168
lines changed

src/Component/CompletionDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class CompletionDumper extends Obj\AbstractObj
2222
{
2323
/**
24-
* @var Application
24+
* @var Application|null
2525
*/
26-
public $app;
26+
public ?Application $app;
2727
}

src/Component/ConsoleAppIShell.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
class ConsoleAppIShell extends IShell
2121
{
2222
/**
23-
* @var Application
23+
* @var Application|null
2424
*/
25-
public $app;
25+
public ?Application $app;
2626

2727
// TODO start an shell for run app.
2828
}

src/Component/ConsoleRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
class ConsoleRenderer
2020
{
2121
/**
22-
* @var FormatterInterface
22+
* @var FormatterInterface|null
2323
*/
24-
private $formatter;
24+
private ?FormatterInterface $formatter;
2525

2626
/**
2727
* @return string

src/Component/ErrorHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ class ErrorHandler implements ErrorHandlerInterface
3030
/**
3131
* @var bool
3232
*/
33-
protected $debug = false;
33+
protected bool $debug = false;
3434

3535
/**
3636
* @var string
3737
*/
38-
protected $rootPath = '';
38+
protected string $rootPath = '';
3939

4040
/**
4141
* @var bool
4242
*/
43-
protected $hideRootPath = false;
43+
protected bool $hideRootPath = false;
4444

4545
/**
4646
* @param array $config

src/Component/Formatter/Body.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
class Body
1818
{
19-
public $nodes = [];
19+
public array $nodes = [];
2020

21-
public $style = '';
21+
public string $style = '';
2222

23-
public $keyStyle = 'info';
23+
public string $keyStyle = 'info';
2424

25-
public $valStyle = '';
25+
public string $valStyle = '';
2626
}

src/Component/Formatter/JSONPretty.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function str_contains;
2424
use function str_ends_with;
2525
use function trim;
26-
use function vdump;
2726

2827
/**
2928
* class JSONPretty

src/Component/Formatter/Panel.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,48 @@
3535
class Panel extends MessageFormatter
3636
{
3737
/** @var string */
38-
public $title = '';
38+
public string $title = '';
3939

4040
/** @var string */
41-
public $titleBorder = '-';
41+
public string $titleBorder = '-';
4242

4343
/** @var string */
44-
public $titleStyle = 'bold';
44+
public string $titleStyle = 'bold';
4545

4646
/** @var string */
47-
public $titleAlign = self::ALIGN_LEFT;
47+
public string $titleAlign = self::ALIGN_LEFT;
4848

4949
/** @var string|array */
50-
public $data;
50+
public string|array $data;
5151

5252
/** @var string */
53-
public $bodyAlign = self::ALIGN_LEFT;
53+
public string $bodyAlign = self::ALIGN_LEFT;
5454

5555
/** @var string */
56-
public $footerBorder = '-';
56+
public string $footerBorder = '-';
5757

5858
/** @var string */
59-
public $footer = '';
59+
public string $footer = '';
6060

6161
/** @var bool */
62-
public $ucFirst = true;
62+
public bool $ucFirst = true;
6363

6464
/** @var int */
65-
public $width = 0;
65+
public int $width = 0;
6666

6767
/** @var bool */
68-
public $showBorder = true;
68+
public bool $showBorder = true;
6969

7070
/** @var string */
71-
public $borderYChar = '-';
71+
public string $borderYChar = '-';
7272

7373
/** @var string */
74-
public $borderXChar = '|';
74+
public string $borderXChar = '|';
7575

7676
/**
7777
* @var string Template for the panel. don't contains border
7878
*/
79-
public $template = <<<EOF
79+
public string $template = <<<EOF
8080
{%title%}
8181
{%title-border%}
8282
{%content%}
@@ -93,7 +93,7 @@ class Panel extends MessageFormatter
9393
*
9494
* @return int
9595
*/
96-
public static function show($data, string $title = 'Information Panel', array $opts = []): int
96+
public static function show(mixed $data, string $title = 'Information Panel', array $opts = []): int
9797
{
9898
if (!$data) {
9999
Console::write('<info>No data to display!</info>');
@@ -164,7 +164,7 @@ public static function show($data, string $title = 'Information Panel', array $o
164164
$titleLength = mb_strlen($title, 'UTF-8');
165165
$panelWidth = $panelWidth > $titleLength ? $panelWidth : $titleLength;
166166
$indentSpace = Str::pad(' ', ceil($panelWidth / 2) - ceil($titleLength / 2) + 2 * 2, ' ');
167-
Console::write(" {$indentSpace}<bold>{$title}</bold>");
167+
Console::write(" $indentSpace<bold>$title</bold>");
168168
}
169169

170170
// output panel top border
@@ -226,7 +226,6 @@ public function format(): string
226226
if (is_array($value)) {
227227
$temp = '';
228228

229-
/** @var array $value */
230229
foreach ($value as $key => $val) {
231230
if (is_bool($val)) {
232231
$val = $val ? 'True' : 'False';
@@ -262,7 +261,7 @@ public function format(): string
262261
$titleLength = mb_strlen($title, 'UTF-8');
263262
$panelWidth = $panelWidth > $titleLength ? $panelWidth : $titleLength;
264263
$indentSpace = Str::pad(' ', ceil($panelWidth / 2) - ceil($titleLength / 2) + 2 * 2, ' ');
265-
$buffer->write(" {$indentSpace}<bold>{$title}</bold>\n");
264+
$buffer->write(" $indentSpace<bold>$title</bold>\n");
266265
}
267266

268267
// output panel top border
@@ -297,7 +296,7 @@ public function format(): string
297296
*
298297
* @return $this
299298
*/
300-
public function showBorder($border): self
299+
public function showBorder(bool $border): self
301300
{
302301
$this->showBorder = (bool)$border;
303302
return $this;

src/Component/Formatter/Section.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class Section extends MessageFormatter
2929
{
3030
/**
3131
* @param string $title The title text
32-
* @param string|array $body The section body message
32+
* @param array|string $body The section body message
3333
* @param array $opts
3434
*/
35-
public static function show(string $title, $body, array $opts = []): void
35+
public static function show(string $title, array|string $body, array $opts = []): void
3636
{
3737
$opts = array_merge([
3838
'width' => 80,

src/Component/Formatter/SingleList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SingleList extends MessageFormatter
4242
*
4343
* @return int|string
4444
*/
45-
public static function show($data, string $title = 'Information', array $opts = [])
45+
public static function show(mixed $data, string $title = 'Information', array $opts = []): int|string
4646
{
4747
$string = '';
4848
$opts = array_merge([

src/Component/Formatter/Table.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@
3030
class Table extends MessageFormatter
3131
{
3232
/** @var array */
33-
public $data = [];
33+
public array $data = [];
3434

3535
/** @var array */
36-
public $columns = [];
36+
public array $columns = [];
3737

3838
/** @var string|array */
39-
public $body;
39+
public string|array $body;
4040

4141
/** @var string */
42-
public $title = '';
42+
public string $title = '';
4343

4444
/** @var string */
45-
public $titleBorder = '-';
45+
public string $titleBorder = '-';
4646

4747
/** @var string */
48-
public $titleStyle = '-';
48+
public string $titleStyle = '-';
4949

5050
/** @var string */
51-
public $titleAlign = self::ALIGN_LEFT;
51+
public string $titleAlign = self::ALIGN_LEFT;
5252

5353
/**
5454
* Tabular data display
@@ -169,7 +169,7 @@ public static function show(array $data, string $title = 'Data Table', array $op
169169
$title = Str::ucwords(trim($title));
170170
$titleLength = Str::utf8Len($title, 'UTF-8');
171171
$indentSpace = Str::pad(' ', ceil($tableWidth / 2) - ceil($titleLength / 2) + ($columnCount * 2), ' ');
172-
$buf->write(" {$indentSpace}<$tStyle>{$title}</$tStyle>\n");
172+
$buf->write(" $indentSpace<$tStyle>$title</$tStyle>\n");
173173
}
174174

175175
$border = $leftIndent . Str::pad($rowBorderChar, $tableWidth + ($columnCount * 3) + 2, $rowBorderChar);
@@ -183,7 +183,7 @@ public static function show(array $data, string $title = 'Data Table', array $op
183183

184184
// output table head
185185
if ($hasHead) {
186-
$headStr = "{$leftIndent}{$colBorderChar} ";
186+
$headStr = "$leftIndent$colBorderChar ";
187187

188188
foreach ($head as $index => $name) {
189189
$colMaxWidth = $info['columnMaxWidth'][$index];
@@ -193,7 +193,7 @@ public static function show(array $data, string $title = 'Data Table', array $op
193193
$name = Str::padByWidth($name, $colMaxWidth, ' ');
194194
$name = ColorTag::wrap($name, $opts['headStyle']);
195195
// join string
196-
$headStr .= " {$name} {$colBorderChar}";
196+
$headStr .= " $name $colBorderChar";
197197
}
198198

199199
$buf->write($headStr . "\n");
@@ -227,7 +227,7 @@ public static function show(array $data, string $title = 'Data Table', array $op
227227
// use Str::padByWidth support zh-CN words
228228
$value = Str::padByWidth($value, $colMaxWidth, ' ');
229229
$value = ColorTag::wrap($value, $opts['bodyStyle']);
230-
$rowStr .= " {$value} {$colBorderChar}";
230+
$rowStr .= " $value $colBorderChar";
231231
$colIndex++;
232232
}
233233

src/Component/Formatter/Tree.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
use Inhere\Console\Component\MessageFormatter;
1313
use Inhere\Console\Console;
14-
use Inhere\Console\Util\FormatUtil;
1514
use Toolkit\Cli\Cli;
15+
use Toolkit\Stdlib\Std;
1616
use function array_merge;
1717
use function is_array;
1818
use function is_scalar;
@@ -26,10 +26,10 @@
2626
class Tree extends MessageFormatter
2727
{
2828
/** @var int */
29-
private $counter = 0;
29+
private int $counter = 0;
3030

3131
/** @var bool */
32-
private $started = false;
32+
private bool $started = false;
3333

3434
/**
3535
* Render data like tree
@@ -64,7 +64,7 @@ public static function show(array $data, array $opts = []): void
6464
$counter++;
6565
$leftString = $opts['leftPadding'] . str_pad($opts['prefix'], $opts['_level'] + 1, $opts['char']);
6666

67-
Console::write($leftString . ' ' . FormatUtil::typeToString($value));
67+
Console::write($leftString . ' ' . Std::toString($value));
6868
} elseif (is_array($value)) {
6969
$newOpts = $opts;
7070
$newOpts['_is_main'] = false;

src/Component/Interact/AbstractQuestion.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Inhere\Console\Component\Interact;
1111

1212
use Inhere\Console\Component\InteractiveHandle;
13-
use Toolkit\Stdlib\Str\StrObject;
13+
use Toolkit\Stdlib\Str\StrValue;
1414

1515
/**
1616
* Class AbstractQuestion
@@ -20,22 +20,22 @@
2020
abstract class AbstractQuestion extends InteractiveHandle
2121
{
2222
/**
23-
* @var StrObject
23+
* @var StrValue|null
2424
*/
25-
protected $answer;
25+
protected ?StrValue $answer = null;
2626

2727
/**
2828
* @param string $str
2929
*/
3030
protected function createAnswer(string $str): void
3131
{
32-
$this->answer = StrObject::new($str)->trim();
32+
$this->answer = StrValue::new($str)->trim();
3333
}
3434

3535
/**
36-
* @return StrObject
36+
* @return StrValue
3737
*/
38-
public function getAnswer(): StrObject
38+
public function getAnswer(): StrValue
3939
{
4040
return $this->answer;
4141
}

src/Component/Interact/AbstractSelect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ abstract class AbstractSelect extends InteractiveHandle
1919
/**
2020
* @var array
2121
*/
22-
protected $data = [];
22+
protected array $data = [];
2323

2424
/**
2525
* @var bool
2626
*/
27-
protected $allowExit = true;
27+
protected bool $allowExit = true;
2828

2929
/**
3030
* @return bool

src/Component/Interact/Checkbox.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class Checkbox extends MultiSelect
2929
* List multiple options and allow multiple selections
3030
*
3131
* @param string $description
32-
* @param string|array $options
33-
* @param null|mixed $default
32+
* @param array|string $options
33+
* @param mixed|null $default
3434
* @param bool $allowExit
3535
*
3636
* @return array
3737
*/
38-
public static function select(string $description, $options, $default = null, bool $allowExit = true): array
38+
public static function select(string $description, array|string $options, mixed $default = null, bool $allowExit = true): array
3939
{
4040
if (!$description = trim($description)) {
4141
Show::error('Please provide a description text!', 1);
@@ -59,13 +59,13 @@ public static function select(string $description, $options, $default = null, bo
5959
}
6060

6161
Console::write($text);
62-
$defText = $default !== null ? "[default:<comment>{$default}</comment>]" : '';
63-
$filter = function ($val) use ($options) {
62+
$defText = $default !== null ? "[default:<comment>$default</comment>]" : '';
63+
$filter = static function ($val) use ($options) {
6464
return $val !== 'q' && isset($options[$val]);
6565
};
6666

6767
beginChoice:
68-
$r = Console::readln("Your choice{$defText} : ");
68+
$r = Console::readln("Your choice$defText : ");
6969
$r = $r !== '' ? str_replace(' ', '', trim($r, $sep)) : '';
7070

7171
// empty

0 commit comments

Comments
 (0)