Skip to content

Commit 22b9efb

Browse files
authored
chore: bump dependency and formatting (#23)
* chore: bump dependency - use component package instead use full package (sonypradana/collection, sonypradana/console) - formatting * formatting: fix phpstan level max * run composer bump
1 parent 718978c commit 22b9efb

12 files changed

+85
-61
lines changed

composer.json

+7-13
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,15 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^7.4 || ^8.0",
26-
"sonypradana/php-library": "^0.19",
27-
"react/socket": "^1.12"
25+
"php": "^8.0",
26+
"sonypradana/collection": "^0.35",
27+
"sonypradana/console": "^0.35",
28+
"react/socket": "^1.15"
2829
},
2930
"require-dev": {
30-
"phpunit/phpunit": "^9.6.8",
31-
"friendsofphp/php-cs-fixer": "^3.17.0",
32-
"phpstan/phpstan": "^1.10.15"
33-
},
34-
"extra": {
35-
"laravel": {
36-
"dont-discover": [
37-
"*"
38-
]
39-
}
31+
"phpunit/phpunit": "^9.6",
32+
"friendsofphp/php-cs-fixer": "^3.59",
33+
"phpstan/phpstan": "^1.11"
4034
},
4135
"minimum-stability": "dev",
4236
"prefer-stable": true,

src/Commands/ServeCommand.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function serve()
5959
if (!$this->promt()) {
6060
exit;
6161
}
62-
$style->new_lines()->flush();
62+
$style->newLines()->flush();
6363
}
6464

6565
/** @var string */
6666
$uri = $this->OPTION[0] ?? Config::get('socket.uri', '127.0.0.1:8080');
6767

6868
// header information
69-
$style->push('socket server')->textGreen()->new_lines();
69+
$style->push('socket server')->textGreen()->newLines();
7070
$style->tap(info($uri));
7171
$style->push('listening...')->textDim()->out();
7272

@@ -75,7 +75,7 @@ public function serve()
7575

7676
$socket->on('connection', function (\React\Socket\ConnectionInterface $connection) {
7777
$connection->on('data', function ($chunk) {
78-
style(now()->__toString())->textDim()->underline()
78+
style((new \DateTime())->format('Y-m-d H:i:s'))->textDim()->underline()
7979
->push($chunk)
8080
->out();
8181
});
@@ -88,7 +88,7 @@ public function serve()
8888
public function help()
8989
{
9090
$this->command_describes = [
91-
'serve' => 'Start socket server, default - ' . Config::get('socket.uri', '127.0.0.1:8080'),
91+
'serve' => 'Start socket server, default - ' . Config::castString('socket.uri', '127.0.0.1:8080'),
9292
'config' => 'Set config to config file',
9393
'help' => 'Show help command information',
9494
];
@@ -117,12 +117,12 @@ public function help()
117117
$print
118118
->textGreen()
119119
->push(' command line application')->textBlue()
120-
->new_lines(2);
120+
->newLines(2);
121121

122-
$print->push('command:')->new_lines();
123-
$print = $this->printCommands($print)->new_lines();
122+
$print->push('command:')->newLines();
123+
$print = $this->printCommands($print)->newLines();
124124

125-
$print->push('option:')->new_lines();
125+
$print->push('option:')->newLines();
126126
$print = $this->printOptions($print);
127127

128128
return $print;

src/Config.php

+24-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
final class Config
88
{
9-
/** @var array<string, string|bool|int|null> */
9+
/** @var array<string, string[]|string|bool|int|null> */
1010
private static $configs = [];
1111

1212
/**
@@ -36,7 +36,7 @@ public static function load($config_file = null)
3636
/**
3737
* Save current config to config file.
3838
*
39-
* @param array<string, string|bool|int|null> $configs
39+
* @param array<string, string[]|string|bool|int|null> $configs
4040
*
4141
* @return void
4242
*/
@@ -57,10 +57,10 @@ private static function save($configs)
5757
/**
5858
* Get config by key.
5959
*
60-
* @param string $key
61-
* @param string|int|bool|null $default
60+
* @param string $key
61+
* @param string[]|string|int|bool|null $default
6262
*
63-
* @return string|int|bool|null
63+
* @return string[]|string|int|bool|null
6464
*/
6565
public static function get($key, $default = null)
6666
{
@@ -74,8 +74,8 @@ public static function get($key, $default = null)
7474
/**
7575
* Set/create array item of config.
7676
*
77-
* @param string $key
78-
* @param string|bool|int|null $val
77+
* @param string $key
78+
* @param string[]|string|bool|int|null $val
7979
*
8080
* @return void
8181
*/
@@ -99,10 +99,26 @@ public static function flush()
9999
/**
100100
* Get cached config.
101101
*
102-
* @return array<string, string|bool|int|null>
102+
* @return array<string, string[]|string|bool|int|null>
103103
*/
104104
public static function all()
105105
{
106106
return self::$configs;
107107
}
108+
109+
/**
110+
* Cast get return type as string.
111+
*
112+
* @param string $key
113+
* @param string|null $default
114+
*
115+
* @return string
116+
*/
117+
public static function castString($key, $default = null)
118+
{
119+
/** @var string */
120+
$string = self::get($key, $default);
121+
122+
return $string;
123+
}
108124
}

src/JsonPrinter.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function dump(...$var)
2727
$snapshot = Here::getCapture($file, $capture);
2828

2929
$this->sendJson([
30-
'file' => $this->content['file'],
31-
'line' => $this->content['line'],
32-
'snapshot' => array_map(fn ($trim) => trim($trim), $snapshot),
30+
'file' => $this->content['file'],
31+
'line' => $this->content['line'],
32+
'snapshot' => array_map(fn ($trim) => trim($trim), $snapshot),
3333
]);
3434
}
3535

@@ -51,20 +51,22 @@ public function count($group)
5151
$group_file = [];
5252
foreach (Here::getHere() as $files) {
5353
if ($files['group'] === $group) {
54-
$group_file[$files['file']][] = $files;
54+
/** @var string */
55+
$file = $files['file'];
56+
$group_file[$file][] = $files;
5557
}
5658
}
5759
// group by line
5860
$groups = [];
59-
foreach ($group_file as $file) {
60-
foreach ($file as $result) {
61+
foreach ($group_file as $files) {
62+
foreach ($files as $result) {
6163
if (in_array($result['line'], $groups)) {
6264
continue;
6365
}
6466
$groups[] = $result['line'];
6567

6668
// counter
67-
$count = array_filter($file, fn ($item) => $item['line'] === $result['line']);
69+
$count = array_filter($files, fn ($item) => $item['line'] === $result['line']);
6870

6971
// build snapshot
7072
/** @var array<int, int> */
@@ -121,14 +123,14 @@ protected function send($out)
121123
return;
122124
}
123125

124-
$uri = (string) Config::get('socket.uri', '127.0.0.1:8080');
126+
$uri = Config::castString('socket.uri', '127.0.0.1:8080');
125127
$out = $out === false ? '' : $out;
126128

127129
$connector = new \React\Socket\Connector();
128130

129131
$connector->connect($uri)->then(function (\React\Socket\ConnectionInterface $connection) use ($out) {
130132
$connection->end($out);
131-
}, function (\Exception $e) {
133+
}, function (\Throwable $e) {
132134
echo 'Error: ' . $e->getMessage() . PHP_EOL;
133135
});
134136
}

src/Printer.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Here\Styles\ArrayStyle;
99
use Here\Styles\VarStyle;
1010
use System\Console\Style\Style;
11-
use System\Text\Str;
1211

1312
final class Printer extends AbstractsPrinter
1413
{
@@ -41,7 +40,7 @@ protected function send($out)
4140
}
4241

4342
$use_socket = Config::get('socket.enable', false);
44-
$uri = (string) Config::get('socket.uri', '127.0.0.1:8080');
43+
$uri = Config::castString('socket.uri', '127.0.0.1:8080');
4544
$out = $out === false ? '' : $out;
4645

4746
if ($use_socket === false) {
@@ -54,7 +53,7 @@ protected function send($out)
5453

5554
$connector->connect($uri)->then(function (\React\Socket\ConnectionInterface $connection) use ($out) {
5655
$connection->end($out);
57-
}, function (\Exception $e) {
56+
}, function (\Throwable $e) {
5857
echo 'Error: ' . $e->getMessage() . PHP_EOL;
5958
});
6059
}
@@ -101,19 +100,21 @@ public function count($group)
101100
$group_file = [];
102101
foreach (Here::getHere() as $files) {
103102
if ($files['group'] === $group) {
104-
$group_file[$files['file']][] = $files;
103+
/** @var string */
104+
$file = $files['file'];
105+
$group_file[$file][] = $files;
105106
}
106107
}
107108
// group by line
108109
$groups = [];
109-
foreach ($group_file as $file) {
110-
foreach ($file as $result) {
110+
foreach ($group_file as $files) {
111+
foreach ($files as $result) {
111112
if (in_array($result['line'], $groups)) {
112113
continue;
113114
}
114115
$groups[] = $result['line'];
115116

116-
$count = array_filter($file, fn ($item) => $item['line'] === $result['line']);
117+
$count = array_filter($files, fn ($item) => $item['line'] === $result['line']);
117118

118119
$this->printInfo($print, $result, count($count));
119120
$this->printSnapshot($print, $result);
@@ -144,7 +145,7 @@ public function countAll()
144145
/** {@inheritdoc} */
145146
protected function printInfo(&$print, $content, $with_counter = false)
146147
{
147-
$print->new_lines();
148+
$print->newLines();
148149

149150
$print->push(' work ')->textDarkGray()->bgGreen();
150151
if ($with_counter !== false) {
@@ -161,7 +162,7 @@ protected function printInfo(&$print, $content, $with_counter = false)
161162
/** {@inheritdoc} */
162163
protected function printSnapshot(&$print, $content, ...$var)
163164
{
164-
$print->new_lines();
165+
$print->newLines();
165166

166167
$count = count($var);
167168
$has_var = $count > 0;
@@ -183,7 +184,7 @@ protected function printSnapshot(&$print, $content, ...$var)
183184
$arrow = $current ? '-> ' : ' ';
184185

185186
$print->push($arrow)->textGreen();
186-
$print->push(Str::fill((string) $line, ' ', $lenght) . ' | ' . $code)->textDim();
187+
$print->push(str_pad((string) $line, $lenght, ' ', STR_PAD_LEFT) . ' | ' . $code)->textDim();
187188
if ($current
188189
&& $has_var === true
189190
&& $this->EOL_var === false
@@ -209,13 +210,13 @@ protected function printSnapshot(&$print, $content, ...$var)
209210
*/
210211
private function printVar(&$style, $var, $margin_left)
211212
{
212-
$style->push(Str::fill('', ' ', $margin_left) . 'var : ')->textLightYellow();
213+
$style->push(str_pad('', $margin_left, ' ', STR_PAD_LEFT) . 'var : ')->textLightYellow();
213214

214215
$tab_size = (int) round($margin_left / 2);
215216
$style = is_array($var)
216217
? (new ArrayStyle($style))->ref($var)->tabSize($tab_size)->render()
217218
: (new VarStyle($style))->ref($var)->tabSize($tab_size)->render();
218219

219-
return $style->new_lines();
220+
return $style->newLines();
220221
}
221222
}

src/Styles/ArrayStyle.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function render(): Style
3333
foreach ($var as $key => $value) {
3434
$this->current_line++;
3535
if ($this->current_line > $this->max_line) {
36-
$this->style->new_lines()->repeat(' ', $this->tab_size * 2)->push('...')->textDim();
36+
$this->style->newLines()->repeat(' ', $this->tab_size * 2)->push('...')->textDim();
3737
break;
3838
}
3939

40-
$this->style->new_lines();
40+
$this->style->newLines();
4141
$this->style->repeat(' ', $this->tab_size * 2);
4242
$this->style->push($key)->textLightGreen();
4343
$this->style->push(' => ')->textYellow();
@@ -53,7 +53,7 @@ public function render(): Style
5353
$this->style = $style->render();
5454
}
5555

56-
$this->style->new_lines()->repeat(' ', ($this->tab_size * 2) - 2);
56+
$this->style->newLines()->repeat(' ', ($this->tab_size * 2) - 2);
5757
$this->style->push(']')->textYellow();
5858

5959
return $this->style;

src/Styles/ClassStyle.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function render(): Style
2929
foreach ($class->getDefaultProperties() as $name => $value) {
3030
$this->current_line++;
3131
if ($this->current_line > $this->max_line) {
32-
$this->style->new_lines()->repeat(' ', $this->tab_size * 2)->push('...')->textDim();
32+
$this->style->newLines()->repeat(' ', $this->tab_size * 2)->push('...')->textDim();
3333
break;
3434
}
3535

@@ -52,7 +52,7 @@ public function render(): Style
5252
break;
5353
}
5454

55-
$this->style->new_lines();
55+
$this->style->newLines();
5656
$this->style->repeat(' ', $this->tab_size * 2);
5757
$this->style->push($visible)->textYellow();
5858
$this->style->push($name);
@@ -71,7 +71,7 @@ public function render(): Style
7171
}
7272

7373
if ($class->hasMethod('__tostring')) {
74-
$this->style->new_lines();
74+
$this->style->newLines();
7575
$this->style->repeat(' ', $this->tab_size * 2);
7676
$this->style->push('__toString');
7777
$this->style->push(': ')->textYellow();

tests/Unit/Styles/ClassStyleTest.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Here\Styles\ClassStyle;
66
use PHPUnit\Framework\TestCase;
7+
use PHPUnit\Util\Test;
78
use System\Console\Style\Style;
89

910
final class ClaasStyleTest extends TestCase
@@ -14,9 +15,19 @@ public function itCanRenderVariableStyle()
1415
$style = new Style();
1516
$var = new ClassStyle($style);
1617

17-
$var->ref(now('04-09-2022'));
18+
$var->ref(new TestClassStyle());
1819
$out = $var->render()->__toString();
1920

2021
$this->assertStringContainsString('2022', $out);
2122
}
2223
}
24+
25+
class TestClassStyle
26+
{
27+
/**
28+
* Public property to scan.
29+
*
30+
* @var string
31+
*/
32+
public $date = '04-09-2022';
33+
}

tests/Unit/Styles/DefaultStyleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function itCanRenderVariableStyle()
1414
$style = new Style();
1515
$var = new DefaultStyle($style);
1616

17-
$var->ref(now('04-09-2022')->__toString());
17+
$var->ref((new DateTime('04-09-2022'))->format('Y-m-d H:i:s'));
1818
$out = $var->render()->__toString();
1919

2020
$this->assertStringContainsString('2022', $out);

0 commit comments

Comments
 (0)