Skip to content

Commit 7e4e7bc

Browse files
committed
Addressed issues raised by PHPStan
1 parent c08cb46 commit 7e4e7bc

14 files changed

+224
-122
lines changed

includes/ContentImport/ImportLogger.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
class ImportLogger {
99

10-
protected $levels_delimiter = '/';
10+
protected string $levels_delimiter = '/';
1111

12-
protected $data = array(
12+
/**
13+
* @var array<string, array>
14+
*/
15+
protected array $data = array(
1316
'info' => array(),
1417
'error' => array(),
1518
'success' => array(),
@@ -29,7 +32,7 @@ public function __construct( ImportCoordinates $import_coordinates ) {
2932
*
3033
* @param ImportLogger|null $logger
3134
*/
32-
public function merge( ImportLogger $logger = null ) {
35+
public function merge( ImportLogger $logger = null ): void {
3336
if ( null === $logger ) {
3437
return;
3538
}
@@ -38,16 +41,16 @@ public function merge( ImportLogger $logger = null ) {
3841
}
3942

4043
/**
41-
* @return array
44+
* @return array<string, array>
4245
*/
43-
public function get_data() {
46+
public function get_data(): array {
4447
return $this->data;
4548
}
4649

4750
/**
4851
* Saves the log or prints it some place.
4952
*/
50-
public function save() {
53+
public function save(): void {
5154
$log_writer = $default_log_writer = AdminNoticeLogger::instance();
5255
$log_writer->set_import_coordinates( $this->import_coordinates );
5356

@@ -82,7 +85,7 @@ public function save() {
8285
* @param string $where A location string using `/` as level format.
8386
* @param mixed $what What should be stored in the log.
8487
*/
85-
public function log_error( $where, $what ) {
88+
public function log_error( $where, $what ): void {
8689
$this->log( $where, $what, 'error' );
8790
}
8891

@@ -93,7 +96,7 @@ public function log_error( $where, $what ) {
9396
* @param mixed $what What should be stored in the log.
9497
* @param string $root Where to log the information.
9598
*/
96-
protected function log( $where, $what, $root = 'info' ) {
99+
protected function log( $where, $what, $root = 'info' ): void {
97100
if ( ! isset( $this->data[ $root ] ) ) {
98101
$this->data[ $root ] = array();
99102
}
@@ -103,7 +106,7 @@ protected function log( $where, $what, $root = 'info' ) {
103106
$this->data[ $root ] = array_merge_recursive( $this->data[ $root ], $data );
104107
}
105108

106-
protected function build_nested_array( $path, $what = '' ) {
109+
protected function build_nested_array( $path, $what = '' ): array {
107110
$json = '{"'
108111
. implode( '":{"', $path )
109112
. '":' . wp_json_encode( $what )
@@ -125,7 +128,7 @@ protected function build_nested_array( $path, $what = '' ) {
125128
*
126129
* @return array
127130
*/
128-
protected function build_path( $where ) {
131+
protected function build_path( $where ): array {
129132
$where_path = explode( $this->levels_delimiter, $where );
130133

131134
return $where_path;
@@ -136,7 +139,7 @@ protected function build_path( $where ) {
136139
*
137140
* @return string
138141
*/
139-
public function get_levels_delimiter() {
142+
public function get_levels_delimiter(): string {
140143
return $this->levels_delimiter;
141144
}
142145

@@ -145,7 +148,7 @@ public function get_levels_delimiter() {
145148
*
146149
* @param string $levels_delimiter
147150
*/
148-
public function set_levels_delimiter( $levels_delimiter ) {
151+
public function set_levels_delimiter( $levels_delimiter ): void {
149152
$this->levels_delimiter = $levels_delimiter;
150153
}
151154

@@ -155,7 +158,7 @@ public function set_levels_delimiter( $levels_delimiter ) {
155158
* @param string $where A location string using `/` as level format.
156159
* @param mixed $what What should be stored in the log.
157160
*/
158-
public function log_success( $where, $what ) {
161+
public function log_success( $where, $what ): void {
159162
$this->log( $where, $what, 'success' );
160163
}
161164

@@ -164,16 +167,21 @@ public function log_success( $where, $what ) {
164167
*
165168
* @param string $message
166169
*/
167-
public function log_information( $key, $message ) {
170+
public function log_information( $key, $message ): void {
168171
$this->data['info'][ $key ] = $message;
169172
}
170173

174+
/**
175+
* @param string $where
176+
*
177+
* @return mixed
178+
*/
171179
public function get_error( $where ) {
172180
return $this->get_nested_value( 'error' . $this->levels_delimiter . $where );
173181
}
174182

175183
/**
176-
* @param $where
184+
* @param string $where
177185
*
178186
* @return mixed
179187
*/
@@ -189,10 +197,20 @@ protected function get_nested_value( $where ) {
189197
return $data;
190198
}
191199

200+
/**
201+
* @param string $where
202+
*
203+
* @return mixed
204+
*/
192205
public function get_success( $where ) {
193206
return $this->get_nested_value( 'success' . $this->levels_delimiter . $where );
194207
}
195208

209+
/**
210+
* @param string $key
211+
*
212+
* @return mixed
213+
*/
196214
public function get_information( $key ) {
197215
return isset( $this->data['info'][ $key ] ) ? $this->data['info'][ $key ] : '';
198216
}

includes/ContentImport/Importers/AttachmentsImporters.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ class AttachmentsImporters extends ImportersBaseFactory {
88

99
const TYPE = 'attachments';
1010

11-
protected $importers_map = [
11+
/**
12+
* @var array<string, string>
13+
*/
14+
protected array $importers_map = array(
1215
Linking::TYPE => Linking::class,
13-
];
16+
);
1417

1518
/**
1619
* Returns the factory details.
1720
*
18-
* @return string
21+
* @return \stdClass
1922
*/
2023
public function details() {
21-
return (object) [
24+
return (object) array(
2225
'slug' => static::TYPE,
2326
'name' => __( 'Image Attachments', 'multisite-language-switcher' ),
2427
'importers' => $this->importers_info(),
2528
'selected' => $this->selected(),
26-
];
29+
);
2730
}
2831
}

includes/ContentImport/Importers/ImportersBaseFactory.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ abstract class ImportersBaseFactory extends MslsRegistryInstance implements Impo
1313
const TYPE = 'none';
1414

1515
/**
16-
* @var array An array defining the slug and Importer class relationships in
16+
* @var array<string, string> An array defining the slug and Importer class relationships in
1717
* the shape [ <slug> => <importer-class> ]
1818
*/
19-
protected $importers_map = [];
19+
protected array $importers_map = array();
2020

2121
/**
2222
* @return Importer
@@ -49,7 +49,6 @@ public function make( ImportCoordinates $import_coordinates ) {
4949
* @param ImportCoordinates $import_coordinates
5050
*
5151
* @since TBD
52-
*
5352
*/
5453
$map = apply_filters( "msls_content_import_{$type}_importers_map", $this->importers_map, $import_coordinates );
5554

@@ -70,10 +69,10 @@ public function make( ImportCoordinates $import_coordinates ) {
7069
* @return \stdClass
7170
*/
7271
public function details() {
73-
return (object) [
72+
return (object) array(
7473
'name' => 'Base Factory',
75-
'importers' => [],
76-
];
74+
'importers' => array(),
75+
);
7776
}
7877

7978
/**
@@ -90,9 +89,6 @@ public function selected() {
9089
*
9190
* @param string $selected The selected importer slug.
9291
* @param ImportersFactory $this
93-
*
94-
* @since TBD
95-
*
9692
*/
9793
$selected = apply_filters( "msls_content_import_{$slug}_selected", $selected, $this );
9894

@@ -102,9 +98,12 @@ public function selected() {
10298
protected function importers_info() {
10399
return array_combine(
104100
array_keys( $this->importers_map ),
105-
array_map( function ( $importer_class ) {
106-
return $importer_class::info();
107-
}, $this->importers_map )
101+
array_map(
102+
function ( $importer_class ) {
103+
return $importer_class::info();
104+
},
105+
$this->importers_map
106+
)
108107
);
109108
}
110-
}
109+
}

includes/ContentImport/Importers/ImportersFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function make( ImportCoordinates $import_coordinates );
1818
/**
1919
* Returns the factory details.
2020
*
21-
* @return string
21+
* @return \stdClass
2222
*/
2323
public function details();
2424

@@ -28,4 +28,4 @@ public function details();
2828
* @return string
2929
*/
3030
public function selected();
31-
}
31+
}

includes/ContentImport/Importers/PostFieldsImporters.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ class PostFieldsImporters extends ImportersBaseFactory {
88

99
const TYPE = 'post-fields';
1010

11-
protected $importers_map = [
11+
/**
12+
* @var array<string, string>
13+
*/
14+
protected array $importers_map = array(
1215
Duplicating::TYPE => Duplicating::class,
13-
];
16+
);
1417

1518
/**
1619
* Returns the factory details.
1720
*
18-
* @return string
21+
* @return \stdClass
1922
*/
2023
public function details() {
21-
return (object) [
24+
return (object) array(
2225
'slug' => static::TYPE,
2326
'name' => __( 'Post Fields', 'multisite-language-switcher' ),
2427
'importers' => $this->importers_info(),
2528
'selected' => $this->selected(),
26-
];
29+
);
2730
}
2831
}

includes/ContentImport/Importers/PostMeta/Duplicating.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace lloc\Msls\ContentImport\Importers\PostMeta;
44

5+
use lloc\Msls\ContentImport\ImportCoordinates;
56
use lloc\Msls\ContentImport\Importers\BaseImporter;
67

78
class Duplicating extends BaseImporter {
@@ -14,11 +15,11 @@ class Duplicating extends BaseImporter {
1415
* @return \stdClass
1516
*/
1617
public static function info() {
17-
return (object) [
18-
'slug' => static::TYPE,
19-
'name' => __( 'Duplicating', 'multisite-language-switcher' ),
20-
'description' => __( 'Copies the source post meta to the destination.', 'multisite-language-switcher' )
21-
];
18+
return (object) array(
19+
'slug' => static::TYPE,
20+
'name' => __( 'Duplicating', 'multisite-language-switcher' ),
21+
'description' => __( 'Copies the source post meta to the destination.', 'multisite-language-switcher' ),
22+
);
2223
}
2324

2425
public function import( array $data ) {
@@ -49,6 +50,13 @@ public function import( array $data ) {
4950
return $data;
5051
}
5152

53+
/**
54+
* Filters the post meta that should not be imported.
55+
*
56+
* @param array $meta
57+
*
58+
* @return array
59+
*/
5260
public function filter_post_meta( array $meta ) {
5361
$blacklist = array( '_edit_last', '_thumbnail_id', '_edit_lock' );
5462

@@ -59,11 +67,13 @@ public function filter_post_meta( array $meta ) {
5967
* @param array $meta
6068
* @param ImportCoordinates $import_coordinates
6169
*/
62-
$blacklist = apply_filters( 'msls_content_import_post_meta_blacklist',
70+
$blacklist = apply_filters(
71+
'msls_content_import_post_meta_blacklist',
6372
$blacklist,
6473
$meta,
65-
$this->import_coordinates );
74+
$this->import_coordinates
75+
);
6676

6777
return array_diff_key( $meta, array_combine( $blacklist, $blacklist ) );
6878
}
69-
}
79+
}

includes/ContentImport/Importers/PostMetaImporters.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ class PostMetaImporters extends ImportersBaseFactory {
88

99
const TYPE = 'post-meta';
1010

11-
protected $importers_map = [
11+
/**
12+
* @var array<string, string>
13+
*/
14+
protected array $importers_map = array(
1215
Duplicating::TYPE => Duplicating::class,
13-
];
16+
);
1417

1518
/**
1619
* Returns the factory details.
1720
*
18-
* @return string
21+
* @return \stdClass
1922
*/
2023
public function details() {
21-
return (object) [
24+
return (object) array(
2225
'slug' => static::TYPE,
2326
'name' => __( 'Meta Fields', 'multisite-language-switcher' ),
2427
'importers' => $this->importers_info(),
2528
'selected' => $this->selected(),
26-
];
29+
);
2730
}
2831
}

0 commit comments

Comments
 (0)