mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Early return instead of complicating the task
This commit is contained in:
parent
42a6cb2b45
commit
137a8b4975
5 changed files with 18 additions and 32 deletions
|
@ -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§ion={$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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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' );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue