Skip to content

Commit c5bc385

Browse files
committed
style: run code inspect for test example resource
1 parent 45f0a1a commit c5bc385

22 files changed

+146
-140
lines changed

examples/Command/CorCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
*/
2121
class CorCommand extends Command
2222
{
23-
protected static $name = 'cor';
23+
protected static string $name = 'cor';
2424

25-
protected static $description = 'a coroutine test command';
25+
protected static string $description = 'a coroutine test command';
2626

27-
protected static $coroutine = true;
27+
protected static bool $coroutine = true;
2828

2929
/**
3030
* @return array

examples/Command/DemoCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class DemoCommand extends Command
2323
{
24-
protected static $name = 'demo';
24+
protected static string $name = 'demo';
2525

26-
protected static $description = 'this is a demo alone command. but use Definition instead of annotations';
26+
protected static string $description = 'this is a demo alone command. but use Definition instead of annotations';
2727

2828
/**
2929
* {@inheritDoc}

examples/Command/TestCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
class TestCommand extends Command
2121
{
22-
protected static $name = 'test';
22+
protected static string $name = 'test';
2323

24-
protected static $description = 'this is a test independent command';
24+
protected static string $description = 'this is a test independent command';
2525

2626
protected function commands(): array
2727
{

examples/Controller/HomeController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Inhere\Console\Util\Interact;
1515
use Inhere\Console\Util\ProgressBar;
1616
use Inhere\Console\Util\Show;
17+
use JetBrains\PhpStorm\NoReturn;
1718
use LogicException;
1819
use RuntimeException;
1920
use Toolkit\Cli\Cli;
@@ -31,9 +32,9 @@
3132
*/
3233
class HomeController extends Controller
3334
{
34-
protected static $name = 'home';
35+
protected static string $name = 'home';
3536

36-
protected static $description = 'This is a demo command controller. there are some command usage examples(2)';
37+
protected static string $description = 'This is a demo command controller. there are some command usage examples(2)';
3738

3839
/**
3940
* @return array
@@ -151,6 +152,7 @@ public function exCommand(): void
151152
/**
152153
* a command for test trigger error
153154
*/
155+
#[NoReturn]
154156
public function errorCommand(): void
155157
{
156158
trigger_error('oo, this is a runtime error!', E_USER_ERROR);

examples/Controller/InteractController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
*/
2323
class InteractController extends Controller
2424
{
25-
protected static $name = 'interact';
25+
protected static string $name = 'interact';
2626

27-
protected static $description = 'there are some demo commands for use interactive method';
27+
protected static string $description = 'there are some demo commands for use interactive method';
2828

2929
public static function aliases(): array
3030
{

examples/Controller/ProcessController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class ProcessController extends Controller
2323
{
24-
protected static $name = 'process';
24+
protected static string $name = 'process';
2525

26-
protected static $description = 'Some simple process to create and use examples';
26+
protected static string $description = 'Some simple process to create and use examples';
2727

2828
protected static function commandAliases(): array
2929
{

examples/Controller/ShowController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
*/
2828
class ShowController extends Controller
2929
{
30-
protected static $name = 'show';
30+
protected static string $name = 'show';
3131

32-
protected static $description = 'there are some demo commands for show format data';
32+
protected static string $description = 'there are some demo commands for show format data';
3333

3434
public static function commandAliases(): array
3535
{

examples/alone

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ $ctrl->setDetached();
1919

2020
try {
2121
exit($ctrl->run([$input->getCommand()]));
22-
} catch (\Exception $e) {
22+
} catch (Exception $e) {
2323
$message = Color::apply('error', $e->getMessage());
2424

25-
echo \sprintf("%s\nFile %s:%d\nTrace:\n%s\n",
25+
echo sprintf("%s\nFile %s:%d\nTrace:\n%s\n",
2626
$message, $e->getFile(), $e->getLine(), $e->getTraceAsString()
2727
);
2828
}

examples/alone-app

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ try {
2323
$app->controller('home', HomeController::class);
2424

2525
$subCmd = $input->getCommand();
26-
$result = $app->dispatch('home:' . $subCmd, true);
26+
$result = $app->dispatch('home:' . $subCmd, []);
2727

2828
exit((int)$result);
29-
} catch (\Exception $e) {
29+
} catch (Exception $e) {
3030
$message = Color::apply('error', $e->getMessage());
3131

3232
echo sprintf("%s\nFile %s:%d\nTrace:\n%s\n",

examples/demo/cli-spinner.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,32 @@ public static function spinner(): void
4343

4444
/**
4545
* Uses `stty` to hide input/output completely.
46+
*
4647
* @param boolean $hidden Will hide/show the next data. Defaults to true.
4748
*/
48-
public static function hide($hidden = true): void
49+
public static function hide(bool $hidden = true): void
4950
{
5051
system('stty ' . ($hidden? '-echo' : 'echo'));
5152
}
5253

5354
/**
5455
* Prompts the user for input. Optionally masking it.
5556
*
56-
* @param string $prompt The prompt to show the user
57-
* @param bool $masked If true, the users input will not be shown. e.g. password input
58-
* @param int $limit The maximum amount of input to accept
57+
* @param string $prompt The prompt to show the user
58+
* @param bool $masked If true, the users input will not be shown. e.g. password input
59+
* @param int $limit The maximum amount of input to accept
60+
*
5961
* @return string
6062
*/
61-
public static function prompt($prompt, $masked=false, $limit=100)
63+
public static function prompt(string $prompt, bool $masked, int $limit=100): string
6264
{
6365
echo "$prompt: ";
6466
if ($masked) {
6567
`stty -echo`; // disable shell echo
6668
}
6769
$buffer = '';
6870
$char = '';
69-
$f = fopen('php://stdin', 'r');
71+
$f = fopen('php://stdin', 'rb');
7072
while (strlen($buffer) < $limit) {
7173
$char = fread($f, 1);
7274
if ($char === "\n" || $char === "\r") {
@@ -89,6 +91,7 @@ public static function prompt($prompt, $masked=false, $limit=100)
8991
echo $input;
9092
die;
9193

94+
/** @noinspection PhpUnreachableStatementInspection */
9295
$total = random_int(5000, 10000);
9396
for ($x=1; $x<=$total; $x++) {
9497
Status::spinner();

0 commit comments

Comments
 (0)