Skip to content

Commit 82cb962

Browse files
authored
Merge pull request #74 from wp-cli/add/phpstan
2 parents bae46fd + 62a6fb9 commit 82cb962

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

phpstan.neon.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- src
5+
- shell-command.php
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli/php
8+
scanFiles:
9+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
10+
treatPhpDocTypesAsCertain: false
11+
ignoreErrors:
12+
- identifier: class.notFound
13+
- identifier: missingType.property
14+
- identifier: missingType.parameter
15+
- identifier: missingType.return

src/Shell_Command.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class Shell_Command extends WP_CLI_Command {
2727
* => string(6) "WP-CLI"
2828
*/
2929
public function __invoke( $_, $assoc_args ) {
30+
$class = WP_CLI\Shell\REPL::class;
31+
3032
$implementations = array(
31-
'Psy\\Shell',
32-
'Boris\\Boris',
33-
'WP_CLI\\Shell\\REPL',
33+
\Psy\Shell::class,
34+
\Boris\Boris::class,
35+
WP_CLI\Shell\REPL::class,
3436
);
3537

36-
if ( Utils\get_flag_value( $assoc_args, 'basic' ) ) {
37-
$class = 'WP_CLI\\Shell\\REPL';
38-
} else {
38+
if ( ! Utils\get_flag_value( $assoc_args, 'basic' ) ) {
3939
foreach ( $implementations as $candidate ) {
4040
if ( class_exists( $candidate ) ) {
4141
$class = $candidate;
@@ -44,10 +44,17 @@ public function __invoke( $_, $assoc_args ) {
4444
}
4545
}
4646

47-
if ( 'Psy\\Shell' === $class ) {
47+
/**
48+
* @var class-string $class
49+
*/
50+
51+
if ( \Psy\Shell::class === $class ) {
4852
$shell = new Psy\Shell();
4953
$shell->run();
5054
} else {
55+
/**
56+
* @var class-string<WP_CLI\Shell\REPL> $class
57+
*/
5158
$repl = new $class( 'wp> ' );
5259
$repl->start();
5360
}

src/WP_CLI/Shell/REPL.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct( $prompt ) {
1717
}
1818

1919
public function start() {
20+
// @phpstan-ignore while.alwaysTrue
2021
while ( true ) {
2122
$line = $this->prompt();
2223

@@ -30,7 +31,7 @@ public function start() {
3031
ob_start();
3132
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
3233
eval( $line );
33-
$out = ob_get_clean();
34+
$out = (string) ob_get_clean();
3435
if ( 0 < strlen( $out ) ) {
3536
$out = rtrim( $out, "\n" ) . "\n";
3637
}
@@ -44,13 +45,13 @@ public function start() {
4445
ob_start();
4546
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
4647
$evl = eval( $line );
47-
$out = ob_get_clean();
48+
$out = (string) ob_get_clean();
4849
if ( 0 < strlen( $out ) ) {
4950
echo rtrim( $out, "\n" ) . "\n";
5051
}
5152
echo '=> ';
5253
var_dump( $evl );
53-
fwrite( STDOUT, ob_get_clean() );
54+
fwrite( STDOUT, (string) ob_get_clean() );
5455
}
5556
}
5657
}
@@ -82,13 +83,16 @@ private function prompt() {
8283

8384
$done = false;
8485
do {
86+
// @phpstan-ignore booleanNot.alwaysTrue
8587
$prompt = ( ! $done && false !== $full_line ) ? '--> ' : $this->prompt;
8688

8789
$fp = popen( self::create_prompt_cmd( $prompt, $this->history_file ), 'r' );
8890

89-
$line = fgets( $fp );
91+
$line = $fp ? fgets( $fp ) : '';
9092

91-
pclose( $fp );
93+
if ( $fp ) {
94+
pclose( $fp );
95+
}
9296

9397
if ( ! $line ) {
9498
break;

0 commit comments

Comments
 (0)