Skip to content

Commit 17d8404

Browse files
authored
PHPStan Level 6 (#416)
1 parent d393723 commit 17d8404

11 files changed

+68
-41
lines changed

includes/ContentImport/AttachmentPathFinder.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ class AttachmentPathFinder extends MslsRegistryInstance {
99
const LINKED = '_msls_linked';
1010

1111
/**
12-
* @param array $sources
13-
* @param mixed $sizeArray
14-
* @param string $imageSrc
15-
* @param mixed $imageMeta
16-
* @param int $attachmentId
17-
* @return array<string, string>
12+
* @param array<string, array<string, mixed>> $sources
13+
* @param mixed $sizeArray
14+
* @param string $imageSrc
15+
* @param mixed $imageMeta
16+
* @param int $attachmentId
17+
*
18+
* @return array<string, mixed>
1819
*/
1920
public function filter_srcset( array $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ): array {
2021
if ( ! $msls_imported = $this->has_import_data( $attachmentId ) ) {
@@ -41,7 +42,7 @@ public function filter_srcset( array $sources, $sizeArray, $imageSrc, $imageMeta
4142

4243
/**
4344
* @param int $attachment_id
44-
* @return array|false
45+
* @return array<string, mixed>|false
4546
*/
4647
protected function has_import_data( $attachment_id ) {
4748
if ( empty( $attachment_id ) ) {
@@ -84,8 +85,8 @@ public function filter_attachment_url( $url, $attachment_id ) {
8485
}
8586

8687
/**
87-
* @param int $attachment_id
88-
* @param array $msls_imported
88+
* @param int $attachment_id
89+
* @param array<string, mixed> $msls_imported
8990
*
9091
* @return \WP_Post|false
9192
*/

includes/ContentImport/ContentImporter.php

+23-12
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public function set_relations( $relations ): void {
7878
/**
7979
* Handles an import request happening during a post save or a template redirect.
8080
*
81-
* @param array $data
81+
* @param string[] $data
8282
*
83-
* @return array The updated, if needed, data array.
83+
* @return string[] The updated, if needed, data array.
8484
*/
8585
public function handle_import( array $data = array() ) {
8686
if ( ! $this->pre_flight_check() || false === $sources = $this->parse_sources() ) {
@@ -138,7 +138,7 @@ public function handle_import( array $data = array() ) {
138138
*
139139
* @return bool
140140
*/
141-
protected function pre_flight_check( array $data = array() ) {
141+
protected function pre_flight_check() {
142142
if ( ! $this->handle ) {
143143
return false;
144144
}
@@ -157,7 +157,7 @@ protected function pre_flight_check( array $data = array() ) {
157157
/**
158158
* Parses the source blog and post IDs from the $_POST array validating them.
159159
*
160-
* @return array|bool
160+
* @return int[]|bool
161161
*/
162162
public function parse_sources() {
163163
if ( ! MslsRequest::has_var( 'msls_import' ) ) {
@@ -203,6 +203,12 @@ protected function get_the_blog_post_ID( $blog_id ) {
203203
return $this->insert_blog_post( $blog_id, $data );
204204
}
205205

206+
/**
207+
* @param int $blog_id
208+
* @param array<string, mixed> $data
209+
*
210+
* @return bool|int
211+
*/
206212
protected function insert_blog_post( $blog_id, array $data = array() ) {
207213
if ( empty( $data ) ) {
208214
return false;
@@ -225,6 +231,11 @@ protected function insert_blog_post( $blog_id, array $data = array() ) {
225231
return $this->has_created_post;
226232
}
227233

234+
/**
235+
* @param bool $handle
236+
*
237+
* @return void
238+
*/
228239
public function handle( $handle ) {
229240
$this->handle = $handle;
230241

@@ -240,11 +251,11 @@ public function handle( $handle ) {
240251
* Imports content according to the provided coordinates.
241252
*
242253
* @param ImportCoordinates $import_coordinates
243-
* @param array $post_fields An optional array of post fields; this can be
244-
* left empty if the method is not called as a consequence
245-
* of filtering the `wp_insert_post_data` filter.
254+
* @param string[] $post_fields An optional array of post fields; this can be
255+
* left empty if the method is not called as a consequence
256+
* of filtering the `wp_insert_post_data` filter.
246257
*
247-
* @return array An array of modified post fields.
258+
* @return string[] An array of modified post fields.
248259
*/
249260
public function import_content( ImportCoordinates $import_coordinates, array $post_fields = array() ) {
250261
if ( ! $import_coordinates->validate() ) {
@@ -332,10 +343,10 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
332343
}
333344

334345
/**
335-
* @param int $blog_id
336-
* @param int $post_id
337-
* @param array $data
338-
* @return array
346+
* @param int $blog_id
347+
* @param int $post_id
348+
* @param array<string, mixed> $data
349+
* @return array<string, mixed>
339350
*/
340351
protected function update_inserted_blog_post_data( $blog_id, $post_id, array $data ) {
341352
$data['ID'] = $post_id;

includes/ContentImport/ImportCoordinates.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class ImportCoordinates {
4141
public $dest_lang;
4242

4343
/**
44-
* @var array An array keeping track of which importer (slug) should be used for
45-
* a specific import type, shape [ <import-type> => <slug> ]
44+
* @var array<string, string> An array keeping track of which importer (slug) should be used for
45+
* a specific import type, shape [ <import-type> => <slug> ]
4646
*/
4747
public $importers = array();
4848

includes/ContentImport/ImportLogger.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ImportLogger {
1010
protected string $levels_delimiter = '/';
1111

1212
/**
13-
* @var array<string, array>
13+
* @var array<string, string[]>
1414
*/
1515
protected array $data = array(
1616
'info' => array(),
@@ -41,7 +41,7 @@ public function merge( ImportLogger $logger = null ): void {
4141
}
4242

4343
/**
44-
* @return array<string, array>
44+
* @return array<string, string[]>
4545
*/
4646
public function get_data(): array {
4747
return $this->data;
@@ -106,10 +106,10 @@ protected function log( $where, $what, $root = 'info' ): void {
106106
}
107107

108108
/**
109-
* @param array $path
110-
* @param mixed $what
109+
* @param string[] $path
110+
* @param mixed $what
111111
*
112-
* @return array
112+
* @return array<string, mixed>
113113
*/
114114
protected function build_nested_array( $path, $what = '' ): array {
115115
$json = '{"'
@@ -131,7 +131,7 @@ protected function build_nested_array( $path, $what = '' ): array {
131131
/**
132132
* @param string $where
133133
*
134-
* @return array
134+
* @return string[]
135135
*/
136136
protected function build_path( string $where ): array {
137137
$where_path = explode( $this->levels_delimiter, $where );

includes/ContentImport/Importers/BaseImporter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function __construct(
4040
}
4141

4242
/**
43-
* @param array $data
43+
* @param array<string, mixed> $data
4444
*
45-
* @return array
45+
* @return array<string, mixed>
4646
*/
4747
public function import( array $data ) {
4848
return $data;

includes/ContentImport/Importers/Map.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Map extends MslsRegistryInstance {
1111
*
1212
* @param ImportCoordinates $import_coordinates
1313
*
14-
* @return array An array of importer instances in the shape [ <string: slug> => <Importer: $importer> ]
14+
* @return array<string, ImportersBaseFactory> An array of importer instances in the shape [ <string: slug> => <Importer: $importer> ]
1515
*/
1616
public function make( ImportCoordinates $import_coordinates ) {
1717
$importers = array_map(
@@ -42,7 +42,6 @@ function ( $factory ) use ( $import_coordinates ) {
4242
* Returns a filtered list of factories that will provide the importers.
4343
*
4444
* @return array<string, ImportersBaseFactory> An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
45-
* @since TBD
4645
*/
4746
public function factories() {
4847
$map = array(

includes/ContentImport/Importers/PostFields/Duplicating.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public static function info() {
3131
);
3232
}
3333

34+
/**
35+
* @param array<string, mixed> $data
36+
*
37+
* @return array<string, mixed>
38+
*/
3439
public function import( array $data ) {
3540
// Set the post type reading it from the request payload, if not possible, use the default one.
3641
$data['post_type'] = $this->read_post_type_from_request( 'post' );
@@ -54,7 +59,7 @@ public function import( array $data ) {
5459
/**
5560
* Filters the post fields that should be duplicated from the source post to the destination one.
5661
*
57-
* @return array
62+
* @return string[]
5863
*/
5964
public function filter_fields() {
6065
$fields = array(

includes/ContentImport/Importers/PostMeta/Duplicating.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function import( array $data ) {
5858
/**
5959
* Filters the post meta that should not be imported.
6060
*
61-
* @param array $meta
61+
* @param mixed[] $meta
6262
*
63-
* @return array
63+
* @return mixed[]
6464
*/
6565
public function filter_post_meta( array $meta ) {
6666
$blacklist = array( '_edit_last', '_thumbnail_id', '_edit_lock' );

includes/ContentImport/Importers/Terms/ShallowDuplicating.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ShallowDuplicating extends BaseImporter {
2020
const TYPE = 'shallow-duplicating';
2121

2222
/**
23-
* @var array
23+
* @var string[]
2424
*/
2525
protected $reset_taxonomies = array();
2626

@@ -40,6 +40,11 @@ public static function info() {
4040
);
4141
}
4242

43+
/**
44+
* @param mixed[] $data
45+
*
46+
* @return mixed[]
47+
*/
4348
public function import( array $data ) {
4449
$source_blog_id = $this->import_coordinates->source_blog_id;
4550
$source_post_id = $this->import_coordinates->source_post_id;
@@ -128,10 +133,10 @@ protected function create_local_term( \WP_Term $term, OptionsTaxInterface $msls_
128133
}
129134

130135
/**
131-
* @param array $meta
136+
* @param mixed[] $meta
132137
* @param \WP_Term $term
133138
*
134-
* @return array
139+
* @return mixed[]
135140
*/
136141
protected function filter_term_meta( array $meta, \WP_Term $term ) {
137142
/**
@@ -158,7 +163,7 @@ protected function filter_term_meta( array $meta, \WP_Term $term ) {
158163
* @param int $dest_term_id
159164
* @param string $taxonomy
160165
*
161-
* @return array|\WP_Error
166+
* @return int[]|\WP_Error
162167
*/
163168
protected function update_object_terms( $object_id, $dest_term_id, $taxonomy ) {
164169
if ( ! in_array( $taxonomy, $this->reset_taxonomies, true ) ) {

includes/MslsCli.php

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public static function init(): void {
2121
* ## EXAMPLES
2222
*
2323
* $ wp msls blog <locale>
24+
*
25+
* @param string[] $args
26+
* @param array<string, string> $assoc_args
27+
* @return void
2428
*/
2529
public function blog( $args, $assoc_args ): void {
2630
list( $locale ) = $args;

phpstan.neon.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 6
33
inferPrivatePropertyTypeFromConstructor: true
44
paths:
55
- MultisiteLanguageSwitcher.php
@@ -8,3 +8,5 @@ parameters:
88
- vendor
99
bootstrapFiles:
1010
- tests/phpstan/bootstrap.php
11+
ignoreErrors:
12+
- '/^Class lloc\\Msls\\MslsWidget extends generic class WP_Widget but does not specify its types: T$/'

0 commit comments

Comments
 (0)