Skip to content

Commit 3474dc8

Browse files
committed
PHPStan level 9
wip
1 parent bae46fd commit 3474dc8

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

phpstan.neon.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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: missingType.property
13+
- identifier: missingType.parameter
14+
- identifier: missingType.return

src/Shell_Command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class Shell_Command extends WP_CLI_Command {
2727
* => string(6) "WP-CLI"
2828
*/
2929
public function __invoke( $_, $assoc_args ) {
30+
/**
31+
* @var array<class-string> $implementations
32+
*/
3033
$implementations = array(
3134
'Psy\\Shell',
3235
'Boris\\Boris',
@@ -44,6 +47,10 @@ public function __invoke( $_, $assoc_args ) {
4447
}
4548
}
4649

50+
/**
51+
* @var class-string $class
52+
*/
53+
4754
if ( 'Psy\\Shell' === $class ) {
4855
$shell = new Psy\Shell();
4956
$shell->run();

src/WP_CLI/Shell/REPL.php

Lines changed: 8 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
}
@@ -86,9 +87,11 @@ private function prompt() {
8687

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

89-
$line = fgets( $fp );
90+
$line = $fp ? fgets( $fp ) : '';
9091

91-
pclose( $fp );
92+
if ( $fp ) {
93+
pclose( $fp );
94+
}
9295

9396
if ( ! $line ) {
9497
break;

0 commit comments

Comments
 (0)