Skip to content

Commit 6d68d6e

Browse files
committed
Plugin Check review
1 parent 95dc3d1 commit 6d68d6e

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

includes/ContentImport/ContentImporter.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function set_relations( $relations ) {
8888
*
8989
* @return array The updated, if needed, data array.
9090
*/
91-
public function handle_import( array $data = [] ) {
91+
public function handle_import( array $data = array() ) {
9292
if ( ! $this->pre_flight_check() || false === $sources = $this->parse_sources() ) {
9393
return $data;
9494
}
@@ -144,7 +144,7 @@ public function handle_import( array $data = [] ) {
144144
*
145145
* @return bool
146146
*/
147-
protected function pre_flight_check( array $data = [] ) {
147+
protected function pre_flight_check( array $data = array() ) {
148148
if ( ! $this->handle ) {
149149
return false;
150150
}
@@ -194,15 +194,15 @@ protected function get_the_blog_post_ID( $blog_id ) {
194194
return (int) $_REQUEST['post'];
195195
}
196196

197-
$data = [
197+
$data = array(
198198
'post_type' => $this->read_post_type_from_request( 'post' ),
199-
'post_title' => 'MSLS Content Import Draft - ' . date( 'Y-m-d H:i:s' )
200-
];
199+
'post_title' => 'MSLS Content Import Draft - ' . ( new \DateTimeImmutable() )->format( 'Y-m-d H:i:s' ),
200+
);
201201

202202
return $this->insert_blog_post( $blog_id, $data );
203203
}
204204

205-
protected function insert_blog_post( $blog_id, array $data = [] ) {
205+
protected function insert_blog_post( $blog_id, array $data = array() ) {
206206
if ( empty( $data ) ) {
207207
return false;
208208
}
@@ -239,13 +239,13 @@ public function handle( $handle ) {
239239
* Imports content according to the provided coordinates.
240240
*
241241
* @param ImportCoordinates $import_coordinates
242-
* @param array $post_fields An optional array of post fields; this can be
243-
* left empty if the method is not called as a consequence
244-
* of filtering the `wp_insert_post_data` filter.
242+
* @param array $post_fields An optional array of post fields; this can be
243+
* left empty if the method is not called as a consequence
244+
* of filtering the `wp_insert_post_data` filter.
245245
*
246246
* @return array An array of modified post fields.
247247
*/
248-
public function import_content( ImportCoordinates $import_coordinates, array $post_fields = [] ) {
248+
public function import_content( ImportCoordinates $import_coordinates, array $post_fields = array() ) {
249249
if ( ! $import_coordinates->validate() ) {
250250
return $post_fields;
251251
}
@@ -264,7 +264,6 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
264264
* @param ImportCoordinates $import_coordinates
265265
*
266266
* @since TBD
267-
*
268267
*/
269268
$post_fields = apply_filters( 'msls_content_import_data_before_import', $post_fields, $import_coordinates );
270269

@@ -311,7 +310,6 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
311310
* @param Relations $relations
312311
*
313312
* @since TBD
314-
*
315313
*/
316314
do_action( 'msls_content_import_after_import', $import_coordinates, $this->logger, $this->relations );
317315

@@ -323,16 +321,18 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
323321
* @param ImportLogger $logger
324322
* @param Relations $relations
325323
*/
326-
return apply_filters( 'msls_content_import_data_after_import',
324+
return apply_filters(
325+
'msls_content_import_data_after_import',
327326
$post_fields,
328327
$import_coordinates,
329328
$this->logger,
330-
$this->relations );
329+
$this->relations
330+
);
331331
}
332332

333333
/**
334334
* @param array $data
335-
* @param int $post_id
335+
* @param int $post_id
336336
*
337337
* @return array
338338
*/

includes/ContentImport/ImportLogger.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
namespace lloc\Msls\ContentImport;
44

5-
65
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
76
use lloc\Msls\ContentImport\LogWriters\LogWriter;
87

98
class ImportLogger {
109

1110
protected $levels_delimiter = '/';
1211

13-
protected $data = [
14-
'info' => [],
15-
'error' => [],
16-
'success' => [],
17-
];
12+
protected $data = array(
13+
'info' => array(),
14+
'error' => array(),
15+
'success' => array(),
16+
);
1817

1918
/**
2019
* @var ImportCoordinates
@@ -66,7 +65,7 @@ public function save() {
6665
}
6766

6867
if ( is_string( $log_writer ) ) {
69-
$log_writer = new $log_writer;
68+
$log_writer = new $log_writer();
7069
}
7170

7271
if ( ! $log_writer instanceof LogWriter ) {
@@ -81,7 +80,7 @@ public function save() {
8180
* Logs an error.
8281
*
8382
* @param string $where A location string using `/` as level format.
84-
* @param mixed $what What should be stored in the log.
83+
* @param mixed $what What should be stored in the log.
8584
*/
8685
public function log_error( $where, $what ) {
8786
$this->log( $where, $what, 'error' );
@@ -91,30 +90,31 @@ public function log_error( $where, $what ) {
9190
* Logs something.
9291
*
9392
* @param string $where A location string using `/` as level format.
94-
* @param mixed $what What should be stored in the log.
93+
* @param mixed $what What should be stored in the log.
9594
* @param string $root Where to log the information.
9695
*/
9796
protected function log( $where, $what, $root = 'info' ) {
9897
if ( ! isset( $this->data[ $root ] ) ) {
99-
$this->data[ $root ] = [];
98+
$this->data[ $root ] = array();
10099
}
101100

102101
$data = $this->build_nested_array( $this->build_path( $where ), $what );
103102

104-
105103
$this->data[ $root ] = array_merge_recursive( $this->data[ $root ], $data );
106104
}
107105

108106
protected function build_nested_array( $path, $what = '' ) {
109107
$json = '{"'
110-
. implode( '":{"', $path )
111-
. '":' . json_encode( $what )
112-
. implode(
113-
'',
114-
array_fill( 0,
115-
count( $path ),
116-
'}' )
117-
);
108+
. implode( '":{"', $path )
109+
. '":' . wp_json_encode( $what )
110+
. implode(
111+
'',
112+
array_fill(
113+
0,
114+
count( $path ),
115+
'}'
116+
)
117+
);
118118
$data = json_decode( $json, true );
119119

120120
return $data;
@@ -153,7 +153,7 @@ public function set_levels_delimiter( $levels_delimiter ) {
153153
* Logs a success.
154154
*
155155
* @param string $where A location string using `/` as level format.
156-
* @param mixed $what What should be stored in the log.
156+
* @param mixed $what What should be stored in the log.
157157
*/
158158
public function log_success( $where, $what ) {
159159
$this->log( $where, $what, 'success' );
@@ -196,4 +196,4 @@ public function get_success( $where ) {
196196
public function get_information( $key ) {
197197
return isset( $this->data['info'][ $key ] ) ? $this->data['info'][ $key ] : '';
198198
}
199-
}
199+
}

includes/MslsJson.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function add( $value, $label ) {
3737
/**
3838
* Compare the item with the key "label" of the array $a and the array $b
3939
*
40-
* @param array $a
41-
* @param array $b
40+
* @param array<string, string> $a
41+
* @param array<string, string> $b
4242
*
4343
* @return int
4444
*/
@@ -65,7 +65,7 @@ public function get(): array {
6565
* @return string
6666
*/
6767
public function encode(): string {
68-
return json_encode( $this->get() );
68+
return wp_json_encode( $this->get() );
6969
}
7070

7171
/**

includes/MslsWidget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function update( $new_instance, $old_instance ) {
8383
$instance = $old_instance;
8484

8585
if ( isset( $new_instance['title'] ) ) {
86-
$instance['title'] = strip_tags( $new_instance['title'] );
86+
$instance['title'] = wp_strip_all_tags( $new_instance['title'] );
8787
}
8888

8989
return $instance;

tests/phpunit/TestMslsWidget.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function test_widget(): void {
4040
}
4141

4242
public function test_update(): void {
43+
Functions\expect( 'wp_strip_all_tags' )->twice()->andReturnFirstArg();
44+
4345
$result = $this->test->update( array(), array() );
4446
$this->assertEquals( array(), $result );
4547

0 commit comments

Comments
 (0)