Skip to content

Commit 4899d23

Browse files
committed
Fix PHPStan issues
1 parent 9d612d4 commit 4899d23

File tree

12 files changed

+47
-29
lines changed

12 files changed

+47
-29
lines changed

classes/admin/class-page-settings.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,28 @@ public function add_admin_page_content() {
5858
public function get_settings() {
5959
$settings = [];
6060
foreach ( \progress_planner()->get_page_types()->get_page_types() as $page_type ) {
61-
if ( ! $this->should_show_setting( $page_type['slug'] ) ) {
61+
$slug = (string) $page_type['slug']; // @phpstan-ignore offsetAccess.invalidOffset
62+
if ( ! $this->should_show_setting( $slug ) ) {
6263
continue;
6364
}
6465

65-
$settings[ $page_type['slug'] ] = [
66-
'id' => $page_type['slug'],
66+
$settings[ $slug ] = [
67+
'id' => $slug,
6768
'value' => '_no_page_needed',
6869
'isset' => 'no',
69-
'title' => $page_type['title'],
70-
'description' => $page_type['description'] ?? '',
70+
'title' => $page_type['title'], // @phpstan-ignore offsetAccess.invalidOffset
71+
'description' => $page_type['description'] ?? '', // @phpstan-ignore offsetAccess.invalidOffset
7172
'type' => 'page-select',
72-
'page' => $page_type['slug'],
73+
'page' => $slug,
7374
];
7475

75-
if ( \progress_planner()->get_page_types()->is_page_needed( $page_type['slug'] ) ) {
76-
$type_pages = \progress_planner()->get_page_types()->get_posts_by_type( 'any', $page_type['slug'] );
76+
if ( \progress_planner()->get_page_types()->is_page_needed( $slug ) ) {
77+
$type_pages = \progress_planner()->get_page_types()->get_posts_by_type( 'any', $slug );
7778
if ( empty( $type_pages ) ) {
78-
$settings[ $page_type['slug'] ]['value'] = \progress_planner()->get_page_types()->get_default_page_id_by_type( $page_type['slug'] );
79+
$settings[ $slug ]['value'] = \progress_planner()->get_page_types()->get_default_page_id_by_type( $slug );
7980
} else {
80-
$settings[ $page_type['slug'] ]['value'] = $type_pages[0]->ID;
81-
$settings[ $page_type['slug'] ]['isset'] = 'yes';
81+
$settings[ $slug ]['value'] = $type_pages[0]->ID;
82+
$settings[ $slug ]['isset'] = 'yes';
8283

8384
// If there is more than one page, we need to check if the page has a parent with the same page-type assigned.
8485
if ( 1 < \count( $type_pages ) ) {
@@ -89,7 +90,7 @@ public function get_settings() {
8990
foreach ( $type_pages as $type_page ) {
9091
$parent = \get_post_field( 'post_parent', $type_page->ID );
9192
if ( $parent && \in_array( (int) $parent, $type_pages_ids, true ) ) {
92-
$settings[ $page_type['slug'] ]['value'] = $parent;
93+
$settings[ $slug ]['value'] = $parent;
9394
break;
9495
}
9596
}

classes/admin/widgets/class-activity-scores.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public function get_checklist_results() {
9898
$items = $this->get_checklist();
9999
$results = [];
100100
foreach ( $items as $item ) {
101-
$results[ $item['label'] ] = $item['callback']();
101+
$label = (string) $item['label']; // @phpstan-ignore offsetAccess.invalidOffset
102+
$results[ $label ] = $item['callback'](); // @phpstan-ignore offsetAccess.invalidOffset
102103
}
103104
return $results;
104105
}

classes/class-base.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ class Base {
8686
*/
8787
public function init() {
8888
if ( ! \function_exists( 'current_user_can' ) ) {
89-
require_once ABSPATH . 'wp-includes/capabilities.php'; // @phpstan-ignore requireOnce.fileNotFound
89+
// @phpstan-ignore-next-line requireOnce.fileNotFound
90+
require_once ABSPATH . 'wp-includes/capabilities.php';
9091
}
9192
if ( ! \function_exists( 'wp_get_current_user' ) ) {
92-
require_once ABSPATH . 'wp-includes/pluggable.php'; // @phpstan-ignore requireOnce.fileNotFound
93+
// @phpstan-ignore-next-line requireOnce.fileNotFound
94+
require_once ABSPATH . 'wp-includes/pluggable.php';
9395
}
9496

9597
if ( \defined( '\IS_PLAYGROUND_PREVIEW' ) && \constant( '\IS_PLAYGROUND_PREVIEW' ) === true ) {
@@ -421,7 +423,8 @@ public function get_file_version( $file ) {
421423

422424
// Otherwise, use the plugin header.
423425
if ( ! \function_exists( 'get_file_data' ) ) {
424-
require_once ABSPATH . 'wp-includes/functions.php'; // @phpstan-ignore requireOnce.fileNotFound
426+
// @phpstan-ignore-next-line requireOnce.fileNotFound
427+
require_once ABSPATH . 'wp-includes/functions.php';
425428
}
426429

427430
if ( ! self::$plugin_version ) {

classes/class-suggested-tasks.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,9 @@ public function rest_api_tax_query( $args, $request ) {
479479

480480
// Handle sorting parameters.
481481
if ( isset( $request['filter']['orderby'] ) ) {
482-
$args['orderby'] = \sanitize_sql_orderby( $request['filter']['orderby'] );
482+
// @phpstan-ignore-next-line argument.templateType
483+
$orderby = \sanitize_sql_orderby( $request['filter']['orderby'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
484+
$args['orderby'] = $orderby !== false ? $orderby : 'date';
483485
}
484486
if ( isset( $request['filter']['order'] ) ) {
485487
$args['order'] = \in_array( \strtoupper( $request['filter']['order'] ), [ 'ASC', 'DESC' ], true )

classes/suggested-tasks/class-task.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ public function get_rest_formatted_data( $post_id = null ): array {
200200

201201
// Make sure WP_REST_Posts_Controller is loaded.
202202
if ( ! \class_exists( 'WP_REST_Posts_Controller' ) ) {
203-
require_once ABSPATH . 'wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php'; // @phpstan-ignore requireOnce.fileNotFound
203+
// @phpstan-ignore-next-line requireOnce.fileNotFound
204+
require_once ABSPATH . 'wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php';
204205
}
205206

206207
// Make sure WP_REST_Request is loaded.
207208
if ( ! \class_exists( 'WP_REST_Request' ) ) {
208-
require_once ABSPATH . 'wp-includes/rest-api/class-wp-rest-request.php'; // @phpstan-ignore requireOnce.fileNotFound
209+
// @phpstan-ignore-next-line requireOnce.fileNotFound
210+
require_once ABSPATH . 'wp-includes/rest-api/class-wp-rest-request.php';
209211
}
210212

211213
// Use the appropriate controller for the post type.

classes/suggested-tasks/data-collector/class-inactive-plugins.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function update_inactive_plugins_cache() {
4747
*/
4848
protected function calculate_data() {
4949
if ( ! \function_exists( 'get_plugins' ) ) {
50-
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore requireOnce.fileNotFound
50+
// @phpstan-ignore-next-line requireOnce.fileNotFound
51+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
5152
}
5253

5354
// Clear the plugins cache, so get_plugins() returns the latest plugins.

classes/suggested-tasks/providers/class-core-update.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function add_core_update_link( $update_actions ) {
107107
public function should_add_task() {
108108
// Without this \wp_get_update_data() might not return correct data for the core updates (depending on the timing).
109109
if ( ! \function_exists( 'get_core_updates' ) ) {
110-
require_once ABSPATH . 'wp-admin/includes/update.php'; // @phpstan-ignore requireOnce.fileNotFound
110+
// @phpstan-ignore-next-line requireOnce.fileNotFound
111+
require_once ABSPATH . 'wp-admin/includes/update.php';
111112
}
112113

113114
// For wp_get_update_data() to return correct data it needs to be called after the 'admin_init' action (with priority 10).

classes/suggested-tasks/providers/class-fewer-tags.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public function is_task_completed( $task_id = '' ) {
154154
protected function is_plugin_active() {
155155
if ( null === $this->is_plugin_active ) {
156156
if ( ! \function_exists( 'get_plugins' ) ) {
157-
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore requireOnce.fileNotFound
157+
// @phpstan-ignore-next-line requireOnce.fileNotFound
158+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
158159
}
159160

160161
$plugins = \get_plugins();

classes/suggested-tasks/providers/class-select-locale.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public function print_popover_instructions() {
205205
public function print_popover_form_contents() {
206206

207207
if ( ! \function_exists( 'wp_get_available_translations' ) ) {
208-
require_once ABSPATH . 'wp-admin/includes/translation-install.php'; // @phpstan-ignore requireOnce.fileNotFound
208+
// @phpstan-ignore-next-line requireOnce.fileNotFound
209+
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
209210
}
210211

211212
$languages = \get_available_languages();
@@ -277,7 +278,8 @@ public function handle_interactive_task_specific_submit() {
277278

278279
// Handle translation installation.
279280
if ( \current_user_can( 'install_languages' ) ) {
280-
require_once ABSPATH . 'wp-admin/includes/translation-install.php'; // @phpstan-ignore requireOnce.fileNotFound
281+
// @phpstan-ignore-next-line requireOnce.fileNotFound
282+
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
281283

282284
if ( \wp_can_install_language_pack() ) {
283285
$language = \wp_download_language_pack( $language_for_update );

classes/ui/class-chart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public function get_chart_data( $args = [] ) {
125125
$previous_period_activities = $period_data['previous_period_activities'];
126126
$period_data_filtered = [];
127127
foreach ( $args['return_data'] as $key ) {
128-
$period_data_filtered[ $key ] = $period_data[ $key ];
128+
$key_string = (string) $key; // @phpstan-ignore offsetAccess.invalidOffset
129+
$period_data_filtered[ $key_string ] = $period_data[ $key_string ]; // @phpstan-ignore offsetAccess.invalidOffset
129130
}
130131
$data[] = $period_data_filtered;
131132
}

0 commit comments

Comments
 (0)