Skip to content

Commit 404e237

Browse files
committed
Remove redundant parameter() call and simplify factory
1 parent 0a4aa60 commit 404e237

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

src/Core/container-definitions.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@
4444
'notice-admin-gateway-not-enabled-monei' => DI\get( NoticeGatewayNotEnabledMonei::class ),
4545
)
4646
),
47-
ApiKeyService::class => DI\autowire(ApiKeyService::class),
48-
PaymentMethodsRepository::class => DI\factory(
49-
function (ApiKeyService $apiKeyService) {
50-
$accountId = $apiKeyService->get_account_id();
51-
return new Monei\Repositories\PaymentMethodsRepository($accountId);
52-
}
53-
)->parameter('apiKeyService', DI\get(ApiKeyService::class)),
47+
ApiKeyService::class => DI\autowire( ApiKeyService::class ),
48+
PaymentMethodsRepository::class => DI\factory(
49+
function ( ApiKeyService $apiKeyService ) {
50+
return new Monei\Repositories\PaymentMethodsRepository( $apiKeyService->get_account_id() );
51+
}
52+
),
5453
PaymentMethodsService::class => DI\create( PaymentMethodsService::class )
5554
->constructor( DI\get( PaymentMethodsRepository::class ) ),
5655
MoneiPaymentServices::class => DI\autowire( MoneiPaymentServices::class ),
@@ -66,11 +65,11 @@ function (ApiKeyService $apiKeyService) {
6665
)->constructor(
6766
DI\get( MoneiSdkClientFactory::class )
6867
),
69-
YithSubscriptionPluginHandler::class => \DI\autowire(YithSubscriptionPluginHandler::class),
68+
YithSubscriptionPluginHandler::class => \DI\autowire( YithSubscriptionPluginHandler::class ),
7069

71-
SubscriptionService::class => \DI\autowire(SubscriptionService::class)
72-
->constructorParameter('wooHandler', \DI\get(WooCommerceSubscriptionsHandler::class))
73-
->constructorParameter('yithHandler', \DI\get(YithSubscriptionPluginHandler::class)),
70+
SubscriptionService::class => \DI\autowire( SubscriptionService::class )
71+
->constructorParameter( 'wooHandler', \DI\get( WooCommerceSubscriptionsHandler::class ) )
72+
->constructorParameter( 'yithHandler', \DI\get( YithSubscriptionPluginHandler::class ) ),
7473
);
7574

7675
// Dynamically load all gateway classes in the folder

src/Gateways/Blocks/MoneiBizumBlocksSupport.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ final class MoneiBizumBlocksSupport extends AbstractPaymentMethodType {
1212

1313
private $gateway;
1414
protected $name = 'monei_bizum';
15-
protected $handler;
16-
protected SubscriptionService $subscriptions_service;
15+
protected $handler;
16+
protected SubscriptionService $subscriptions_service;
1717

18-
public function __construct( WCMoneiPaymentGateway $gateway, SubscriptionService $subscriptionService) {
19-
$this->gateway = $gateway;
20-
$this->subscriptions_service = $subscriptionService;
21-
$this->handler = $this->subscriptions_service->getHandler();
18+
public function __construct( WCMoneiPaymentGateway $gateway, SubscriptionService $subscriptionService ) {
19+
$this->gateway = $gateway;
20+
$this->subscriptions_service = $subscriptionService;
21+
$this->handler = $this->subscriptions_service->getHandler();
2222
}
2323

2424
public function initialize() {
@@ -65,24 +65,24 @@ public function is_active() {
6565
}
6666

6767
public function get_payment_method_data() {
68-
$total = isset( WC()->cart ) ? WC()->cart->get_total( false ) : 0;
69-
$cart_has_subscription = $this->handler? $this->handler->cart_has_subscription(): false;
70-
$data = array(
71-
72-
'title' => $this->gateway->title,
73-
'description' => $this->gateway->description,
74-
'logo' => WC_Monei()->plugin_url() . '/public/images/bizum-logo.svg',
75-
'supports' => $this->get_supported_features(),
76-
'currency' => get_woocommerce_currency(),
77-
'total' => $total,
78-
'language' => locale_iso_639_1_code(),
68+
$total = isset( WC()->cart ) ? WC()->cart->get_total( false ) : 0;
69+
$cart_has_subscription = $this->handler ? $this->handler->cart_has_subscription() : false;
70+
$data = array(
71+
72+
'title' => $this->gateway->title,
73+
'description' => $this->gateway->description,
74+
'logo' => WC_Monei()->plugin_url() . '/public/images/bizum-logo.svg',
75+
'supports' => $this->get_supported_features(),
76+
'currency' => get_woocommerce_currency(),
77+
'total' => $total,
78+
'language' => locale_iso_639_1_code(),
7979

8080
// yes: test mode.
8181
// no: live,
82-
'test_mode' => $this->gateway->getTestmode() ?? false,
83-
'accountId' => $this->gateway->getAccountId() ?? false,
84-
'sessionId' => ( wc()->session ) ? wc()->session->get_customer_id() : '',
85-
'cart_has_subscription' => $cart_has_subscription,
82+
'test_mode' => $this->gateway->getTestmode() ?? false,
83+
'accountId' => $this->gateway->getAccountId() ?? false,
84+
'sessionId' => ( wc()->session ) ? wc()->session->get_customer_id() : '',
85+
'cart_has_subscription' => $cart_has_subscription,
8686
);
8787

8888
if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) {

0 commit comments

Comments
 (0)