Skip to content

Commit 47de47f

Browse files
committed
Increase PHPStan checks to level 9
1 parent d70d626 commit 47de47f

52 files changed

Lines changed: 178 additions & 141 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

classes/actions/class-content-scan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function update_stats() {
105105
// Calculate the total pages to scan.
106106
$total_pages = $this->get_total_pages();
107107
// Get the last scanned page.
108-
$last_page = (int) \progress_planner()->get_settings()->get( static::LAST_SCANNED_PAGE_OPTION, 0 );
108+
$last_page = (int) \progress_planner()->get_settings()->get( static::LAST_SCANNED_PAGE_OPTION, 0 ); // @phpstan-ignore-line cast.int
109109
// The current page to scan.
110110
$current_page = $last_page + 1;
111111

classes/activities/class-content-helpers.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ public function get_post_types_names() {
2626
}
2727
$default = [ 'post', 'page' ];
2828
$include_post_types = \array_filter(
29-
\progress_planner()->get_settings()->get( [ 'include_post_types' ], $default ),
29+
(array) \progress_planner()->get_settings()->get( [ 'include_post_types' ], $default ),
3030
function ( $post_type ) {
31-
return $post_type && \post_type_exists( $post_type ) && \is_post_type_viewable( $post_type );
31+
return $post_type
32+
&& \is_string( $post_type )
33+
&& \post_type_exists( $post_type )
34+
&& \is_post_type_viewable( $post_type );
3235
}
3336
);
3437
return empty( $include_post_types ) ? $default : \array_values( $include_post_types );

classes/activities/class-query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ protected function get_activity_class_name( $category ) {
450450
* @return void
451451
*/
452452
private function maybe_upgrade() {
453-
$db_version = (int) \get_option( 'progress_planner_db_version', 0 );
453+
$db_version = (int) \get_option( 'progress_planner_db_version', 0 ); // @phpstan-ignore-line cast.int
454454
$available_upgrades = [];
455455
// Get an array of methods that are prefixed with "upgrade_".
456456
$methods = \get_class_methods( $this );

classes/admin/class-editor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function enqueue_editor_script() {
2828
// Bail early when we're on the site-editor.php page.
2929
$request = \filter_input( INPUT_SERVER, 'REQUEST_URI' );
3030
if ( ! $request && isset( $_SERVER['REQUEST_URI'] ) ) {
31-
$request = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) );
31+
$request = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) ); // @phpstan-ignore-line argument.type
3232
}
3333
if ( $request && \str_contains( $request, 'site-editor.php' ) ) {
3434
return;
@@ -38,7 +38,7 @@ public function enqueue_editor_script() {
3838

3939
// Check if the page-type is set in the URL (user is coming from the Settings page).
4040
if ( isset( $_GET['prpl_page_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
41-
$prpl_pt = \sanitize_text_field( \wp_unslash( $_GET['prpl_page_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
41+
$prpl_pt = \sanitize_text_field( \wp_unslash( $_GET['prpl_page_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, @phpstan-ignore-line argument.type
4242

4343
foreach ( $page_types as $page_type ) {
4444
if ( $page_type['slug'] === $prpl_pt ) {

classes/admin/class-page-settings.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ public function store_settings_form_options() {
132132
\check_admin_referer( 'progress_planner' );
133133

134134
if ( isset( $_POST['pages'] ) ) {
135-
foreach ( \wp_unslash( $_POST['pages'] ) as $type => $page_args ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
136-
137-
$need_page = \sanitize_text_field( \wp_unslash( $page_args['have_page'] ) );
135+
$pages = (array) \wp_unslash( $_POST['pages'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
136+
foreach ( $pages as $type => $page_args ) {
137+
$page_args = (array) $page_args;
138+
$need_page = isset( $page_args['have_page'] )
139+
? \sanitize_text_field( \wp_unslash( $page_args['have_page'] ) ) // @phpstan-ignore-line argument.type
140+
: 'not-applicable';
138141

139142
\progress_planner()->get_page_types()->set_no_page_needed(
140143
$type,
@@ -165,7 +168,7 @@ public function store_settings_form_options() {
165168

166169
if ( 'no' !== $page_args['have_page'] ) {
167170
// Add the term to the `progress_planner_page_types` taxonomy.
168-
\progress_planner()->get_page_types()->set_page_type_by_id( (int) $page_args['id'], $type );
171+
\progress_planner()->get_page_types()->set_page_type_by_id( (int) $page_args['id'], $type ); // @phpstan-ignore-line cast.int
169172
}
170173
}
171174
}
@@ -188,7 +191,7 @@ public function save_settings() {
188191
\check_admin_referer( 'progress_planner' );
189192

190193
$redirect_on_login = isset( $_POST['prpl-redirect-on-login'] )
191-
? \sanitize_text_field( \wp_unslash( $_POST['prpl-redirect-on-login'] ) )
194+
? \sanitize_text_field( \wp_unslash( $_POST['prpl-redirect-on-login'] ) ) // @phpstan-ignore-line argument.type
192195
: false;
193196

194197
\update_user_meta( \get_current_user_id(), 'prpl_redirect_on_login', (bool) $redirect_on_login );
@@ -204,7 +207,7 @@ public function save_post_types() {
204207
\check_admin_referer( 'progress_planner' );
205208

206209
$include_post_types = isset( $_POST['prpl-post-types-include'] )
207-
? \array_map( 'sanitize_text_field', \wp_unslash( $_POST['prpl-post-types-include'] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
210+
? \array_map( 'sanitize_text_field', \wp_unslash( $_POST['prpl-post-types-include'] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized @phpstan-ignore-line argument.type
208211
// If no post types are selected, use the default post types (post and page can be deregistered).
209212
: \array_intersect( [ 'post', 'page' ], \progress_planner()->get_settings()->get_public_post_types() );
210213

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function personal_record_callback() {
184184
'priority' => 'low',
185185
'evaluate' => function ( $goal_object ) {
186186
// Get the cached activities.
187-
$cached_activities = \progress_planner()->get_settings()->get( $this->cache_key, [] );
187+
$cached_activities = (array) \progress_planner()->get_settings()->get( $this->cache_key, [] );
188188

189189
// Get the weekly cache key.
190190
$weekly_cache_key = $goal_object->get_details()['start_date']->format( 'Y-m-d' ) . '_' . $goal_object->get_details()['end_date']->format( 'Y-m-d' );

classes/admin/widgets/class-challenge.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function get_challenge() {
3434
'feed' => [],
3535
'expires' => 0,
3636
];
37+
} else {
38+
$feed_data = (array) $feed_data;
3739
}
3840

3941
// Transient expired, fetch new feed.

classes/admin/widgets/class-whats-new.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ final class Whats_New extends Widget {
3636
public function get_blog_feed() {
3737
$feed_data = \progress_planner()->get_utils__cache()->get( self::CACHE_KEY );
3838

39-
// Migrate old feed to new format.
40-
if ( \is_array( $feed_data ) && ! isset( $feed_data['expires'] ) && ! isset( $feed_data['feed'] ) ) {
41-
$feed_data = [
42-
'feed' => $feed_data,
43-
'expires' => \get_option( '_transient_timeout_' . Cache::CACHE_PREFIX . self::CACHE_KEY, 0 ),
44-
];
45-
}
46-
4739
// Transient not set.
4840
if ( false === $feed_data ) {
4941
$feed_data = [
5042
'feed' => [],
5143
'expires' => 0,
5244
];
45+
} elseif ( \is_array( $feed_data ) && ! isset( $feed_data['expires'] ) && ! isset( $feed_data['feed'] ) ) {
46+
// Migrate old feed to new format.
47+
$feed_data = [
48+
'feed' => $feed_data,
49+
'expires' => \get_option( '_transient_timeout_' . Cache::CACHE_PREFIX . self::CACHE_KEY, 0 ),
50+
];
51+
} else {
52+
$feed_data = (array) $feed_data;
5353
}
5454

5555
// Transient expired, fetch new feed.
@@ -61,11 +61,15 @@ public function get_blog_feed() {
6161
// If we cant fetch the feed, we will try again later.
6262
$feed_data['expires'] = \time() + 5 * MINUTE_IN_SECONDS;
6363
} else {
64-
$feed = \json_decode( \wp_remote_retrieve_body( $response ), true );
64+
$feed = (array) \json_decode( \wp_remote_retrieve_body( $response ), true );
6565

6666
foreach ( $feed as $key => $post ) {
67+
if ( ! \is_array( $post ) ) {
68+
continue;
69+
}
70+
6771
// Get the featured media.
68-
$featured_media_id = $post['featured_media'];
72+
$featured_media_id = (int) $post['featured_media']; // @phpstan-ignore-line cast.int
6973
if ( $featured_media_id ) {
7074
$response = \wp_remote_get( \progress_planner()->get_remote_server_root_url() . '/wp-json/wp/v2/media/' . $featured_media_id );
7175
if ( ! \is_wp_error( $response ) ) {

classes/admin/widgets/class-widget.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function get_range() {
6161
// phpcs:ignore WordPress.Security.NonceVerification
6262
return isset( $_GET['range'] )
6363
// phpcs:ignore WordPress.Security.NonceVerification
64-
? \sanitize_text_field( \wp_unslash( $_GET['range'] ) )
64+
? \sanitize_text_field( \wp_unslash( $_GET['range'] ) ) // @phpstan-ignore-line argument.type
6565
: '-6 months';
6666
}
6767

@@ -74,7 +74,7 @@ public function get_frequency() {
7474
// phpcs:ignore WordPress.Security.NonceVerification
7575
return isset( $_GET['frequency'] )
7676
// phpcs:ignore WordPress.Security.NonceVerification
77-
? \sanitize_text_field( \wp_unslash( $_GET['frequency'] ) )
77+
? \sanitize_text_field( \wp_unslash( $_GET['frequency'] ) ) // @phpstan-ignore-line argument.type
7878
: 'monthly';
7979
}
8080

classes/badges/class-badge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract public function progress_callback( $args = [] );
7171
* @return array
7272
*/
7373
protected function get_saved() {
74-
return \progress_planner()->get_settings()->get( [ 'badges', $this->id ], [] );
74+
return (array) \progress_planner()->get_settings()->get( [ 'badges', $this->id ], [] );
7575
}
7676

7777
/**

0 commit comments

Comments
 (0)