Skip to content

Commit 9bcf528

Browse files
committed
property.nonObject & parameter.phpDocType
1 parent a95278d commit 9bcf528

36 files changed

Lines changed: 127 additions & 156 deletions

classes/actions/class-content.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,7 @@ private function is_there_recent_activity( $post, $type ) {
207207
}
208208

209209
// Check if there is an activity for this post.
210-
$existing = \progress_planner()->get_activities__query()->query_activities(
211-
$query_args,
212-
'RAW'
213-
);
210+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw( $query_args );
214211

215212
// If there is an activity for this post, bail.
216213
return ! empty( $existing ) ? true : false;
@@ -228,13 +225,12 @@ private function add_post_activity( $post, $type ) {
228225
// Post was updated to publish for the first time, ie draft was published.
229226
if ( 'update' === $type && 'publish' === $post->post_status ) {
230227
// Check if there is a publish activity for this post.
231-
$existing = \progress_planner()->get_activities__query()->query_activities(
228+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw(
232229
[
233230
'category' => 'content',
234231
'type' => 'publish',
235232
'data_id' => (string) $post->ID,
236-
],
237-
'RAW'
233+
]
238234
);
239235

240236
// If there is no publish activity for this post, add it.
@@ -247,14 +243,13 @@ private function add_post_activity( $post, $type ) {
247243
// Post was updated, but it was published previously.
248244
if ( 'update' === $type ) {
249245
// Check if there are any activities for this post, on this date.
250-
$existing = \progress_planner()->get_activities__query()->query_activities(
246+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw(
251247
[
252248
'category' => 'content',
253249
'data_id' => (string) $post->ID,
254250
'start_date' => \progress_planner()->get_utils__date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '-12 hours' ),
255251
'end_date' => \progress_planner()->get_utils__date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '+12 hours' ),
256-
],
257-
'RAW'
252+
]
258253
);
259254

260255
// If there are activities for this post, on this date, bail.
@@ -268,13 +263,12 @@ private function add_post_activity( $post, $type ) {
268263
// Update the badges.
269264
if ( 'publish' === $type ) {
270265
// Check if there is a publish activity for this post.
271-
$existing = \progress_planner()->get_activities__query()->query_activities(
266+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw(
272267
[
273268
'category' => 'content',
274269
'type' => 'publish',
275270
'data_id' => (string) $post->ID,
276-
],
277-
'RAW'
271+
]
278272
);
279273

280274
// If there is no publish activity for this post, add it.

classes/activities/class-activity.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,15 @@ class Activity {
7676
* @return void
7777
*/
7878
public function save() {
79-
$existing = \progress_planner()->get_activities__query()->query_activities(
79+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw(
8080
[
8181
'category' => $this->category,
8282
'type' => $this->type,
8383
'data_id' => (string) $this->data_id,
84-
],
85-
'RAW'
84+
]
8685
);
8786
if ( ! empty( $existing ) ) {
88-
\progress_planner()->get_activities__query()->update_activity( $existing[0]->id, $this );
87+
\progress_planner()->get_activities__query()->update_activity( $existing[0]->id, $this ); // @phpstan-ignore-line property.nonObject
8988
return;
9089
}
9190
\progress_planner()->get_activities__query()->insert_activity( $this );

classes/activities/class-maintenance.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ public function save() {
4444
$this->date = new \DateTime();
4545
$this->user_id = \get_current_user_id();
4646

47-
$existing = \progress_planner()->get_activities__query()->query_activities(
47+
$existing = \progress_planner()->get_activities__query()->query_activities_get_raw(
4848
[
4949
'category' => $this->category,
5050
'type' => $this->type,
5151
'data_id' => $this->data_id,
5252
'start_date' => $this->date,
53-
],
54-
'RAW'
53+
]
5554
);
5655
if ( ! empty( $existing ) ) {
57-
\progress_planner()->get_activities__query()->update_activity( $existing[0]->id, $this );
56+
\progress_planner()->get_activities__query()->update_activity( $existing[0]->id, $this ); // @phpstan-ignore-line property.nonObject
5857
return;
5958
}
6059
\progress_planner()->get_activities__query()->insert_activity( $this );

classes/activities/class-query.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function create_tables() {
5555
private function create_activities_table() {
5656
global $wpdb;
5757

58-
$table_name = $wpdb->prefix . static::TABLE_NAME;
58+
$table_name = $wpdb->prefix . static::TABLE_NAME; // @phpstan-ignore-line property.nonObject
5959
$charset_collate = $wpdb->get_charset_collate();
6060

6161
/**
@@ -84,12 +84,22 @@ private function create_activities_table() {
8484
/**
8585
* Query the database for activities.
8686
*
87-
* @param array $args The arguments for the query.
88-
* @param string $return_type The type of the return value. Can be "RAW" or "ACTIVITIES".
87+
* @param array $args The arguments for the query.
88+
*
89+
* @return \Progress_Planner\Activities\Activity[] The activities.
90+
*/
91+
public function query_activities( $args ) {
92+
return $this->get_activities_from_results( $this->query_activities_get_raw( $args ) );
93+
}
94+
95+
/**
96+
* Query the database for activities.
97+
*
98+
* @param array $args The arguments for the query.
8999
*
90100
* @return array The activities.
91101
*/
92-
public function query_activities( $args, $return_type = 'ACTIVITIES' ) {
102+
public function query_activities_get_raw( $args ) {
93103
global $wpdb;
94104

95105
$defaults = [
@@ -147,7 +157,7 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) {
147157
$results = ( empty( $where_args ) )
148158
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
149159
? $wpdb->get_results(
150-
$wpdb->prepare( 'SELECT * FROM %i ORDER BY date', $wpdb->prefix . static::TABLE_NAME )
160+
$wpdb->prepare( 'SELECT * FROM %i ORDER BY date', $wpdb->prefix . static::TABLE_NAME ) // @phpstan-ignore-line property.nonObject
151161
)
152162
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
153163
: $wpdb->get_results(
@@ -158,7 +168,7 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) {
158168
\implode( ' AND ', $where_args )
159169
),
160170
\array_merge(
161-
[ $wpdb->prefix . static::TABLE_NAME ],
171+
[ $wpdb->prefix . static::TABLE_NAME ], // @phpstan-ignore-line property.nonObject
162172
$prepare_args
163173
)
164174
)
@@ -174,19 +184,15 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) {
174184
// Remove duplicates. This could be removed in a future release.
175185
$results_unique = [];
176186
foreach ( $results as $key => $result ) {
177-
$result_key = $result->category . $result->type . $result->data_id . $result->date;
187+
$result_key = $result->category . $result->type . $result->data_id . $result->date; // @phpstan-ignore-line property.nonObject
178188
// Cleanup any duplicates that may exist.
179189
if ( isset( $results_unique[ $result_key ] ) ) {
180-
$this->delete_activity_by_id( $result->id );
190+
$this->delete_activity_by_id( $result->id ); // @phpstan-ignore-line property.nonObject
181191
continue;
182192
}
183-
$results_unique[ $result->category . $result->type . $result->data_id . $result->date ] = $result;
193+
$results_unique[ $result->category . $result->type . $result->data_id . $result->date ] = $result; // @phpstan-ignore-line property.nonObject
184194
}
185-
$results = \array_values( $results_unique );
186-
187-
return 'RAW' === $return_type
188-
? $results
189-
: $this->get_activities_from_results( $results );
195+
return \array_values( $results_unique );
190196
}
191197

192198
/**
@@ -223,7 +229,7 @@ public function insert_activity( $activity ) {
223229

224230
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
225231
$result = $wpdb->insert(
226-
$wpdb->prefix . static::TABLE_NAME,
232+
$wpdb->prefix . static::TABLE_NAME, // @phpstan-ignore-line property.nonObject
227233
[
228234
'date' => $activity->date ? $activity->date->format( 'Y-m-d H:i:s' ) : ( new \DateTime() )->format( 'Y-m-d H:i:s' ),
229235
'category' => $activity->category,
@@ -246,7 +252,7 @@ public function insert_activity( $activity ) {
246252

247253
\wp_cache_flush_group( static::CACHE_GROUP );
248254

249-
return (int) $wpdb->insert_id;
255+
return (int) $wpdb->insert_id; // @phpstan-ignore-line property.nonObject
250256
}
251257

252258
/**
@@ -259,7 +265,7 @@ public function insert_activity( $activity ) {
259265
private function get_activities_from_results( $results ) {
260266
$activities = [];
261267
foreach ( $results as $result ) {
262-
$class_name = $this->get_activity_class_name( $result->category );
268+
$class_name = $this->get_activity_class_name( $result->category ); // @phpstan-ignore-line property.nonObject
263269
$activity = new $class_name();
264270
$activity->date = new \DateTime( $result->date ); // @phpstan-ignore-line property.notFound
265271
$activity->category = $result->category; // @phpstan-ignore-line property.notFound
@@ -286,7 +292,7 @@ public function update_activity( $id, $activity ) {
286292

287293
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
288294
$wpdb->update(
289-
$wpdb->prefix . static::TABLE_NAME,
295+
$wpdb->prefix . static::TABLE_NAME, // @phpstan-ignore-line property.nonObject
290296
[
291297
'date' => $activity->date ? $activity->date->format( 'Y-m-d H:i:s' ) : ( new \DateTime() )->format( 'Y-m-d H:i:s' ),
292298
'category' => $activity->category,
@@ -344,7 +350,7 @@ public function delete_activity_by_id( $id ) {
344350

345351
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
346352
$wpdb->delete(
347-
$wpdb->prefix . static::TABLE_NAME,
353+
$wpdb->prefix . static::TABLE_NAME, // @phpstan-ignore-line property.nonObject
348354
[ 'id' => $id ],
349355
[ '%d' ]
350356
);
@@ -364,7 +370,7 @@ public function delete_category_activities( $category ) {
364370

365371
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
366372
$wpdb->delete(
367-
$wpdb->prefix . static::TABLE_NAME,
373+
$wpdb->prefix . static::TABLE_NAME, // @phpstan-ignore-line property.nonObject
368374
[ 'category' => $category ],
369375
[ '%s' ]
370376
);
@@ -386,7 +392,7 @@ public function get_latest_activities( $limit = 5 ) {
386392
$results = $wpdb->get_results(
387393
$wpdb->prepare(
388394
'SELECT * FROM %i ORDER BY date DESC LIMIT %d',
389-
$wpdb->prefix . static::TABLE_NAME,
395+
$wpdb->prefix . static::TABLE_NAME, // @phpstan-ignore-line property.nonObject
390396
$limit
391397
)
392398
);
@@ -410,15 +416,15 @@ public function get_oldest_activity() {
410416
$result = $wpdb->get_row(
411417
$wpdb->prepare(
412418
'SELECT * FROM %i ORDER BY date ASC LIMIT 1',
413-
$wpdb->prefix . static::TABLE_NAME
419+
$wpdb->prefix . static::TABLE_NAME // @phpstan-ignore-line property.nonObject
414420
)
415421
);
416422

417423
if ( ! $result ) {
418424
return null;
419425
}
420426

421-
$class_name = $this->get_activity_class_name( $result->category );
427+
$class_name = $this->get_activity_class_name( $result->category ); // @phpstan-ignore-line property.nonObject
422428
$activity = new $class_name();
423429
$activity->date = new \DateTime( $result->date ); // @phpstan-ignore-line property.notFound
424430
$activity->category = $result->category; // @phpstan-ignore-line property.notFound
@@ -488,10 +494,10 @@ private function maybe_upgrade() {
488494
private function upgrade_20241011() {
489495
global $wpdb;
490496

491-
$table_name = $wpdb->prefix . static::TABLE_NAME;
497+
$table_name = $wpdb->prefix . static::TABLE_NAME; // @phpstan-ignore-line property.nonObject
492498

493499
foreach ( $wpdb->get_results( "DESCRIBE $table_name" ) as $column ) {
494-
if ( 'data_id' === $column->Field && \str_contains( \strtolower( $column->Type ), 'int' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
500+
if ( 'data_id' === $column->Field && \str_contains( \strtolower( $column->Type ), 'int' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase, @phpstan-ignore-line property.nonObject
495501
$wpdb->query( "ALTER TABLE $table_name CHANGE COLUMN data_id data_id VARCHAR(255)" );
496502
}
497503
}

classes/admin/class-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function get_widgets() {
6363
*
6464
* @return array<\Progress_Planner\Admin\Widgets\Widget>
6565
*/
66-
return \apply_filters( 'progress_planner_admin_widgets', $widgets );
66+
return \apply_filters( 'progress_planner_admin_widgets', $widgets ); // @phpstan-ignore-line parameter.phpDocType
6767
}
6868

6969
/**

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ public function get_color( $number, $date ) {
7070
*/
7171
public function get_score() {
7272
$activities = \progress_planner()->get_activities__query()->query_activities(
73-
[
74-
// Use 31 days to take into account
75-
// the activities score decay from previous activities.
76-
'start_date' => new \DateTime( '-31 days' ),
77-
]
73+
// Use 31 days to take into account the activities score decay from previous activities.
74+
[ 'start_date' => new \DateTime( '-31 days' ) ]
7875
);
7976

8077
$score = 0;

classes/class-badges.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public function clear_monthly_progress( $activity_id ) {
117117
'category' => 'suggested_task',
118118
'type' => 'completed',
119119
'data_id' => (string) $activity_id,
120-
],
121-
'ACTIVITIES'
120+
]
122121
);
123122

124123
if ( empty( $activities ) ) {

classes/class-base.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
* @method \Progress_Planner\Plugin_Installer get_plugin_installer()
4444
* @method \Progress_Planner\Admin\Widgets\Badge_Streak_Content get_admin__widgets__badge_streak_content()
4545
* @method \Progress_Planner\Admin\Widgets\Badge_Streak_Maintenance get_admin__widgets__badge_streak_maintenance()
46+
* @method \Progress_Planner\Admin\Enqueue get_admin__enqueue()
47+
* @method \Progress_Planner\Admin\Widgets\Whats_New get_admin__widgets__whats_new()
48+
* @method \Progress_Planner\Admin\Widgets\ToDo get_admin__widgets__todo()
49+
* @method \Progress_Planner\Admin\Widgets\Monthly_Badges get_admin__widgets__monthly_badges()
50+
* @method \Progress_Planner\UI\Popover get_ui__popover()
51+
* @method \Progress_Planner\Admin\Widgets\Latest_Badge get_admin__widgets__latest_badge()
52+
* @method \Progress_Planner\Admin\Widgets\Content_Activity get_admin__widgets__content_activity()
53+
* @method \Progress_Planner\UI\Chart get_ui__chart()
54+
* @method \Progress_Planner\Activities\Content_Helpers get_activities__content_helpers()
55+
* @method \Progress_Planner\Admin\Widgets\Challenge get_admin__widgets__challenge()
56+
* @method \Progress_Planner\Admin\Widgets\Activity_Scores get_admin__widgets__activity_scores()
57+
* @method \Progress_Planner\Utils\Date get_utils__date()
4658
*/
4759
class Base {
4860

classes/class-page-types.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,13 @@ private function get_posts_by_title( $title ) {
520520
// Cache the query.
521521
$posts = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
522522
$wpdb->prepare(
523-
"SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'trash' AND post_title LIKE %s",
523+
"SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'trash' AND post_title LIKE %s", // @phpstan-ignore-line property.nonObject
524524
'%' . $wpdb->esc_like( $title ) . '%'
525525
)
526526
);
527527
$posts_ids = [];
528528
foreach ( $posts as $post ) {
529-
$posts_ids[] = (int) $post->ID;
529+
$posts_ids[] = (int) $post->ID; // @phpstan-ignore-line property.nonObject
530530
}
531531
\wp_cache_set( $cache_key, $posts_ids, $cache_group );
532532
return $posts_ids;

classes/class-suggested-tasks-db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function update_recommendation( $id, $data ) {
203203

204204
if ( ! empty( $update_terms ) ) {
205205
foreach ( $update_terms as $taxonomy => $term ) {
206-
$update_results[] = (bool) \wp_set_object_terms( $id, $term->slug, $taxonomy );
206+
$update_results[] = (bool) \wp_set_object_terms( $id, $term->slug, $taxonomy ); // @phpstan-ignore-line property.nonObject
207207
}
208208
}
209209

0 commit comments

Comments
 (0)