Skip to content

Commit

Permalink
CS...
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsoo committed Jun 21, 2023
1 parent 175998e commit 5727788
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Application\Actions;

use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Factory_Interface;
Expand All @@ -14,7 +15,7 @@
use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action;

/**
*
* The Verify_Indexable_Action_Factory class
*/
class Verify_Indexable_Action_Factory implements Verify_Indexables_Action_Factory_Interface {

Expand Down Expand Up @@ -58,6 +59,8 @@ class Verify_Indexable_Action_Factory implements Verify_Indexables_Action_Factor
private $verify_term_links_indexables_action;

/**
* The constructor.
*
* @param Verify_Term_Indexables_Action $verify_term_indexables_action The instance.
* @param Verify_General_Indexables_Action $verify_general_indexables_action The instance.
* @param Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action The instance.
Expand All @@ -80,7 +83,7 @@ public function __construct(
*
* @param Current_Verification_Action $verification_action The Verification action.
*
* @throws Verify_Action_Not_Found_Exception
* @throws Verify_Action_Not_Found_Exception When the given verification action does not exists.
* @return Verify_Indexables_Action_Interface
*/
public function get( Current_Verification_Action $verification_action ): Verify_Indexables_Action_Interface {
Expand All @@ -103,15 +106,15 @@ public function get( Current_Verification_Action $verification_action ): Verify_
*
* @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for.
*
* @throws No_Verification_Action_Left_Exception
* @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left.
* @return Current_Verification_Action
*/
public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object
): Current_Verification_Action {
$current_verification_action = $current_verification_action_object->get_action();

if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING ) ) {
$key = array_search( $current_verification_action, self::VERIFICATION_MAPPING );
if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING, true ) ) {
$key = array_search( $current_verification_action, self::VERIFICATION_MAPPING, true );
if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) {
return new Current_Verification_Action( self::VERIFICATION_MAPPING[ $key ] );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php


// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Application\Commands;

use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler;
Expand All @@ -12,6 +12,10 @@
use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception;
use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count;

/**
* The Verify_Non_Timestamp_Indexables_Command_Handler class.
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
*/
class Verify_Non_Timestamp_Indexables_Command_Handler {

/**
Expand Down Expand Up @@ -45,21 +49,21 @@ class Verify_Non_Timestamp_Indexables_Command_Handler {
/**
* The constructor.
*
* @param Verification_Cron_Schedule_Handler $cron_schedule_handler
* @param Verification_Cron_Batch_Handler $cron_batch_handler
* @param Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory
* @param Next_Verification_Action_Handler $action_handler
* @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler.
* @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler.
* @param Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory The verify indexables action factory.
* @param Next_Verification_Action_Handler $action_handler The action handler.
*/
public function __construct(
Verification_Cron_Schedule_Handler $cron_schedule_handler,
Verification_Cron_Batch_Handler $cron_batch_handler,
Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory,
Next_Verification_Action_Handler $action_handler
) {
$this->cron_schedule_handler = $cron_schedule_handler;
$this->cron_batch_handler = $cron_batch_handler;
$this->cron_schedule_handler = $cron_schedule_handler;
$this->cron_batch_handler = $cron_batch_handler;
$this->verify_indexables_action_factory = $verify_indexables_action_factory;
$this->action_handler = $action_handler;
$this->action_handler = $action_handler;
}

/**
Expand All @@ -79,7 +83,6 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time
}

$has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() );
// for each fix
if ( $has_more_to_index ) {
$this->cron_batch_handler->set_current_non_timestamped_indexables_batch( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Application\Commands;

use Yoast\WP\SEO\Indexables\Domain\Abstract_Indexables_Command;
use Yoast\WP\SEO\Indexables\Domain\Batch_Size;
use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action;

/**
*
* The Verify_Non_Timestamp_Indexables_Command class.
*/
class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Command {

/**
* @var Current_Verification_Action $current_action The current verification action in progress.
* The current verification action in progress.
*
* @var Current_Verification_Action $current_action
*/
private $current_action;

/**
* The constructor.
*
* @param int $last_batch The last batch count.
* @param int $batch_size The batch size.
* @param string $plugin_deactivated_at The plugin deactivated at timestamp.
* @param string $current_action The current verification action.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php


// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Application\Commands;

use Yoast\WP\SEO\Builders\Indexable_Builder;
Expand Down Expand Up @@ -45,10 +45,10 @@ class Verify_Post_Indexables_Command_Handler {
/**
* The constructor.
*
* @param Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository
* @param Verification_Cron_Schedule_Handler $cron_schedule_handler
* @param Verification_Cron_Batch_Handler $verification_cron_batch_handler
* @param Indexable_Builder $indexable_builder
* @param Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository The outdated post indexables repository.
* @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler.
* @param Verification_Cron_Batch_Handler $verification_cron_batch_handler The verification cron batch handler.
* @param Indexable_Builder $indexable_builder The indexable builder.
*/
public function __construct(
Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Application\Ports;

use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception;
Expand All @@ -13,7 +14,7 @@ interface Outdated_Post_Indexables_Repository_Interface {
* Finds a list of posts for which the indexables are not up to date.
* This is done by checking if the updated at of the post is the same as the indexable.
*
* @param Last_Batch_Count $count
* @param Last_Batch_Count $count The batch count domain object.
*
* @throws No_Outdated_Posts_Found_Exception When there are no outdated posts found.
* @return Outdated_Post_Indexables_List
Expand Down
33 changes: 33 additions & 0 deletions src/indexables/application/verification-cron-batch-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Yoast\WP\SEO\Indexables\Domain\Batch_Size;
use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count;

/**
* The Verification_Cron_Batch_Handler class.
*/
class Verification_Cron_Batch_Handler {

/**
Expand All @@ -15,22 +18,52 @@ class Verification_Cron_Batch_Handler {
*/
protected $options_helper;

/**
* The constructor.
*
* @param Options_Helper $options_helper The options helper.
*/
public function __construct( Options_Helper $options_helper ) {
$this->options_helper = $options_helper;
}

/**
* Gets the `cron_verify_post_indexables_last_batch` option
*
* @return int
*/
public function get_current_post_indexables_batch():int {
return $this->options_helper->get( 'cron_verify_post_indexables_last_batch', 0 );
}

/**
* Sets the `cron_verify_post_indexables_last_batch` option
*
* @param int $batch_count The batch count.
*
* @return void
*/
public function set_current_post_indexables_batch( int $batch_count ) {
$this->options_helper->set( 'cron_verify_post_indexables_last_batch', $batch_count );
}

/**
* Gets the `cron_verify_non_timestamped_indexables_last_batch` option
*
* @return int
*/
public function get_current_non_timestamped_indexables_batch():int {
return $this->options_helper->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 );
}

/**
* Sets the `cron_verify_non_timestamped_indexables_last_batch` option.
*
* @param Last_Batch_Count $last_batch_count The current batch count.
* @param Batch_Size $batch_size The batch size.
*
* @return void
*/
public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ) {
$batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() );
$this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Verification_Cron_Schedule_Handler {
public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables';

/**
* he name of the CRON job.
* The name of the CRON job.
*/
public const INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME = 'wpseo_indexable_verify_non_timestamped_indexables';

Expand All @@ -27,7 +27,7 @@ class Verification_Cron_Schedule_Handler {
/**
* The constructor.
*
* @param Cron_Verification_Gate $cron_verification_gate
* @param Cron_Verification_Gate $cron_verification_gate The cron verification gate.
*/
public function __construct( Cron_Verification_Gate $cron_verification_gate ) {
$this->cron_verification_gate = $cron_verification_gate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
namespace Yoast\WP\SEO\Indexables\Domain\Actions;

use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action;
Expand All @@ -8,6 +9,8 @@

/**
* The Verify_Indexables_Action_Factory_Interface interface.
*
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
*/
interface Verify_Indexables_Action_Factory_Interface {

Expand All @@ -16,7 +19,7 @@ interface Verify_Indexables_Action_Factory_Interface {
*
* @param Current_Verification_Action $verification_action The Verification action.
*
* @throws Verify_Action_Not_Found_Exception
* @throws Verify_Action_Not_Found_Exception When the given verification action does not exists.
* @return Verify_Indexables_Action_Interface
*/
public function get( Current_Verification_Action $verification_action ):Verify_Indexables_Action_Interface;
Expand All @@ -26,7 +29,7 @@ public function get( Current_Verification_Action $verification_action ):Verify_I
*
* @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for.
*
* @throws No_Verification_Action_Left_Exception
* @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left.
* @return Current_Verification_Action
*/
public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ):Current_Verification_Action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface Verify_Indexables_Action_Interface {
public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size):bool;

/**
* Sets the wpdb instance.
*
* @param \wpdb $wpdb The wpdb instance.
*
* @return mixed
Expand Down
20 changes: 18 additions & 2 deletions src/indexables/domain/batch-size.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@

namespace Yoast\WP\SEO\Indexables\Domain;

/**
* The Batch_Size domain class.
*/
class Batch_Size {

/**
* @var int $batch_size The batch size.
* The batch size.
*
* @var int $batch_size
*/
private $batch_size;

/**
* @param int $batch_size
* The constructor.
*
* @param int $batch_size The batch size.
*/
public function __construct( int $batch_size ) {
$this->batch_size = $batch_size;
}

/**
* Returns the batch size.
*
* @return int
*/
public function get_batch_size(): int {
return $this->batch_size;
}

/**
* Checks if the batch is bigger than the count.
*
* @param int|null $count The count to check.
*
* @return bool
*/
public function should_keep_going( ?int $count ): bool {
return $count >= $this->get_batch_size();
}
Expand Down
11 changes: 10 additions & 1 deletion src/indexables/domain/current-verification-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

namespace Yoast\WP\SEO\Indexables\Domain;

/**
* The Current_Verification_Action class.
*/
class Current_Verification_Action {

/**
* The current action.
*
* @var string $action
*/
private $action;

/**
* @param string $action
* The constructor.
*
* @param string $action The current action.
*/
public function __construct( string $action ) {
$this->action = $action;
}

/**
* Gets the current action.
*
* @return string
*/
public function get_action(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

/**
* The No_Non_Timestamped_Objects_Found_Exception exception.
*
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
*/
class No_Non_Timestamped_Objects_Found_Exception extends \Exception {

Expand Down
Loading

0 comments on commit 5727788

Please sign in to comment.