Skip to content

Commit eb53879

Browse files
committed
chore: add PHPCS rule to enforce use statements over fully qualified names
- Install slevomat/coding-standard package - Add ReferenceUsedNamesOnly rule to phpcs.xml - Auto-fix 59 violations across 12 files - Enforces use statements for classes, functions, and constants - Prevents \Fully\Qualified\Names in favor of imports This ensures consistent code style and better IDE support.
1 parent 248d8bb commit eb53879

12 files changed

+75
-59
lines changed

includes/class-wc-monei-ipn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function handle_valid_ipn( $payload ) {
168168
if ( $payment_method_display ) {
169169
$order->update_meta_data( '_monei_payment_method_display', $payment_method_display );
170170
}
171-
} catch ( \Exception $e ) {
171+
} catch ( Exception $e ) {
172172
// Log but don't fail - payment method display is not critical
173173
WC_Monei_Logger::log( '[MONEI] Failed to get payment method display: ' . $e->getMessage(), 'warning' );
174174
}

src/Core/container-definitions.php

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
use Monei\Templates\NoticeGatewayNotEnabledMonei;
2121
use Monei\Templates\SettingsHeader;
2222
use Monei\Templates\TemplateManager;
23+
use function DI\autowire;
24+
use function DI\create;
25+
use function DI\get;
26+
use function DI\factory;
2327

2428
$blocksPath = dirname( __DIR__, 1 ) . '/Gateways/Blocks';
2529
$gatewayPath = dirname( __DIR__, 1 ) . '/Gateways/PaymentMethods';
@@ -28,62 +32,62 @@
2832
$definitions = array(
2933
// ========== TEMPLATES ==========
3034
// Register each template as an autowired service
31-
NoticeAdminNewInstall::class => DI\autowire( NoticeAdminNewInstall::class ),
32-
SettingsHeader::class => DI\autowire( SettingsHeader::class ),
33-
NoticeAdminDependency::class => DI\autowire( NoticeAdminDependency::class ),
34-
NoticeGatewayNotAvailable::class => DI\autowire( NoticeGatewayNotAvailable::class ),
35-
NoticeGatewayNotAvailableApi::class => DI\autowire( NoticeGatewayNotAvailableApi::class ),
36-
NoticeGatewayNotEnabledMonei::class => DI\autowire( NoticeGatewayNotEnabledMonei::class ),
35+
NoticeAdminNewInstall::class => autowire( NoticeAdminNewInstall::class ),
36+
SettingsHeader::class => autowire( SettingsHeader::class ),
37+
NoticeAdminDependency::class => autowire( NoticeAdminDependency::class ),
38+
NoticeGatewayNotAvailable::class => autowire( NoticeGatewayNotAvailable::class ),
39+
NoticeGatewayNotAvailableApi::class => autowire( NoticeGatewayNotAvailableApi::class ),
40+
NoticeGatewayNotEnabledMonei::class => autowire( NoticeGatewayNotEnabledMonei::class ),
3741

3842
// array of [ 'short-template-name' => <template-class-instance> ]
39-
TemplateManager::class => DI\create( TemplateManager::class )
43+
TemplateManager::class => create( TemplateManager::class )
4044
->constructor(
4145
array(
42-
'notice-admin-new-install' => DI\get( NoticeAdminNewInstall::class ),
43-
'monei-settings-header' => DI\get( SettingsHeader::class ),
44-
'notice-admin-dependency' => DI\get( NoticeAdminDependency::class ),
45-
'notice-admin-gateway-not-available' => DI\get( NoticeGatewayNotAvailable::class ),
46-
'notice-admin-gateway-not-available-api' => DI\get( NoticeGatewayNotAvailableApi::class ),
47-
'notice-admin-gateway-not-enabled-monei' => DI\get( NoticeGatewayNotEnabledMonei::class ),
46+
'notice-admin-new-install' => get( NoticeAdminNewInstall::class ),
47+
'monei-settings-header' => get( SettingsHeader::class ),
48+
'notice-admin-dependency' => get( NoticeAdminDependency::class ),
49+
'notice-admin-gateway-not-available' => get( NoticeGatewayNotAvailable::class ),
50+
'notice-admin-gateway-not-available-api' => get( NoticeGatewayNotAvailableApi::class ),
51+
'notice-admin-gateway-not-enabled-monei' => get( NoticeGatewayNotEnabledMonei::class ),
4852
)
4953
),
50-
ApiKeyService::class => DI\autowire( ApiKeyService::class ),
51-
MoneiSdkClientFactory::class => DI\autowire( MoneiSdkClientFactory::class )
52-
->constructor( DI\get( ApiKeyService::class ) ),
53-
PaymentMethodsRepository::class => DI\factory(
54+
ApiKeyService::class => autowire( ApiKeyService::class ),
55+
MoneiSdkClientFactory::class => autowire( MoneiSdkClientFactory::class )
56+
->constructor( get( ApiKeyService::class ) ),
57+
PaymentMethodsRepository::class => factory(
5458
function ( ApiKeyService $apiKeyService, MoneiSdkClientFactory $sdkClientFactory ) {
55-
return new Monei\Repositories\PaymentMethodsRepository( $apiKeyService->get_account_id(), $sdkClientFactory->get_client() );
59+
return new PaymentMethodsRepository( $apiKeyService->get_account_id(), $sdkClientFactory->get_client() );
5660
}
5761
),
58-
PaymentMethodsService::class => DI\create( PaymentMethodsService::class )
59-
->constructor( DI\get( PaymentMethodsRepository::class ) ),
60-
CardBrandHelper::class => DI\create( CardBrandHelper::class )
61-
->constructor( DI\get( PaymentMethodsService::class ) ),
62-
MoneiPaymentServices::class => DI\autowire( MoneiPaymentServices::class ),
63-
MoneiStatusCodeHandler::class => DI\autowire( MoneiStatusCodeHandler::class ),
64-
PaymentMethodFormatter::class => DI\autowire( PaymentMethodFormatter::class ),
65-
BlockSupportService::class => DI\create( BlockSupportService::class )
62+
PaymentMethodsService::class => create( PaymentMethodsService::class )
63+
->constructor( get( PaymentMethodsRepository::class ) ),
64+
CardBrandHelper::class => create( CardBrandHelper::class )
65+
->constructor( get( PaymentMethodsService::class ) ),
66+
MoneiPaymentServices::class => autowire( MoneiPaymentServices::class ),
67+
MoneiStatusCodeHandler::class => autowire( MoneiStatusCodeHandler::class ),
68+
PaymentMethodFormatter::class => autowire( PaymentMethodFormatter::class ),
69+
BlockSupportService::class => create( BlockSupportService::class )
6670
->constructor( $blocksPath, $blockNamespacePrefix ),
67-
MoneiApplePayVerificationService::class => DI\autowire( MoneiApplePayVerificationService::class )
68-
->constructor( DI\get( MoneiPaymentServices::class ) ),
69-
WooCommerceSubscriptionsHandler::class => \DI\create(
71+
MoneiApplePayVerificationService::class => autowire( MoneiApplePayVerificationService::class )
72+
->constructor( get( MoneiPaymentServices::class ) ),
73+
WooCommerceSubscriptionsHandler::class => create(
7074
WooCommerceSubscriptionsHandler::class,
7175
)->constructor(
72-
DI\get( MoneiSdkClientFactory::class )
76+
get( MoneiSdkClientFactory::class )
7377
),
74-
YithSubscriptionPluginHandler::class => \DI\autowire( YithSubscriptionPluginHandler::class ),
78+
YithSubscriptionPluginHandler::class => autowire( YithSubscriptionPluginHandler::class ),
7579

76-
SubscriptionService::class => \DI\autowire( SubscriptionService::class )
77-
->constructorParameter( 'wooHandler', \DI\get( WooCommerceSubscriptionsHandler::class ) )
78-
->constructorParameter( 'yithHandler', \DI\get( YithSubscriptionPluginHandler::class ) ),
80+
SubscriptionService::class => autowire( SubscriptionService::class )
81+
->constructorParameter( 'wooHandler', get( WooCommerceSubscriptionsHandler::class ) )
82+
->constructorParameter( 'yithHandler', get( YithSubscriptionPluginHandler::class ) ),
7983
);
8084

8185
// Dynamically load all gateway classes in the folder
8286
foreach ( glob( $gatewayPath . '/*.php' ) as $file ) {
8387
$className = $gatewayNamespacePrefix . pathinfo( $file, PATHINFO_FILENAME );
8488

8589
if ( class_exists( $className ) ) {
86-
$definitions[ $className ] = DI\autowire();
90+
$definitions[ $className ] = autowire();
8791
}
8892
}
8993

@@ -96,13 +100,13 @@ function ( ApiKeyService $apiKeyService, MoneiSdkClientFactory $sdkClientFactory
96100
$gatewayClassName = $gatewayNamespacePrefix . $gatewayNamePrefix . str_replace( 'BlocksSupport', '', pathinfo( $file, PATHINFO_FILENAME ) );
97101

98102
// Register the block support class with the gateway as a dependency
99-
$definitions[ $blockClassName ] = DI\autowire()
100-
->constructorParameter( 'gateway', DI\get( $gatewayClassName ) );
103+
$definitions[ $blockClassName ] = autowire()
104+
->constructorParameter( 'gateway', get( $gatewayClassName ) );
101105

102106
// Inject CardBrandHelper only for CC blocks support
103107
if ( $blockClassName === 'Monei\\Gateways\\Blocks\\MoneiCCBlocksSupport' ) {
104108
$definitions[ $blockClassName ] = $definitions[ $blockClassName ]
105-
->constructorParameter( 'cardBrandHelper', DI\get( CardBrandHelper::class ) );
109+
->constructorParameter( 'cardBrandHelper', get( CardBrandHelper::class ) );
106110
}
107111
}
108112
}

src/Features/Subscriptions/WooCommerceSubscriptionsHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Monei\Services\payment\MoneiPaymentServices;
77
use Monei\Services\sdk\MoneiSdkClientFactory;
88
use WC_Order;
9+
use Exception;
10+
use WC_Monei_Logger;
11+
use WC_Subscriptions_Product;
912

1013
class WooCommerceSubscriptionsHandler implements SubscriptionHandlerInterface {
1114

@@ -184,9 +187,9 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
184187
}
185188
$renewal_order->save();
186189

187-
} catch ( \Exception $e ) {
190+
} catch ( Exception $e ) {
188191
do_action( 'wc_gateway_monei_scheduled_subscription_payment_error', $e, $renewal_order, $amount_to_charge );
189-
\WC_Monei_Logger::log( $e, 'error' );
192+
WC_Monei_Logger::log( $e, 'error' );
190193
$renewal_order->update_status( 'failed' );
191194
$renewal_order->add_order_note( __( 'Error Renewal scheduled_subscription_payment. Reason: ', 'monei' ) . $e->getMessage() );
192195
$renewal_order->save();
@@ -232,9 +235,9 @@ public function init_subscriptions( array $supports, string $gateway_id ): array
232235
}
233236
public function get_cart_subscription_interval_in_days() {
234237
foreach ( WC()->cart->cart_contents as $cart_item ) {
235-
if ( \WC_Subscriptions_Product::is_subscription( $cart_item['data'] ) ) {
236-
$interval = \WC_Subscriptions_Product::get_interval( $cart_item['data'] );
237-
$period = \WC_Subscriptions_Product::get_period( $cart_item['data'] );
238+
if ( WC_Subscriptions_Product::is_subscription( $cart_item['data'] ) ) {
239+
$interval = WC_Subscriptions_Product::get_interval( $cart_item['data'] );
240+
$period = WC_Subscriptions_Product::get_period( $cart_item['data'] );
238241
break;
239242
}
240243
}

src/Features/Subscriptions/YithSubscriptionPluginHandler.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Monei\Services\payment\MoneiPaymentServices;
66
use Monei\Services\sdk\MoneiSdkClientFactory;
77
use WC_Order;
8+
use WC_Monei_Logger;
9+
use Exception;
810

911
class YithSubscriptionPluginHandler implements SubscriptionHandlerInterface {
1012
private $moneiPaymentServices;
@@ -14,7 +16,7 @@ public function __construct( MoneiSdkClientFactory $sdkClient ) {
1416
add_action(
1517
'ywsbs_pay_renew_order_with_' . MONEI_GATEWAY_ID,
1618
function ( $renew_order ) {
17-
if ( ! $renew_order instanceof \WC_Order ) {
19+
if ( ! $renew_order instanceof WC_Order ) {
1820
return false;
1921
}
2022
$amount_to_charge = $renew_order->get_total();
@@ -207,7 +209,7 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
207209
$sequence_id = $this->get_sequence_id_from_subscription( $subscription );
208210

209211
if ( ! $subscription || 'yes' !== $is_a_renew ) {
210-
\WC_Monei_Logger::log( sprintf( 'Sorry, any subscription was found for order #%s or order is not a renew.', $order_id ), 'subscription_payment' );
212+
WC_Monei_Logger::log( sprintf( 'Sorry, any subscription was found for order #%s or order is not a renew.', $order_id ), 'subscription_payment' );
211213
}
212214
$payload = array(
213215
'orderId' => (string) $renewal_order->get_id(),
@@ -238,9 +240,9 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
238240
}
239241
$renewal_order->save();
240242

241-
} catch ( \Exception $e ) {
243+
} catch ( Exception $e ) {
242244
do_action( 'wc_gateway_monei_scheduled_subscription_payment_error', $e, $renewal_order, $amount_to_charge );
243-
\WC_Monei_Logger::log( $e, 'error' );
245+
WC_Monei_Logger::log( $e, 'error' );
244246
$renewal_order->update_status( 'failed' );
245247
$renewal_order->add_order_note( __( 'Error Renewal scheduled_subscription_payment. Reason: ', 'monei' ) . $e->getMessage() );
246248
$renewal_order->save();
@@ -257,7 +259,7 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
257259
* @return \YWSBS_Subscription|false
258260
*/
259261
// @phpstan-ignore-next-line
260-
private function get_subscription_from_renew_order( \WC_Order $renewal_order ) {
262+
private function get_subscription_from_renew_order( WC_Order $renewal_order ) {
261263
$subscriptions = $renewal_order->get_meta( 'subscriptions' );
262264
$subscription_id = ! empty( $subscriptions ) ? array_shift( $subscriptions ) : false; // $subscriptions is always an array of 1 element.
263265

src/Gateways/Abstracts/WCMoneiPaymentGatewayHosted.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use WC_Geolocation;
88
use WC_Order;
99
use WC_Payment_Tokens;
10+
use Monei\ApiException;
1011

1112
if ( ! defined( 'ABSPATH' ) ) {
1213
exit;
@@ -160,7 +161,7 @@ public function process_payment( $order_id, $allowed_payment_method = null ) {
160161
'result' => 'success',
161162
'redirect' => $payment->getNextAction()->getRedirectUrl(),
162163
);
163-
} catch ( \Monei\ApiException $e ) {
164+
} catch ( ApiException $e ) {
164165
do_action( 'wc_gateway_monei_process_payment_error', $e, $order );
165166
// Parse API exception and get user-friendly error message
166167
$error_info = $this->statusCodeHandler->parse_api_exception( $e );

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Monei\Templates\TemplateManager;
1212
use WC_Blocks_Utils;
1313
use WC_Monei_IPN;
14+
use WC_Admin_Settings;
1415

1516
if ( ! defined( 'ABSPATH' ) ) {
1617
exit;
@@ -143,7 +144,7 @@ public function validate_payment_request_style_field( $key, $value ) {
143144

144145
// Check for JSON errors
145146
if ( json_last_error() !== JSON_ERROR_NONE ) {
146-
\WC_Admin_Settings::add_error(
147+
WC_Admin_Settings::add_error(
147148
sprintf(
148149
/* translators: %s: JSON error message */
149150
__( 'Apple Pay / Google Pay Style field contains invalid JSON: %s', 'monei' ),

src/Gateways/PaymentMethods/WCGatewayMoneiBizum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Monei\Templates\TemplateManager;
1111
use WC_Monei_IPN;
1212
use WC_Monei_Payment_Gateway_Hosted;
13+
use WC_Admin_Settings;
1314

1415
if ( ! defined( 'ABSPATH' ) ) {
1516
exit;
@@ -147,7 +148,7 @@ public function validate_bizum_style_field( $key, $value ) {
147148

148149
// Check for JSON errors
149150
if ( json_last_error() !== JSON_ERROR_NONE ) {
150-
\WC_Admin_Settings::add_error(
151+
WC_Admin_Settings::add_error(
151152
sprintf(
152153
/* translators: %s: JSON error message */
153154
__( 'Bizum Style field contains invalid JSON: %s', 'monei' ),

src/Gateways/PaymentMethods/WCGatewayMoneiCC.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Monei\Templates\TemplateManager;
1515
use WC_Geolocation;
1616
use WC_Monei_IPN;
17+
use WC_Admin_Settings;
1718

1819
if ( ! defined( 'ABSPATH' ) ) {
1920
exit;
@@ -210,7 +211,7 @@ public function validate_card_input_style_field( $key, $value ) {
210211

211212
// Check for JSON errors
212213
if ( json_last_error() !== JSON_ERROR_NONE ) {
213-
\WC_Admin_Settings::add_error(
214+
WC_Admin_Settings::add_error(
214215
sprintf(
215216
/* translators: %s: JSON error message */
216217
__( 'Card Input Style field contains invalid JSON: %s', 'monei' ),

src/Gateways/PaymentMethods/WCGatewayMoneiPaypal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Monei\Templates\TemplateManager;
1111
use WC_Monei_IPN;
1212
use WC_Monei_Payment_Gateway_Hosted;
13+
use WC_Admin_Settings;
1314

1415
if ( ! defined( 'ABSPATH' ) ) {
1516
exit;
@@ -150,7 +151,7 @@ public function validate_paypal_style_field( $key, $value ) {
150151

151152
// Check for JSON errors
152153
if ( json_last_error() !== JSON_ERROR_NONE ) {
153-
\WC_Admin_Settings::add_error(
154+
WC_Admin_Settings::add_error(
154155
sprintf(
155156
/* translators: %s: JSON error message */
156157
__( 'PayPal Style field contains invalid JSON: %s', 'monei' ),

src/Repositories/PaymentMethodsRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Monei\Repositories;
44

55
use Monei\MoneiClient;
6+
use Exception;
67

78
class PaymentMethodsRepository implements PaymentMethodsRepositoryInterface {
89
private $accountId;
@@ -22,7 +23,7 @@ private function fetchFromAPI(): ?array {
2223
}
2324
try {
2425
$response = $this->moneiClient->paymentMethods->get( $this->accountId );
25-
} catch ( \Exception $e ) {
26+
} catch ( Exception $e ) {
2627
$response = null;
2728
}
2829

0 commit comments

Comments
 (0)