Skip to content

Commit 6f02324

Browse files
authored
Merge pull request #116 from wp-cli/add/phpstan
2 parents 224371b + bd2d7c1 commit 6f02324

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
}
1313
],
1414
"require": {
15-
"wp-cli/wp-cli": "^2.12"
15+
"wp-cli/wp-cli": "^2.13"
1616
},
1717
"require-dev": {
1818
"wp-cli/entity-command": "^1.3 || ^2",
1919
"wp-cli/eval-command": "^2.0",
2020
"wp-cli/server-command": "^2.0",
21-
"wp-cli/wp-cli-tests": "^4"
21+
"wp-cli/wp-cli-tests": "^5"
2222
},
2323
"config": {
2424
"process-timeout": 7200,
2525
"sort-packages": true,
2626
"allow-plugins": {
2727
"dealerdirect/phpcodesniffer-composer-installer": true,
28-
"johnpbloch/wordpress-core-installer": true
28+
"johnpbloch/wordpress-core-installer": true,
29+
"phpstan/extension-installer": true
2930
},
3031
"lock": false
3132
},
@@ -62,12 +63,14 @@
6263
"behat-rerun": "rerun-behat-tests",
6364
"lint": "run-linter-tests",
6465
"phpcs": "run-phpcs-tests",
66+
"phpstan": "run-phpstan-tests",
6567
"phpcbf": "run-phpcbf-cleanup",
6668
"phpunit": "run-php-unit-tests",
6769
"prepare-tests": "install-package-tests",
6870
"test": [
6971
"@lint",
7072
"@phpcs",
73+
"@phpstan",
7174
"@phpunit",
7275
"@behat"
7376
]

features/cron-event.feature

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ Feature: Manage WP Cron events
8181
Error: No events found for hook 'wp_cli_test_event'.
8282
"""
8383

84-
@less-than-wp-4.9.0
85-
Scenario: Unschedule cron event for WP < 4.9.0, wp_unschedule_hook was not included
86-
When I try `wp cron event unschedule wp_cli_test_event_1`
87-
Then STDERR should be:
88-
"""
89-
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.
90-
"""
91-
9284
Scenario: Run cron event with a registered shutdown function
9385
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
9486
"""

phpstan.neon.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- src
5+
- cron-command.php
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli/php
8+
scanFiles:
9+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
10+
treatPhpDocTypesAsCertain: false
11+
ignoreErrors:
12+
- identifier: missingType.iterableValue
13+
- identifier: missingType.parameter
14+
- identifier: missingType.return

src/Cron_Command.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function test() {
6565
*/
6666
protected static function get_cron_spawn() {
6767

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

7170
$cron_request_array = array(
@@ -75,7 +74,7 @@ protected static function get_cron_spawn() {
7574
'timeout' => 3,
7675
'blocking' => true,
7776
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
78-
'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
77+
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
7978
),
8079
);
8180

src/Cron_Event_Command.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@
2828
* @package wp-cli
2929
*/
3030
class Cron_Event_Command extends WP_CLI_Command {
31-
31+
/**
32+
* @var string[]
33+
*/
3234
private $fields = array(
3335
'hook',
3436
'next_run_gmt',
3537
'next_run_relative',
3638
'recurrence',
3739
);
3840

41+
/**
42+
* @var string
43+
*/
3944
private static $time_format = 'Y-m-d H:i:s';
4045

4146
/**
@@ -154,13 +159,17 @@ public function list_( $args, $assoc_args ) {
154159
* # Schedule new cron event and pass arguments
155160
* $ wp cron event schedule cron_test '+1 hour' --0=first-argument --1=second-argument
156161
* Success: Scheduled event with hook 'cron_test' for 2016-05-31 11:21:35 GMT.
162+
*
163+
* @param array{0: string, 1?: string, 2?: string} $args Positional arguments.
164+
* @param array<int, string> $assoc_args Associative arguments.
157165
*/
158166
public function schedule( $args, $assoc_args ) {
159167
if ( count( $assoc_args ) && count( array_filter( array_keys( $assoc_args ), 'is_string' ) ) ) {
160168
WP_CLI::warning( 'Numeric keys should be used for the hook arguments.' );
161169
}
162170

163-
$hook = $args[0];
171+
$hook = $args[0];
172+
164173
$next_run = Utils\get_flag_value( $args, 1, 'now' );
165174
$recurrence = Utils\get_flag_value( $args, 2, false );
166175

@@ -263,10 +272,6 @@ public function unschedule( $args, $assoc_args ) {
263272

264273
list( $hook ) = $args;
265274

266-
if ( Utils\wp_version_compare( '4.9.0', '<' ) ) {
267-
WP_CLI::error( 'Unscheduling events is only supported from WordPress 4.9.0 onwards.' );
268-
}
269-
270275
$unscheduled = wp_unschedule_hook( $hook );
271276

272277
if ( empty( $unscheduled ) ) {
@@ -457,6 +462,10 @@ protected static function get_cron_events( $is_due_now = false ) {
457462
protected static function get_selected_cron_events( $args, $assoc_args ) {
458463
$due_now = Utils\get_flag_value( $assoc_args, 'due-now' );
459464
$all = Utils\get_flag_value( $assoc_args, 'all' );
465+
466+
/**
467+
* @var string $exclude
468+
*/
460469
$exclude = Utils\get_flag_value( $assoc_args, 'exclude' );
461470

462471
if ( empty( $args ) && ! $due_now && ! $all ) {
@@ -549,11 +558,18 @@ private static function interval( $since ) {
549558
array( 1, 'second' ),
550559
);
551560

561+
$name = 'second';
562+
$count = 0;
563+
$seconds = 1;
564+
552565
// we only want to output two chunks of time here, eg:
553566
// x years, xx months
554567
// x days, xx hours
555568
// so there's only two bits of calculation below:
556569

570+
$i = 0;
571+
$j = 0;
572+
557573
// step one: the first chunk
558574
for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
559575
$seconds = $chunks[ $i ][0];

src/Cron_Schedule_Command.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
* +------------+-------------+----------+
1717
*/
1818
class Cron_Schedule_Command extends WP_CLI_Command {
19-
19+
/**
20+
* @var string[]
21+
*/
2022
private $fields = array(
2123
'name',
2224
'display',

0 commit comments

Comments
 (0)