Skip to content

Commit

Permalink
feat: add non activated exception (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee authored Jan 24, 2024
1 parent a589453 commit ef50362
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/class-trigger-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
use Storipress\Storipress\Errors\Exception;
use Storipress\Storipress\Errors\Internal_Error_Exception;
use Storipress\Storipress\Errors\Invalid_Payload_Exception;
use Storipress\Storipress\Errors\Post_Not_Found_Exception;
use Storipress\Storipress\Errors\Non_Activated_Trigger_Exception;
use Storipress\Storipress\Triggers\ACF_Data;
use Storipress\Storipress\Triggers\Connect;
use Storipress\Storipress\Triggers\Disconnect;
use Storipress\Storipress\Triggers\Trigger;
use Storipress\Storipress\Triggers\Update_Yoast_Seo_Metadata;
use Throwable;
use WP_Post;
use WP_REST_Request;
use WP_REST_Server;

Expand Down Expand Up @@ -174,8 +173,8 @@ public function update_yoast_seo_metadata( $request ) {
* @since 0.0.12
*/
public function handle( Trigger $trigger ) {
if ( ! $trigger->validate() ) {
$this->error( new Invalid_Payload_Exception() );
if ( ! $trigger->is_activated() ) {
$this->error( new Non_Activated_Trigger_Exception() );

return;
}
Expand Down
24 changes: 24 additions & 0 deletions src/errors/class-non-activated-trigger-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Storipress
*
* @package Storipress
*/

declare(strict_types=1);

namespace Storipress\Storipress\Errors;

/**
* Invalid request payload exception.
*
* @since 0.0.12
*/
final class Non_Activated_Trigger_Exception extends Exception {
/**
* Constructor.
*/
public function __construct() {
parent::__construct( '', 4222001 );
}
}
2 changes: 1 addition & 1 deletion src/triggers/class-acf-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ACF_Data extends Trigger {
/**
* {@inheritDoc}
*/
public function validate(): bool {
public function is_activated(): bool {
if ( ! Storipress::instance()->core->is_connected() ) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/triggers/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct( string $client ) {
/**
* {@inheritDoc}
*/
public function validate(): bool {
public function is_activated(): bool {
// not allow to connect more than one client.
return ! Storipress::instance()->core->is_connected();
}
Expand Down
2 changes: 1 addition & 1 deletion src/triggers/class-disconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Disconnect extends Trigger {
/**
* {@inheritDoc}
*/
public function validate(): bool {
public function is_activated(): bool {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/triggers/class-trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
*/
abstract class Trigger {
/**
* Validate the trigger request payload.
* The trigger is activated or not.
*
* @since 0.0.12
*/
abstract public function validate(): bool;
abstract public function is_activated(): bool;

/**
* Run the trigger and return response data.
Expand Down
2 changes: 1 addition & 1 deletion src/triggers/class-update-yoast-seo-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct( int $post_id, array $options ) {
/**
* {@inheritDoc}
*/
public function validate(): bool {
public function is_activated(): bool {
if ( ! Storipress::instance()->core->is_connected() ) {
return false;
}
Expand Down

0 comments on commit ef50362

Please sign in to comment.