Skip to content

Commit ccebd37

Browse files
committed
PHPStan level 9
1 parent a0ea11e commit ccebd37

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ PHAR_BUILD_VERSION
1111
phpunit.xml
1212
phpcs.xml
1313
.phpcs.xml
14+
/build

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"test": [
8282
"@lint",
8383
"@phpcs",
84+
"@phpstan",
8485
"@phpunit",
8586
"@behat"
8687
]

phpstan.neon.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- php
5+
- utils
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli
8+
scanFiles:
9+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
10+
- php/boot-phar.php
11+
treatPhpDocTypesAsCertain: false
12+
dynamicConstantNames:
13+
- WP_DEBUG
14+
- WP_DEBUG_LOG
15+
- WP_DEBUG_DISPLAY
16+
ignoreErrors:
17+
- identifier: missingType.parameter
18+
- identifier: missingType.return

utils/get-package-require-from-composer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
exit( 1 );
77
}
88

9-
$contents = file_get_contents( $file );
9+
$contents = (string) file_get_contents( $file );
1010
$composer = json_decode( $contents );
1111

1212
if ( empty( $composer ) || ! is_object( $composer ) ) {

utils/make-phar.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
define( 'BUILD', isset( $runtime_config['build'] ) ? $runtime_config['build'] : '' );
3939

40-
$current_version = trim( file_get_contents( WP_CLI_ROOT . '/VERSION' ) );
40+
$current_version = trim( (string) file_get_contents( WP_CLI_ROOT . '/VERSION' ) );
4141

4242
if ( isset( $runtime_config['version'] ) ) {
4343
$new_version = $runtime_config['version'];
@@ -101,9 +101,9 @@ static function ( $v ) {
101101
$strips
102102
);
103103
}
104-
$phar[ $key ] = preg_replace( $strip_res, '', file_get_contents( $path ) );
104+
$phar[ $key ] = preg_replace( $strip_res, '', (string) file_get_contents( $path ) );
105105
} else {
106-
$phar[ $key ] = file_get_contents( $path );
106+
$phar[ $key ] = (string) file_get_contents( $path );
107107
}
108108
}
109109

@@ -125,6 +125,9 @@ function get_composer_versions( $current_version ) {
125125
return '';
126126
}
127127

128+
/**
129+
* @var null|array{packages: array{name?: string, version?: string, source?: array{reference?: string}, dist?: array{reference?: string}}} $composer_lock
130+
*/
128131
$composer_lock = json_decode( $composer_lock_file, true );
129132
if ( ! $composer_lock ) {
130133
fwrite( STDERR, sprintf( "Warning: Could not decode '%s'." . PHP_EOL, $composer_lock_path ) );
@@ -286,8 +289,11 @@ function get_composer_versions( $current_version ) {
286289
add_file( $phar, $file );
287290
}
288291
// Any PHP files in the project root
289-
foreach ( glob( WP_CLI_BASE_PATH . '/*.php' ) as $file ) {
290-
add_file( $phar, $file );
292+
$files = glob( WP_CLI_BASE_PATH . '/*.php' );
293+
if ( $files ) {
294+
foreach ( $files as $file ) {
295+
add_file( $phar, $file );
296+
}
291297
}
292298
}
293299
}

0 commit comments

Comments
 (0)