diff --git a/composer.json b/composer.json index c6c799b6..cf77fbfa 100644 --- a/composer.json +++ b/composer.json @@ -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 }, @@ -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" ] diff --git a/features/cron-event.feature b/features/cron-event.feature index 48d01647..86356f20 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -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: """ diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..2b34fce1 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,14 @@ +parameters: + level: 9 + paths: + - src + - cron-command.php + scanDirectories: + - vendor/wp-cli/wp-cli/php + scanFiles: + - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php + treatPhpDocTypesAsCertain: false + ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.parameter + - identifier: missingType.return diff --git a/src/Cron_Command.php b/src/Cron_Command.php index 132ef3c7..290d5050 100644 --- a/src/Cron_Command.php +++ b/src/Cron_Command.php @@ -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( @@ -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 ), ), ); diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 62f2c7ec..e789267c 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -28,7 +28,9 @@ * @package wp-cli */ class Cron_Event_Command extends WP_CLI_Command { - + /** + * @var string[] + */ private $fields = array( 'hook', 'next_run_gmt', @@ -36,6 +38,9 @@ class Cron_Event_Command extends WP_CLI_Command { 'recurrence', ); + /** + * @var string + */ private static $time_format = 'Y-m-d H:i:s'; /** @@ -154,13 +159,17 @@ public function list_( $args, $assoc_args ) { * # Schedule new cron event and pass arguments * $ wp cron event schedule cron_test '+1 hour' --0=first-argument --1=second-argument * Success: Scheduled event with hook 'cron_test' for 2016-05-31 11:21:35 GMT. + * + * @param array{0: string, 1?: string, 2?: string} $args Positional arguments. + * @param array $assoc_args Associative arguments. */ public function schedule( $args, $assoc_args ) { if ( count( $assoc_args ) && count( array_filter( array_keys( $assoc_args ), 'is_string' ) ) ) { 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' ); $recurrence = Utils\get_flag_value( $args, 2, false ); @@ -263,10 +272,6 @@ public function unschedule( $args, $assoc_args ) { 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 ) ) { @@ -457,6 +462,10 @@ protected static function get_cron_events( $is_due_now = false ) { 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 ) { @@ -549,11 +558,18 @@ private static function interval( $since ) { 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]; diff --git a/src/Cron_Schedule_Command.php b/src/Cron_Schedule_Command.php index b5b29fdc..839a91f1 100644 --- a/src/Cron_Schedule_Command.php +++ b/src/Cron_Schedule_Command.php @@ -16,7 +16,9 @@ * +------------+-------------+----------+ */ class Cron_Schedule_Command extends WP_CLI_Command { - + /** + * @var string[] + */ private $fields = array( 'name', 'display',