Skip to content

Commit 2ea0adf

Browse files
committed
PHPStan level 9
1 parent 0860d10 commit 2ea0adf

File tree

8 files changed

+168
-6
lines changed

8 files changed

+168
-6
lines changed

functions.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?php
22

3-
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Renaming breaks Phar compat.
4-
function wp_export( $args = array() ) {
5-
$defaults = array(
3+
/**
4+
* @param array{filters?: array<mixed>, format?: class-string<WP_Export_WXR_Formatter>, writer?: class-string<WP_Export_Returner>, writer_args?: mixed} $args
5+
*/
6+
function wp_export( $args = array() ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Renaming breaks Phar compat.
7+
$defaults = array(
68
'filters' => array(),
79
'format' => 'WP_Export_WXR_Formatter',
810
'writer' => 'WP_Export_Returner',
911
'writer_args' => null,
1012
);
13+
14+
/**
15+
* @var array{filters: array<mixed>, format: class-string<WP_Export_WXR_Formatter>, writer: class-string<WP_Export_Returner>, writer_args: mixed} $args
16+
*/
1117
$args = wp_parse_args( $args, $defaults );
1218
$export_query = new WP_Export_Query( $args['filters'] );
1319
$formatter = new $args['format']( $export_query );

phpstan.neon.dist

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

src/Export_Command.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,14 @@ private function validate_args( $args ) {
251251
}
252252
}
253253

254+
/**
255+
* @param string $path
256+
*
257+
* @phpstan-ignore method.unused
258+
*/
254259
private function check_dir( $path ) {
255260
if ( empty( $path ) ) {
256-
$path = getcwd();
261+
$path = (string) getcwd();
257262
} elseif ( ! is_dir( $path ) ) {
258263
WP_CLI::error( sprintf( "The directory '%s' does not exist.", $path ) );
259264
} elseif ( ! is_writable( $path ) ) {
@@ -265,6 +270,11 @@ private function check_dir( $path ) {
265270
return true;
266271
}
267272

273+
/**
274+
* @param string $date
275+
*
276+
* @phpstan-ignore method.unused
277+
*/
268278
private function check_start_date( $date ) {
269279
if ( null === $date ) {
270280
return true;
@@ -279,6 +289,11 @@ private function check_start_date( $date ) {
279289
return true;
280290
}
281291

292+
/**
293+
* @param string $date
294+
*
295+
* @phpstan-ignore method.unused
296+
*/
282297
private function check_end_date( $date ) {
283298
if ( null === $date ) {
284299
return true;
@@ -293,6 +308,11 @@ private function check_end_date( $date ) {
293308
return true;
294309
}
295310

311+
/**
312+
* @param string $post_type
313+
*
314+
* @phpstan-ignore method.unused
315+
*/
296316
private function check_post_type( $post_type ) {
297317
if ( null === $post_type || 'any' === $post_type ) {
298318
return true;
@@ -317,6 +337,11 @@ private function check_post_type( $post_type ) {
317337
return true;
318338
}
319339

340+
/**
341+
* @param string $post_type
342+
*
343+
* @phpstan-ignore method.unused
344+
*/
320345
private function check_post_type__not_in( $post_type ) {
321346
if ( null === $post_type ) {
322347
return true;
@@ -341,6 +366,11 @@ private function check_post_type__not_in( $post_type ) {
341366
return true;
342367
}
343368

369+
/**
370+
* @param string $post__in
371+
*
372+
* @phpstan-ignore method.unused
373+
*/
344374
private function check_post__in( $post__in ) {
345375
if ( null === $post__in ) {
346376
return true;
@@ -357,6 +387,11 @@ private function check_post__in( $post__in ) {
357387
return true;
358388
}
359389

390+
/**
391+
* @param string $start_id
392+
*
393+
* @phpstan-ignore method.unused
394+
*/
360395
private function check_start_id( $start_id ) {
361396
if ( null === $start_id ) {
362397
return true;
@@ -374,6 +409,11 @@ private function check_start_id( $start_id ) {
374409
return true;
375410
}
376411

412+
/**
413+
* @param string $author
414+
*
415+
* @phpstan-ignore method.unused
416+
*/
377417
private function check_author( $author ) {
378418
if ( null === $author ) {
379419
return true;
@@ -418,6 +458,11 @@ private function check_max_num_posts( $num ) {
418458
return true;
419459
}
420460

461+
/**
462+
* @param string $category
463+
*
464+
* @phpstan-ignore method.unused
465+
*/
421466
private function check_category( $category ) {
422467
if ( null === $category ) {
423468
return true;
@@ -436,6 +481,11 @@ private function check_category( $category ) {
436481
return true;
437482
}
438483

484+
/**
485+
* @param string $status
486+
*
487+
* @phpstan-ignore method.unused
488+
*/
439489
private function check_post_status( $status ) {
440490
if ( null === $status ) {
441491
return true;
@@ -455,6 +505,11 @@ private function check_post_status( $status ) {
455505
return true;
456506
}
457507

508+
/**
509+
* @param string|null $shkip
510+
*
511+
* @phpstan-ignore method.unused
512+
*/
458513
private function check_skip_comments( $skip ) {
459514
if ( null === $skip ) {
460515
return true;
@@ -468,6 +523,11 @@ private function check_skip_comments( $skip ) {
468523
return true;
469524
}
470525

526+
/**
527+
* @param string $size
528+
*
529+
* @phpstan-ignore method.unused
530+
*/
471531
private function check_max_file_size( $size ) {
472532
if ( ! is_numeric( $size ) ) {
473533
WP_CLI::warning( 'max_file_size should be numeric.' );
@@ -479,6 +539,11 @@ private function check_max_file_size( $size ) {
479539
return true;
480540
}
481541

542+
/**
543+
* @param string $once
544+
*
545+
* @phpstan-ignore method.unused
546+
*/
482547
private function check_include_once( $once ) {
483548
if ( null === $once ) {
484549
return true;
@@ -497,6 +562,11 @@ private function check_include_once( $once ) {
497562
return true;
498563
}
499564

565+
/**
566+
* @param string $allow_orphan_terms
567+
*
568+
* @phpstan-ignore method.unused
569+
*/
500570
private function check_allow_orphan_terms( $allow_orphan_terms ) {
501571
if ( null === $allow_orphan_terms ) {
502572
return true;

src/WP_Export_Returner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class WP_Export_Returner extends WP_Export_Base_Writer {
44
private $result = '';
55

66
public function export() {
7-
$this->private = '';
87
try {
98
parent::export();
109
} catch ( WP_Export_Exception $e ) {

src/WP_Export_WXR_Formatter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@
1212
* Responsible for formatting the data in WP_Export_Query to WXR
1313
*/
1414
class WP_Export_WXR_Formatter {
15+
/**
16+
* @var WP_Export_Query
17+
*/
18+
private $export;
19+
20+
/**
21+
* @var string
22+
*/
23+
private $wxr_version;
24+
1525
public function __construct( $export ) {
1626
$this->export = $export;
1727
$this->wxr_version = WXR_VERSION;
1828
}
1929

30+
/**
31+
* @param array<string> $requested_sections
32+
*/
2033
public function before_posts( $requested_sections = [] ) {
2134
$available_sections = [
2235
'header',

src/WP_Export_XML_Over_HTTP.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<?php
22

3-
43
class WP_Export_XML_Over_HTTP extends WP_Export_Base_Writer {
4+
/**
5+
* @var string
6+
*/
7+
private $result;
8+
9+
/**
10+
* @var string
11+
*/
512
private $file_name;
613

14+
/**
15+
* @param WP_Export_WXR_Formatter $formatter
16+
* @param string $file_name
17+
*/
718
public function __construct( $formatter, $file_name ) {
819
parent::__construct( $formatter );
920
$this->file_name = $file_name;

src/WP_Map_Iterator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?php
22

33
class WP_Map_Iterator extends IteratorIterator {
4+
/**
5+
* @var callable
6+
*/
7+
private $callback;
8+
9+
/**
10+
* @param \Iterator $iterator
11+
* @param callable $callback
12+
*/
413
public function __construct( $iterator, $callback ) {
514
$this->callback = $callback;
615
parent::__construct( $iterator );

src/WP_Post_IDs_Iterator.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
<?php
22

3+
/**
4+
* @implements \Iterator<int, object{}>
5+
*/
36
class WP_Post_IDs_Iterator implements Iterator {
7+
/**
8+
* @var \wpdb
9+
*/
10+
private $db;
11+
12+
/**
13+
* @var int
14+
*/
415
private $limit = 100;
16+
17+
/**
18+
* @var int[]
19+
*/
520
private $post_ids;
21+
22+
/**
23+
* @var int[]
24+
*/
625
private $ids_left;
26+
27+
/**
28+
* @var int[]
29+
*/
730
private $results = array();
831

32+
/**
33+
* @var int
34+
*/
35+
private $index_in_results;
36+
37+
/**
38+
* @var int
39+
*/
40+
private $global_index;
41+
942
public function __construct( $post_ids, $limit = null ) {
1043
$this->db = $GLOBALS['wpdb'];
1144
$this->post_ids = $post_ids;
@@ -15,26 +48,31 @@ public function __construct( $post_ids, $limit = null ) {
1548
}
1649
}
1750

51+
#[\ReturnTypeWillChange]
1852
public function current() {
1953
return $this->results[ $this->index_in_results ];
2054
}
2155

56+
#[\ReturnTypeWillChange]
2257
public function key() {
2358
return $this->global_index;
2459
}
2560

61+
#[\ReturnTypeWillChange]
2662
public function next() {
2763
++$this->index_in_results;
2864
++$this->global_index;
2965
}
3066

67+
#[\ReturnTypeWillChange]
3168
public function rewind() {
3269
$this->results = array();
3370
$this->global_index = 0;
3471
$this->index_in_results = 0;
3572
$this->ids_left = $this->post_ids;
3673
}
3774

75+
#[\ReturnTypeWillChange]
3876
public function valid() {
3977
if ( isset( $this->results[ $this->index_in_results ] ) ) {
4078
return true;

0 commit comments

Comments
 (0)