Early return instead of complicating the task

This commit is contained in:
Narek Zakarian 2024-09-11 20:28:31 +04:00
parent 42a6cb2b45
commit 137a8b4975
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
5 changed files with 18 additions and 32 deletions

View file

@ -1790,15 +1790,18 @@ return array(
$section_id = PayPalGateway::ID;
$pay_later_tab_id = Settings::PAY_LATER_TAB_ID;
return array(
array(
$list_of_config = array();
if ( $container->get('paylater-configurator.is-available') ) {
$list_of_config[] = array(
'id' => 'pay-later-messaging-task',
'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ),
'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ),
'redirect_url' => admin_url("admin.php?page=wc-settings&tab=checkout&section={$section_id}&ppcp-tab={$pay_later_tab_id}"),
'is_enabled' => $container->get('paylater-configurator.is-available'),
),
);
);
}
return $list_of_config;
},
/**
@ -1818,8 +1821,7 @@ return array(
$title = $config['title'] ?? '';
$description = $config['description'] ?? '';
$redirect_url = $config['redirect_url'] ?? '';
$is_enabled = $config['is_enabled'] ?? false;
$simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url, $is_enabled );
$simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url );
}
return $simple_redirect_tasks;

View file

@ -17,7 +17,7 @@ class SimpleRedirectTaskFactory implements SimpleRedirectTaskFactoryInterface {
/**
* {@inheritDoc}
*/
public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask {
return new SimpleRedirectTask( $id, $title, $description, $redirect_url, $is_enabled );
public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask {
return new SimpleRedirectTask( $id, $title, $description, $redirect_url );
}
}

View file

@ -20,8 +20,7 @@ interface SimpleRedirectTaskFactoryInterface {
* @param string $title The task title.
* @param string $description The task description.
* @param string $redirect_url The redirection URL.
* @param bool $is_enabled Whether the task is enabled.
* @return SimpleRedirectTask The task.
*/
public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask;
public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask;
}

View file

@ -44,14 +44,6 @@ class SimpleRedirectTask extends Task {
*/
protected string $redirect_url;
/**
* Whether the task is enabled.
*
* @var bool
*/
protected bool $is_enabled;
/**
* SimpleRedirectTask constructor.
*
@ -59,16 +51,14 @@ class SimpleRedirectTask extends Task {
* @param string $title The task title.
* @param string $description The task description.
* @param string $redirect_url The redirection URL.
* @param bool $is_enabled Whether the task is enabled.
*/
public function __construct( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ) {
public function __construct( string $id, string $title, string $description, string $redirect_url ) {
parent::__construct();
$this->id = $id;
$this->title = $title;
$this->description = $description;
$this->redirect_url = $redirect_url;
$this->is_enabled = $is_enabled;
}
/**
@ -116,15 +106,6 @@ class SimpleRedirectTask extends Task {
return $this->redirect_url;
}
/**
* Whether the task is enabled.
*
* @return bool
*/
public function is_enabled(): bool {
return $this->is_enabled;
}
/**
* The task completion.
*

View file

@ -843,7 +843,11 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
*/
protected function register_wc_tasks( ContainerInterface $container ): void {
$simple_redirect_tasks = $container->get( 'wcgateway.settings.wc-tasks.simple-redirect-tasks' );
$task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' );
if ( empty( $simple_redirect_tasks ) ) {
return;
}
$task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' );
assert( $task_registrar instanceof TaskRegistrarInterface );
$logger = $container->get( 'woocommerce.logger.woocommerce' );