| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Analytics\Application; |
| 4 |
|
| 5 |
use WPSEO_Collection; |
| 6 |
use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface; |
| 7 |
use Yoast\WP\SEO\Analytics\Domain\Missing_Indexable_Bucket; |
| 8 |
use Yoast\WP\SEO\Analytics\Domain\Missing_Indexable_Count; |
| 9 |
|
| 10 |
/** |
| 11 |
* Manages the collection of the missing indexable data. |
| 12 |
* |
| 13 |
* @makePublic |
| 14 |
*/ |
| 15 |
class Missing_Indexables_Collector implements WPSEO_Collection { |
| 16 |
|
| 17 |
/** |
| 18 |
* All the indexation actions. |
| 19 |
* |
| 20 |
* @var array<Indexation_Action_Interface> |
| 21 |
*/ |
| 22 |
private $indexation_actions; |
| 23 |
|
| 24 |
/** |
| 25 |
* The collector constructor. |
| 26 |
* |
| 27 |
* @param Indexation_Action_Interface ...$indexation_actions All the Indexation actions. |
| 28 |
*/ |
| 29 |
public function __construct( Indexation_Action_Interface ...$indexation_actions ) { |
| 30 |
$this->indexation_actions = $indexation_actions; |
| 31 |
$this->add_additional_indexing_actions(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Gets the data for the tracking collector. |
| 36 |
* |
| 37 |
* @return array The list of missing indexables. |
| 38 |
*/ |
| 39 |
public function get() { |
| 40 |
$missing_indexable_bucket = new Missing_Indexable_Bucket(); |
| 41 |
foreach ( $this->indexation_actions as $indexation_action ) { |
| 42 |
$missing_indexable_count = new Missing_Indexable_Count( \get_class( $indexation_action ), $indexation_action->get_total_unindexed() ); |
| 43 |
$missing_indexable_bucket->add_missing_indexable_count( $missing_indexable_count ); |
| 44 |
} |
| 45 |
|
| 46 |
return [ 'missing_indexables' => $missing_indexable_bucket->to_array() ]; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Adds additional indexing actions to count from the 'wpseo_indexable_collector_add_indexation_actions' filter. |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
private function add_additional_indexing_actions() { |
| 55 |
/** |
| 56 |
* Filter: Adds the possibility to add additional indexation actions to be included in the count routine. |
| 57 |
* |
| 58 |
* @internal |
| 59 |
* @param Indexation_Action_Interface $actions This filter expects a list of Indexation_Action_Interface instances |
| 60 |
* and expects only Indexation_Action_Interface implementations to be |
| 61 |
* added to the list. |
| 62 |
*/ |
| 63 |
$indexing_actions = (array) \apply_filters( 'wpseo_indexable_collector_add_indexation_actions', $this->indexation_actions ); |
| 64 |
|
| 65 |
$this->indexation_actions = \array_filter( |
| 66 |
$indexing_actions, |
| 67 |
static function ( $indexing_action ) { |
| 68 |
return \is_a( $indexing_action, Indexation_Action_Interface::class ); |
| 69 |
}, |
| 70 |
); |
| 71 |
} |
| 72 |
} |
| 73 |
|