Skip to content

Commit 995552d

Browse files
committed
PHPStan level 5
1 parent f282b67 commit 995552d

File tree

6 files changed

+44
-28
lines changed

6 files changed

+44
-28
lines changed

bin/run-phpstan-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# Run the code style check only if a configuration file exists.
44
if [ -f "phpstan.dist.neon" ] || [ -f "phpstan.neon.dist" ] || [ -f "phpstan.neon" ]
55
then
6-
vendor/bin/phpstan analyse "$@"
6+
vendor/bin/phpstan --memory-limit=2048M analyse "$@"
77
fi

phpstan.neon.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
- tests
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli
8+
- vendor/phpunit/php-code-coverage
9+
- vendor/behat/behat
10+
scanFiles:
11+
- tests/phpstan/scan-files.php
12+
treatPhpDocTypesAsCertain: false
13+
dynamicConstantNames:
14+
- WP_DEBUG
15+
- WP_DEBUG_LOG
16+
- WP_DEBUG_DISPLAY
17+
ignoreErrors:
18+
# Needs fixing in WP-CLI.
19+
- message: '#Parameter \#1 \$cmd of function WP_CLI\\Utils\\esc_cmd expects array<string>#'

src/Context/FeatureContext.php

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,10 @@ public function install_wp( $subdir = '' ) {
11801180
];
11811181

11821182
$run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR'];
1183-
$install_cache_path = '';
11841183

1185-
if ( self::$install_cache_dir ) {
1186-
$install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir );
1187-
}
1184+
$install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir );
11881185

1189-
if ( $install_cache_path && file_exists( $install_cache_path ) ) {
1186+
if ( file_exists( $install_cache_path ) ) {
11901187
self::copy_dir( $install_cache_path, $run_dir );
11911188

11921189
// This is the sqlite equivalent of restoring a database dump in MySQL
@@ -1198,26 +1195,24 @@ public function install_wp( $subdir = '' ) {
11981195
} else {
11991196
$this->proc( 'wp core install', $install_args, $subdir )->run_check();
12001197

1201-
if ( $install_cache_path ) {
1202-
mkdir( $install_cache_path );
1198+
mkdir( $install_cache_path );
12031199

1204-
self::dir_diff_copy( $run_dir, self::$cache_dir, $install_cache_path );
1200+
self::dir_diff_copy( $run_dir, self::$cache_dir, $install_cache_path );
12051201

1206-
if ( 'sqlite' !== self::$db_type ) {
1207-
$mysqldump_binary = Utils\get_sql_dump_command();
1208-
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
1209-
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
1210-
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
1211-
if ( $support_column_statistics ) {
1212-
$command .= ' --skip-column-statistics';
1213-
}
1214-
self::run_sql( $command, [ 'result-file' => "{$install_cache_path}.sql" ], true /*add_database*/ );
1202+
if ( 'sqlite' !== self::$db_type ) {
1203+
$mysqldump_binary = Utils\get_sql_dump_command();
1204+
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
1205+
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
1206+
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
1207+
if ( $support_column_statistics ) {
1208+
$command .= ' --skip-column-statistics';
12151209
}
1210+
self::run_sql( $command, [ 'result-file' => "{$install_cache_path}.sql" ], true /*add_database*/ );
1211+
}
12161212

1217-
if ( 'sqlite' === self::$db_type ) {
1218-
// This is the sqlite equivalent of creating a database dump in MySQL
1219-
copy( "$run_dir/wp-content/database/.ht.sqlite", "{$install_cache_path}.sqlite" );
1220-
}
1213+
if ( 'sqlite' === self::$db_type ) {
1214+
// This is the sqlite equivalent of creating a database dump in MySQL
1215+
copy( "$run_dir/wp-content/database/.ht.sqlite", "{$install_cache_path}.sqlite" );
12211216
}
12221217
}
12231218
}
@@ -1557,11 +1552,6 @@ function wpcli_bootstrap_behat_feature_context() {
15571552
$framework_folder = FeatureContext::get_framework_dir();
15581553
wp_cli_behat_env_debug( "Framework folder location: {$framework_folder}" );
15591554

1560-
// Didn't manage to detect a valid framework folder.
1561-
if ( empty( $vendor_folder ) ) {
1562-
return;
1563-
}
1564-
15651555
// Load helper functionality that is needed for the tests.
15661556
require_once "{$framework_folder}/php/utils.php";
15671557
require_once "{$framework_folder}/php/WP_CLI/Process.php";

src/Context/Support.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function check_string( $output, $expected, $action, $message = false,
7070
break;
7171

7272
default:
73-
throw new PendingException();
73+
throw new \Behat\Behat\Tester\Exception\PendingException();
7474
}
7575

7676
if ( ! $r ) {

src/Context/ThenStepDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ public function then_a_specific_file_folder_should_exist( $path, $type, $strictl
423423
}
424424
$action = substr( $action, 0, -1 );
425425
$expected = $this->replace_variables( (string) $expected );
426+
$contents = '';
426427
if ( 'file' === $type ) {
427428
$contents = file_get_contents( $path );
428429
} elseif ( 'directory' === $type ) {

tests/phpstan/scan-files.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
namespace SebastianBergmann\CodeCoverage\Driver {
4+
class Xdebug {
5+
}
6+
}

0 commit comments

Comments
 (0)