Skip to content

PHPStan level 9 #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/eval-command": "^2.0",
"wp-cli/server-command": "^2.0",
"wp-cli/wp-cli-tests": "^4"
"wp-cli/wp-cli-tests": "dev-add/phpstan-enhancements"
},
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
"johnpbloch/wordpress-core-installer": true,
"phpstan/extension-installer": true
},
"lock": false
},
Expand Down Expand Up @@ -62,12 +63,14 @@
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpstan": "run-phpstan-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpstan",
"@phpunit",
"@behat"
]
Expand Down
8 changes: 0 additions & 8 deletions features/cron-event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ Feature: Manage WP Cron events
Error: No events found for hook 'wp_cli_test_event'.
"""

@less-than-wp-4.9.0
Scenario: Unschedule cron event for WP < 4.9.0, wp_unschedule_hook was not included
When I try `wp cron event unschedule wp_cli_test_event_1`
Then STDERR should be:
"""
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.
"""

Scenario: Run cron event with a registered shutdown function
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
"""
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
level: 9
paths:
- src
- cron-command.php
scanDirectories:
- vendor/wp-cli/wp-cli/php
- vendor/wp-cli/wp-cli-tests
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
treatPhpDocTypesAsCertain: false
dynamicConstantNames:
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.parameter
- identifier: missingType.return
3 changes: 1 addition & 2 deletions src/Cron_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function test() {
*/
protected static function get_cron_spawn() {

$sslverify = \WP_CLI\Utils\wp_version_compare( 4.0, '<' );
$doing_wp_cron = sprintf( '%.22F', microtime( true ) );

$cron_request_array = array(
Expand All @@ -75,7 +74,7 @@ protected static function get_cron_spawn() {
'timeout' => 3,
'blocking' => true,
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
),
);

Expand Down
25 changes: 19 additions & 6 deletions src/Cron_Event_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
* @package wp-cli
*/
class Cron_Event_Command extends WP_CLI_Command {

/**
* @var string[]
*/
private $fields = array(
'hook',
'next_run_gmt',
'next_run_relative',
'recurrence',
);

/**
* @var string
*/
private static $time_format = 'Y-m-d H:i:s';

/**
Expand Down Expand Up @@ -160,9 +165,10 @@
WP_CLI::warning( 'Numeric keys should be used for the hook arguments.' );
}

$hook = $args[0];
$hook = $args[0];

$next_run = Utils\get_flag_value( $args, 1, 'now' );

Check failure on line 170 in src/Cron_Event_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $flag of function WP_CLI\Utils\get_flag_value expects string, int given.
$recurrence = Utils\get_flag_value( $args, 2, false );

Check failure on line 171 in src/Cron_Event_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $flag of function WP_CLI\Utils\get_flag_value expects string, int given.

if ( empty( $next_run ) ) {
$timestamp = time();
Expand Down Expand Up @@ -263,10 +269,6 @@

list( $hook ) = $args;

if ( Utils\wp_version_compare( '4.9.0', '<' ) ) {
WP_CLI::error( 'Unscheduling events is only supported from WordPress 4.9.0 onwards.' );
}

$unscheduled = wp_unschedule_hook( $hook );

if ( empty( $unscheduled ) ) {
Expand Down Expand Up @@ -457,6 +459,10 @@
protected static function get_selected_cron_events( $args, $assoc_args ) {
$due_now = Utils\get_flag_value( $assoc_args, 'due-now' );
$all = Utils\get_flag_value( $assoc_args, 'all' );

/**
* @var string $exclude
*/
$exclude = Utils\get_flag_value( $assoc_args, 'exclude' );

if ( empty( $args ) && ! $due_now && ! $all ) {
Expand Down Expand Up @@ -549,11 +555,18 @@
array( 1, 'second' ),
);

$name = 'second';
$count = 0;
$seconds = 1;

// we only want to output two chunks of time here, eg:
// x years, xx months
// x days, xx hours
// so there's only two bits of calculation below:

$i = 0;
$j = 0;

// step one: the first chunk
for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
$seconds = $chunks[ $i ][0];
Expand Down
4 changes: 3 additions & 1 deletion src/Cron_Schedule_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* +------------+-------------+----------+
*/
class Cron_Schedule_Command extends WP_CLI_Command {

/**
* @var string[]
*/
private $fields = array(
'name',
'display',
Expand Down
Loading