PHPStan level 9

This commit is contained in:
Pascal Birchler 2025-07-10 16:31:07 +02:00
parent a0ea11e9be
commit ccebd37467
No known key found for this signature in database
GPG key ID: 0DECE73DD74E8B2F
5 changed files with 32 additions and 6 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ PHAR_BUILD_VERSION
phpunit.xml
phpcs.xml
.phpcs.xml
/build

View file

@ -81,6 +81,7 @@
"test": [
"@lint",
"@phpcs",
"@phpstan",
"@phpunit",
"@behat"
]

18
phpstan.neon.dist Normal file
View file

@ -0,0 +1,18 @@
parameters:
level: 9
paths:
- php
- utils
scanDirectories:
- vendor/wp-cli/wp-cli
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- php/boot-phar.php
treatPhpDocTypesAsCertain: false
dynamicConstantNames:
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
ignoreErrors:
- identifier: missingType.parameter
- identifier: missingType.return

View file

@ -6,7 +6,7 @@ if ( ! file_exists( $file ) ) {
exit( 1 );
}
$contents = file_get_contents( $file );
$contents = (string) file_get_contents( $file );
$composer = json_decode( $contents );
if ( empty( $composer ) || ! is_object( $composer ) ) {

View file

@ -37,7 +37,7 @@ define( 'BE_QUIET', isset( $runtime_config['quiet'] ) && $runtime_config['quiet'
define( 'BUILD', isset( $runtime_config['build'] ) ? $runtime_config['build'] : '' );
$current_version = trim( file_get_contents( WP_CLI_ROOT . '/VERSION' ) );
$current_version = trim( (string) file_get_contents( WP_CLI_ROOT . '/VERSION' ) );
if ( isset( $runtime_config['version'] ) ) {
$new_version = $runtime_config['version'];
@ -101,9 +101,9 @@ function add_file( $phar, $path ) {
$strips
);
}
$phar[ $key ] = preg_replace( $strip_res, '', file_get_contents( $path ) );
$phar[ $key ] = preg_replace( $strip_res, '', (string) file_get_contents( $path ) );
} else {
$phar[ $key ] = file_get_contents( $path );
$phar[ $key ] = (string) file_get_contents( $path );
}
}
@ -125,6 +125,9 @@ function get_composer_versions( $current_version ) {
return '';
}
/**
* @var null|array{packages: array{name?: string, version?: string, source?: array{reference?: string}, dist?: array{reference?: string}}} $composer_lock
*/
$composer_lock = json_decode( $composer_lock_file, true );
if ( ! $composer_lock ) {
fwrite( STDERR, sprintf( "Warning: Could not decode '%s'." . PHP_EOL, $composer_lock_path ) );
@ -286,8 +289,11 @@ if ( 'cli' !== BUILD ) {
add_file( $phar, $file );
}
// Any PHP files in the project root
foreach ( glob( WP_CLI_BASE_PATH . '/*.php' ) as $file ) {
add_file( $phar, $file );
$files = glob( WP_CLI_BASE_PATH . '/*.php' );
if ( $files ) {
foreach ( $files as $file ) {
add_file( $phar, $file );
}
}
}
}