Skip to content

Commit e9a6ab6

Browse files
authored
Merge pull request #532 from ProgressPlanner/ari/fix-duplicate-transform_collector_data
Move `transform_collector_data` method to parent class
2 parents 92276ec + 84997a7 commit e9a6ab6

File tree

4 files changed

+31
-57
lines changed

4 files changed

+31
-57
lines changed

classes/suggested-tasks/providers/class-remove-terms-without-posts.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,6 @@ protected function is_specific_task_completed( $task_id ) {
206206
return $term ? self::MIN_POSTS < $term->count : true;
207207
}
208208

209-
/**
210-
* Transform data collector data into task data format.
211-
*
212-
* @param array $data The data from data collector.
213-
* @return array The transformed data with original data merged.
214-
*/
215-
protected function transform_collector_data( array $data ): array {
216-
return \array_merge(
217-
$data,
218-
[
219-
'target_term_id' => $data['term_id'],
220-
'target_taxonomy' => $data['taxonomy'],
221-
'target_term_name' => $data['name'],
222-
]
223-
);
224-
}
225-
226209
/**
227210
* Get an array of tasks to inject.
228211
*
@@ -236,11 +219,11 @@ public function get_tasks_to_inject() {
236219
return [];
237220
}
238221

239-
$data = $this->get_data_collector()->collect();
222+
$data = $this->transform_collector_data( $this->get_data_collector()->collect() );
240223
$task_id = $this->get_task_id(
241224
[
242-
'term_id' => $data['term_id'],
243-
'taxonomy' => $data['taxonomy'],
225+
'target_term_id' => $data['target_term_id'],
226+
'target_taxonomy' => $data['target_taxonomy'],
244227
]
245228
);
246229

@@ -251,7 +234,7 @@ public function get_tasks_to_inject() {
251234
// Transform the data to match the task data structure.
252235
$task_data = $this->modify_injection_task_data(
253236
$this->get_task_details(
254-
$this->transform_collector_data( $data )
237+
$data
255238
)
256239
);
257240

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,28 @@ public function get_task_details( $task_data = [] ) {
540540
'snoozable' => $this->is_snoozable(),
541541
];
542542
}
543+
544+
/**
545+
* Transform data collector data into task data format.
546+
*
547+
* @param array $data The data from data collector.
548+
* @return array The transformed data with original data merged.
549+
*/
550+
protected function transform_collector_data( array $data ): array {
551+
$transform_keys = [
552+
'term_id' => 'target_term_id',
553+
'taxonomy' => 'target_taxonomy',
554+
'name' => 'target_term_name',
555+
'post_id' => 'target_post_id',
556+
'post_title' => 'target_post_title',
557+
];
558+
559+
foreach ( $transform_keys as $key => $value ) {
560+
if ( isset( $data[ $key ] ) ) {
561+
$data[ $value ] = $data[ $key ];
562+
}
563+
}
564+
565+
return $data;
566+
}
543567
}

classes/suggested-tasks/providers/class-update-term-description.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,6 @@ protected function is_specific_task_completed( $task_id ) {
189189
return '' !== $term_description && '&nbsp;' !== $term_description;
190190
}
191191

192-
/**
193-
* Transform data collector data into task data format.
194-
*
195-
* @param array $data The data from data collector.
196-
* @return array The transformed data with original data merged.
197-
*/
198-
protected function transform_collector_data( array $data ): array {
199-
return \array_merge(
200-
$data,
201-
[
202-
'target_term_id' => $data['term_id'],
203-
'target_taxonomy' => $data['taxonomy'],
204-
'target_term_name' => $data['name'],
205-
]
206-
);
207-
}
208-
209192
/**
210193
* Get an array of tasks to inject.
211194
*

classes/suggested-tasks/providers/integrations/yoast/class-fix-orphaned-content.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,6 @@ protected function is_specific_task_completed( $task_id ) {
147147
return 0 !== (int) $linked_count;
148148
}
149149

150-
/**
151-
* Transform data collector data into task data format.
152-
*
153-
* @param array $data The data from data collector.
154-
* @return array The transformed data with original data merged.
155-
*/
156-
protected function transform_collector_data( array $data ): array {
157-
return \array_merge(
158-
$data,
159-
[
160-
'target_post_id' => $data['post_id'],
161-
'target_post_title' => $data['post_title'],
162-
]
163-
);
164-
}
165-
166150
/**
167151
* Get an array of tasks to inject.
168152
*
@@ -173,10 +157,10 @@ public function get_tasks_to_inject() {
173157
return [];
174158
}
175159

176-
$data = $this->get_data_collector()->collect();
160+
$data = $this->transform_collector_data( $this->get_data_collector()->collect() );
177161
$task_id = $this->get_task_id(
178162
[
179-
'post_id' => $data['post_id'],
163+
'target_post_id' => $data['target_post_id'],
180164
]
181165
);
182166

@@ -188,7 +172,7 @@ public function get_tasks_to_inject() {
188172
// Transform the data to match the task data structure.
189173
$task_data = $this->modify_injection_task_data(
190174
$this->get_task_details(
191-
$this->transform_collector_data( $data )
175+
$data
192176
)
193177
);
194178

0 commit comments

Comments
 (0)