| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\Task_List\Domain\Tasks; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Task_List\Domain\Components\Task_Analyzer_Interface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Abstract class for a child task. |
| 9 |
* Use this when you need a task that belongs to a parent task. |
| 10 |
*/ |
| 11 |
abstract class Abstract_Child_Task extends Abstract_Task implements Child_Task_Interface { |
| 12 |
|
| 13 |
/** |
| 14 |
* The parent task associated with the task. |
| 15 |
* |
| 16 |
* @var Parent_Task_Interface |
| 17 |
*/ |
| 18 |
protected $parent_task; |
| 19 |
|
| 20 |
/** |
| 21 |
* Returns the task's analyzer component. |
| 22 |
* |
| 23 |
* @return Task_Analyzer_Interface|null |
| 24 |
*/ |
| 25 |
public function get_analyzer(): ?Task_Analyzer_Interface { |
| 26 |
return null; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns an array representation of the task data. |
| 31 |
* |
| 32 |
* @return array<string, string|bool|int|array|null> Returns in an array format. |
| 33 |
*/ |
| 34 |
public function to_array(): array { |
| 35 |
$data = parent::to_array(); |
| 36 |
|
| 37 |
$analyzer = $this->get_analyzer(); |
| 38 |
|
| 39 |
$data['parentTaskId'] = $this->parent_task->get_id(); |
| 40 |
$data['analyzer'] = ( $analyzer !== null ) ? $analyzer->to_array() : null; |
| 41 |
|
| 42 |
return $data; |
| 43 |
} |
| 44 |
} |
| 45 |
|