Skip to content

Commit 360a4bf

Browse files
committed
convert more anonymous functions
1 parent 1b315cc commit 360a4bf

10 files changed

Lines changed: 19 additions & 75 deletions

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,22 @@ public function get_chart_args_content_count( $type = 'publish', $color = '#5347
4949
public function get_chart_args( $type = 'publish', $color = '#534786' ) {
5050
return [
5151
'type' => 'line',
52-
'items_callback' => function ( $start_date, $end_date ) use ( $type ) {
53-
return \progress_planner()->get_activities__query()->query_activities(
54-
[
55-
'category' => 'content',
56-
'start_date' => $start_date,
57-
'end_date' => $end_date,
58-
'type' => $type,
59-
]
60-
);
61-
},
52+
'items_callback' => fn( $start_date, $end_date ) => \progress_planner()->get_activities__query()->query_activities(
53+
[
54+
'category' => 'content',
55+
'start_date' => $start_date,
56+
'end_date' => $end_date,
57+
'type' => $type,
58+
]
59+
),
6260
'dates_params' => [
6361
'start_date' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $this->get_range() ),
6462
'end_date' => new \DateTime(),
6563
'frequency' => $this->get_frequency(),
6664
'format' => 'M',
6765
],
6866
'filter_results' => [ $this, 'filter_activities' ],
69-
'color' => function () use ( $color ) {
70-
return $color;
71-
},
67+
'color' => fn() => $color,
7268
];
7369
}
7470

classes/ui/class-branding.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,7 @@ public function filter_widgets( $widgets ) {
226226
return $widgets;
227227
}
228228

229-
return \array_filter(
230-
$widgets,
231-
function ( $widget ) use ( $show_papers ) {
232-
return \in_array( $widget->get_id(), $show_papers, true );
233-
}
234-
);
229+
return \array_filter( $widgets, fn( $widget ) => \in_array( $widget->get_id(), $show_papers, true ) );
235230
}
236231

237232
/**

classes/utils/class-system-status.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ public function get_system_status() {
8484
'frequency' => 'monthly',
8585
'format' => 'M',
8686
],
87-
'count_callback' => function ( $activities, $date ) {
88-
$score = 0;
89-
foreach ( $activities as $activity ) {
90-
$score += $activity->get_points( $date );
91-
}
92-
return $score * 100 / Base::SCORE_TARGET;
93-
},
87+
'count_callback' => fn( $activities, $date ) =>
88+
array_sum( array_map( fn( $activity ) => $activity->get_points( $date ), $activities ) ) * 100 / Base::SCORE_TARGET,
9489
'normalized' => true,
9590
'max' => 100,
9691
]

tests/phpunit/test-class-page-types.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,7 @@ public function test_get_page_types() {
128128
$this->assertCount( \count( $lessons ), $page_types );
129129

130130
foreach ( $lessons as $lesson ) {
131-
$this->assertCount(
132-
1,
133-
\array_filter(
134-
$page_types,
135-
function ( $page_type ) use ( $lesson ) {
136-
return $page_type['slug'] === $lesson['settings']['id'];
137-
}
138-
)
139-
);
131+
$this->assertCount( 1, \array_filter( $page_types, fn( $page_type ) => $page_type['slug'] === $lesson['settings']['id'] ) );
140132
}
141133
}
142134

tests/phpunit/test-class-terms-without-description-data-collector.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ public function test_collect_respects_excluded_terms() {
134134
$term_id = $term_result['term_id'];
135135

136136
// Add filter to exclude the term.
137-
\add_filter(
138-
'progress_planner_terms_without_description_exclude_term_ids',
139-
function () use ( $term_id ) {
140-
return [ $term_id ];
141-
}
142-
);
137+
\add_filter( 'progress_planner_terms_without_description_exclude_term_ids', fn() => [ $term_id ] );
143138

144139
// Get the data.
145140
$this->data_collector->update_cache();

tests/phpunit/test-class-terms-without-posts-data-collector.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ public function test_collect_respects_excluded_terms() {
102102
$term_id = $term_result['term_id'];
103103

104104
// Add filter to exclude the term.
105-
\add_filter(
106-
'progress_planner_terms_without_posts_exclude_term_ids',
107-
function () use ( $term_id ) {
108-
return [ $term_id ];
109-
}
110-
);
105+
\add_filter( 'progress_planner_terms_without_posts_exclude_term_ids', fn() => [ $term_id ] );
111106

112107
// Get the data.
113108
$this->data_collector->update_cache();

tests/phpunit/test-class-upgrade-migration-130.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ public function test_recreating_tasks_from_activities() {
103103

104104
// Verify that every value in the $activity_ids array is present in the $tasks array and has completed status.
105105
foreach ( $activity_ids as $activity_id ) {
106-
$matching_tasks = \array_filter(
107-
$tasks,
108-
function ( $task ) use ( $activity_id ) {
109-
return isset( $task['task_id'] ) &&
110-
$task['task_id'] === $activity_id;
111-
}
112-
);
106+
$matching_tasks = \array_filter( $tasks, fn( $task ) => isset( $task['task_id'] ) && $task['task_id'] === $activity_id );
113107

114108
$this->assertNotEmpty(
115109
$matching_tasks,

tests/phpunit/test-class-upgrade-migrations-111.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,7 @@ public function test_dataset_1() {
236236

237237
// Verify that every value in the $items array is present in the $tasks array and has completed status.
238238
foreach ( $migration_map as $item ) {
239-
$matching_tasks = \array_filter(
240-
$tasks,
241-
function ( $task ) use ( $item ) {
242-
return isset( $task['task_id'] ) &&
243-
isset( $item['task_id'] ) &&
244-
$task['task_id'] === $item['task_id'];
245-
}
246-
);
239+
$matching_tasks = \array_filter( $tasks, fn( $task ) => isset( $task['task_id'] ) && isset( $item['task_id'] ) && $task['task_id'] === $item['task_id'] );
247240

248241
$this->assertNotEmpty(
249242
$matching_tasks,

views/page-widgets/activity-scores.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@
6666
'frequency' => $prpl_widget->get_frequency(),
6767
'format' => 'M',
6868
],
69-
'count_callback' => function ( $activities, $date ) {
70-
$score = 0;
71-
foreach ( $activities as $activity ) {
72-
$score += $activity->get_points( $date );
73-
}
74-
return $score * 100 / Base::SCORE_TARGET;
75-
},
69+
'count_callback' => fn( $activities, $date ) => array_sum( array_map( fn( $activity ) => $activity->get_points( $date ), $activities ) ) * 100 / Base::SCORE_TARGET,
7670
'normalized' => true,
7771
'color' => [ $prpl_widget, 'get_color' ],
7872
'max' => 100,

views/page-widgets/content-activity.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@
7272
if ( $prpl_activities ) {
7373
if ( 'delete' !== $prpl_activity_type ) {
7474
// Filter the activities to only include the tracked post types.
75-
$prpl_activities = \array_filter(
76-
$prpl_activities,
77-
function ( $activity ) use ( $prpl_tracked_post_types ) {
78-
return \in_array( \get_post_type( $activity->data_id ), $prpl_tracked_post_types, true );
79-
}
80-
);
75+
$prpl_activities = \array_filter( $prpl_activities, fn( $activity ) => \in_array( \get_post_type( $activity->data_id ), $prpl_tracked_post_types, true ) );
8176
}
8277

8378
// Update the count.

0 commit comments

Comments
 (0)