From d6515fc3e76d57009d28e9aee47725feff94f7a1 Mon Sep 17 00:00:00 2001 From: n4ss1m Date: Sun, 2 Feb 2025 23:38:54 +0100 Subject: [PATCH 1/4] refactor: activate deadCode,codeQuality,codingStyle,typeDeclarations on rector --- rector.php | 10 ++++++- .../EcotrackProviderIntegration.php | 28 +++++++++---------- .../ProcolisProviderIntegration.php | 16 +++++------ .../YalidineProviderIntegration.php | 16 +++++------ src/Services/ShippingService.php | 8 +++--- .../MaystroDeliveryProvider.php | 6 ++-- tests/Unit/Services/ShippingServiceTest.php | 26 ++++++++--------- 7 files changed, 59 insertions(+), 51 deletions(-) diff --git a/rector.php b/rector.php index c1cbd7b..96814a6 100644 --- a/rector.php +++ b/rector.php @@ -9,4 +9,12 @@ __DIR__.'/src', __DIR__.'/tests', ]) - ->withPhpSets(); + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + // privatization: true, + // naming: true, + // rectorPreset: true + )->withPhpSets(); diff --git a/src/ProviderIntegrations/EcotrackProviderIntegration.php b/src/ProviderIntegrations/EcotrackProviderIntegration.php index 4b9ef92..52672a6 100644 --- a/src/ProviderIntegrations/EcotrackProviderIntegration.php +++ b/src/ProviderIntegrations/EcotrackProviderIntegration.php @@ -61,7 +61,7 @@ public function __construct(array $credentials) $provider_name = (static::metadata())['name']; if (! isset($credentials['token'])) { - throw new CredentialsException("{$provider_name} credentials must include 'token'."); + throw new CredentialsException($provider_name." credentials must include 'token'."); } $this->credentials = $credentials; @@ -91,7 +91,7 @@ public function testCredentials(): bool // Define the headers $headers = [ - 'Authorization' => "Bearer {$this->credentials['token']}", + 'Authorization' => 'Bearer '.$this->credentials['token'], ]; // Make the GET request @@ -109,9 +109,9 @@ public function testCredentials(): bool // If the request returns any other status code, throw an HttpException default => throw new HttpException('Ecotrack '.static::metadata()['name'].', Unexpected error occurred.'), }; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -126,7 +126,7 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array // Define the headers $headers = [ - 'Authorization' => "Bearer {$this->credentials['token']}", + 'Authorization' => 'Bearer '.$this->credentials['token'], ]; // Make the GET request @@ -157,9 +157,9 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array // Return the list of shipping rates return $result['livraison']; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -191,7 +191,7 @@ public function createOrder(array $orderData): array // Define the headers $headers = [ - 'Authorization' => "Bearer {$this->credentials['token']}", + 'Authorization' => 'Bearer '.$this->credentials['token'], 'Content-Type' => 'application/json', ]; @@ -214,9 +214,9 @@ public function createOrder(array $orderData): array // Return the order response return $arrayResponse; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -231,7 +231,7 @@ public function orderLabel(string $orderId): array // Define the headers $headers = [ - 'Authorization' => "Bearer {$this->credentials['token']}", + 'Authorization' => 'Bearer '.$this->credentials['token'], ]; // Make the GET request @@ -254,7 +254,7 @@ public function orderLabel(string $orderId): array // Get the response body $label = $response->getBody()->getContents(); - if (empty($label)) { + if ($label === '' || $label === '0') { throw new HttpException('Failed to retrieve label for order with tracking ID '.$orderId.' - Empty response from Ecotrack'); } @@ -270,9 +270,9 @@ public function orderLabel(string $orderId): array 'data' => $base64data, ]; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } diff --git a/src/ProviderIntegrations/ProcolisProviderIntegration.php b/src/ProviderIntegrations/ProcolisProviderIntegration.php index ce38edc..402501b 100644 --- a/src/ProviderIntegrations/ProcolisProviderIntegration.php +++ b/src/ProviderIntegrations/ProcolisProviderIntegration.php @@ -108,9 +108,9 @@ public function testCredentials(): bool // If the request returns any other status code, throw an HttpException default => throw new HttpException('Procolis, Unexpected error occurred.'), }; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -163,9 +163,9 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array // Decode JSON response return $result; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -230,9 +230,9 @@ public function createOrder(array $orderData): array // Return the created order return $arrayResponse['Colis'][0]; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -280,9 +280,9 @@ public function getOrder(string $trackingId): array // Decode JSON response return $arrayResponse['Colis'][0]; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } diff --git a/src/ProviderIntegrations/YalidineProviderIntegration.php b/src/ProviderIntegrations/YalidineProviderIntegration.php index d80c4ca..2c8d460 100644 --- a/src/ProviderIntegrations/YalidineProviderIntegration.php +++ b/src/ProviderIntegrations/YalidineProviderIntegration.php @@ -122,9 +122,9 @@ public function testCredentials(): bool // Any other status code is considered an unexpected error throw new HttpException('Yalidine, Unexpected error occurred.'); - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -156,9 +156,9 @@ public function getRates($from_wilaya_id, $to_wilaya_id): array // Return the response body as an array return json_decode($response->getBody()->getContents(), true); - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -210,9 +210,9 @@ public function createOrder(array $orderData): array // Return the created order return $arrayResponse[$orderData['id']]; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } @@ -262,9 +262,9 @@ public function getOrder(string $trackingId): array return $data['data'][0]; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } } diff --git a/src/Services/ShippingService.php b/src/Services/ShippingService.php index 39faf99..ef5de3b 100644 --- a/src/Services/ShippingService.php +++ b/src/Services/ShippingService.php @@ -38,7 +38,7 @@ public function __construct(string $providerName, array $credentials) */ private function loadProvider(string $providerName, array $credentials): ShippingProviderContract { - $namespace = "CourierDZ\\ShippingProviders\\{$providerName}Provider"; + $namespace = sprintf('CourierDZ\ShippingProviders\%sProvider', $providerName); if (! class_exists($namespace)) { // If the provider class does not exist, throw an exception @@ -48,7 +48,7 @@ private function loadProvider(string $providerName, array $credentials): Shippin $availableProvidersNames .= $provider['name'].', '; } - throw new InvalidProviderException("Incorrect `{$providerName}` Shipping provider name, Available providers are: ".rtrim($availableProvidersNames, ', ')); + throw new InvalidProviderException(sprintf('Incorrect `%s` Shipping provider name, Available providers are: ', $providerName).rtrim($availableProvidersNames, ', ')); } // Create an instance of the provider class @@ -57,7 +57,7 @@ private function loadProvider(string $providerName, array $credentials): Shippin $providerClass = new $namespace($credentials); if (! $providerClass instanceof ShippingProviderContract) { - throw new InvalidProviderException("{$providerName}Provider must implement ShippingProviderContract or extend XyzProviderIntegration."); + throw new InvalidProviderException($providerName.'Provider must implement ShippingProviderContract or extend XyzProviderIntegration.'); } return $providerClass; @@ -207,7 +207,7 @@ public static function getProviders(): array foreach ($providersList as $file) { $className = basename($file, '.php'); - $namespace = "CourierDZ\\ShippingProviders\\{$className}"; + $namespace = 'CourierDZ\ShippingProviders\\'.$className; // Check if the class exists and implements the ShippingProviderContract if (class_exists($namespace) && is_subclass_of($namespace, ShippingProviderContract::class)) { diff --git a/src/ShippingProviders/MaystroDeliveryProvider.php b/src/ShippingProviders/MaystroDeliveryProvider.php index c2c4012..79b990e 100644 --- a/src/ShippingProviders/MaystroDeliveryProvider.php +++ b/src/ShippingProviders/MaystroDeliveryProvider.php @@ -82,7 +82,7 @@ public function testCredentials(): bool // Define the headers $headers = [ - 'Authorization' => "Token {$this->credentials['token']}", + 'Authorization' => 'Token '.$this->credentials['token'], ]; // Make the GET request @@ -100,9 +100,9 @@ public function testCredentials(): bool // If the request returns any other status code, throw an HttpException default => throw new HttpException(static::metadata()['name'].', Unexpected error occurred.'), }; - } catch (GuzzleException $e) { + } catch (GuzzleException $guzzleException) { // Handle exceptions - throw new HttpException($e->getMessage()); + throw new HttpException($guzzleException->getMessage()); } } diff --git a/tests/Unit/Services/ShippingServiceTest.php b/tests/Unit/Services/ShippingServiceTest.php index 894f7a9..6b0d248 100644 --- a/tests/Unit/Services/ShippingServiceTest.php +++ b/tests/Unit/Services/ShippingServiceTest.php @@ -9,7 +9,7 @@ use CourierDZ\Services\ShippingService; use Mockery; -test('it can boot', function () { +test('it can boot', function (): void { $service = new ShippingService(ShippingProvider::ZREXPRESS->value, ['token' => 123, 'key' => 123]); @@ -17,7 +17,7 @@ }); -it('need a credentials to boot', function () { +it('need a credentials to boot', function (): void { $courier = new CourierDZ; @@ -27,7 +27,7 @@ })->throws(CredentialsException::class); -it('need a valid credentials keys format', function () { +it('need a valid credentials keys format', function (): void { $courier = new CourierDZ; @@ -40,7 +40,7 @@ })->throws(CredentialsException::class); -it('return true if credentials are valid', function () { +it('return true if credentials are valid', function (): void { $shippingService = Mockery::mock(ShippingService::class); $shippingService->shouldReceive('testCredentials')->andReturn(true); @@ -49,7 +49,7 @@ }); -test('get create order validation rules', function () { +test('get create order validation rules', function (): void { $courier = new CourierDZ; @@ -62,7 +62,7 @@ }); -test('throw error on invalid create order data', function () { +test('throw error on invalid create order data', function (): void { $courier = new CourierDZ; @@ -75,7 +75,7 @@ })->throws(CreateOrderValidationException::class); -test('create order', function () { +test('create order', function (): void { $shippingService = Mockery::mock(ShippingService::class); $shippingService->shouldReceive('createOrder')->andReturn([]); @@ -84,13 +84,13 @@ }); -test('get order', function () {})->skip(); // @todo +test('get order', function (): void {})->skip(); // @todo -test('cancel order', function () {})->skip(); // @todo +test('cancel order', function (): void {})->skip(); // @todo -test('order label', function () {})->skip(); // @todo +test('order label', function (): void {})->skip(); // @todo -it('return array for getRates', function () { +it('return array for getRates', function (): void { $shippingService = Mockery::mock(ShippingService::class); $shippingService->shouldReceive('getRates')->andReturn([]); @@ -99,14 +99,14 @@ }); -test('get providers', function () { +test('get providers', function (): void { $providers = CourierDZ::providers(); expect($providers)->toBeArray(); }); -test('meta data', function () { +test('meta data', function (): void { $courier = new CourierDZ; From 5da3656ca2acf1b0aa8577cff5a94f0a11fafeb5 Mon Sep 17 00:00:00 2001 From: n4ss1m Date: Sun, 2 Feb 2025 23:48:16 +0100 Subject: [PATCH 2/4] refactor: activate privatization,naming on rector --- rector.php | 6 ++--- src/CourierDZ.php | 6 ++--- src/Services/ShippingService.php | 30 ++++++++++----------- src/Support/ValidatorSetup.php | 4 +-- tests/Unit/Services/ShippingServiceTest.php | 30 ++++++++++----------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/rector.php b/rector.php index 96814a6..cf70d16 100644 --- a/rector.php +++ b/rector.php @@ -14,7 +14,7 @@ codeQuality: true, codingStyle: true, typeDeclarations: true, - // privatization: true, - // naming: true, - // rectorPreset: true + privatization: true, + naming: true, + //rectorPreset: true )->withPhpSets(); diff --git a/src/CourierDZ.php b/src/CourierDZ.php index f5173b7..3fc0c71 100755 --- a/src/CourierDZ.php +++ b/src/CourierDZ.php @@ -11,14 +11,14 @@ class CourierDZ /** * Create a new ShippingService instance for the given provider. * - * @param ShippingProvider $provider The provider to use + * @param ShippingProvider $shippingProvider The provider to use * @param array $credentials The credentials to use for the provider * * @throws InvalidProviderException */ - public static function provider(ShippingProvider $provider, array $credentials): ShippingService + public static function provider(ShippingProvider $shippingProvider, array $credentials): ShippingService { - return new ShippingService($provider->value, $credentials); + return new ShippingService($shippingProvider->value, $credentials); } /** diff --git a/src/Services/ShippingService.php b/src/Services/ShippingService.php index ef5de3b..023e53c 100644 --- a/src/Services/ShippingService.php +++ b/src/Services/ShippingService.php @@ -7,7 +7,7 @@ class ShippingService { - private readonly ShippingProviderContract $provider; + private readonly ShippingProviderContract $shippingProviderContract; /** * Create a new ShippingService instance for the given provider. @@ -19,7 +19,7 @@ class ShippingService */ public function __construct(string $providerName, array $credentials) { - $this->provider = $this->loadProvider($providerName, $credentials); + $this->shippingProviderContract = $this->loadProvider($providerName, $credentials); } /** @@ -74,7 +74,7 @@ private function loadProvider(string $providerName, array $credentials): Shippin public function testCredentials(): bool { // Call the provider's testCredentials method to verify the credentials. - return $this->provider->testCredentials(); + return $this->shippingProviderContract->testCredentials(); } /** @@ -84,7 +84,7 @@ public function testCredentials(): bool */ public function getCreateOrderValidationRules(): array { - return $this->provider->getCreateOrderValidationRules(); + return $this->shippingProviderContract->getCreateOrderValidationRules(); } /** @@ -99,7 +99,7 @@ public function getCreateOrderValidationRules(): array public function validateCreate(array $orderData): bool { // Call the provider's validateCreate method to validate the order data - return $this->provider->validateCreate($orderData); + return $this->shippingProviderContract->validateCreate($orderData); } /** @@ -111,7 +111,7 @@ public function validateCreate(array $orderData): bool */ public function getRates(?int $from_wilaya_id = null, ?int $to_wilaya_id = null): array { - return $this->provider->getRates($from_wilaya_id, $to_wilaya_id); + return $this->shippingProviderContract->getRates($from_wilaya_id, $to_wilaya_id); } /** @@ -125,7 +125,7 @@ public function getRates(?int $from_wilaya_id = null, ?int $to_wilaya_id = null) */ public function createOrder(array $orderData): array { - return $this->provider->createOrder($orderData); + return $this->shippingProviderContract->createOrder($orderData); } /** @@ -139,7 +139,7 @@ public function createOrder(array $orderData): array */ public function getOrder(string $trackingId): array { - return $this->provider->getOrder($trackingId); + return $this->shippingProviderContract->getOrder($trackingId); } /** @@ -154,7 +154,7 @@ public function getOrder(string $trackingId): array public function orderLabel(string $orderId): array { // Delegate to the provider's orderLabel method to get the order label - return $this->provider->orderLabel($orderId); + return $this->shippingProviderContract->orderLabel($orderId); } // /** @@ -182,7 +182,7 @@ public function orderLabel(string $orderId): array */ public function metaData(): array { - return $this->provider->metaData(); + return $this->shippingProviderContract->metaData(); } /** @@ -199,14 +199,14 @@ public static function getProviders(): array { $providers = []; - $providersList = glob(__DIR__.'/../ShippingProviders/*Provider.php'); + $providers_filenames = glob(__DIR__.'/../ShippingProviders/*Provider.php'); - if ($providersList === false) { - $providersList = []; + if ($providers_filenames === false) { + $providers_filenames = []; } - foreach ($providersList as $file) { - $className = basename($file, '.php'); + foreach ($providers_filenames as $provider_filename) { + $className = basename($provider_filename, '.php'); $namespace = 'CourierDZ\ShippingProviders\\'.$className; // Check if the class exists and implements the ShippingProviderContract diff --git a/src/Support/ValidatorSetup.php b/src/Support/ValidatorSetup.php index b6705dc..5ae501c 100644 --- a/src/Support/ValidatorSetup.php +++ b/src/Support/ValidatorSetup.php @@ -23,11 +23,11 @@ public static function makeValidator(?string $langPath = null, string $locale = // Step 2: Create a FileLoader instance to load language files // The FileLoader is responsible for loading language files from the specified directory - $loader = new FileLoader(new Filesystem, $langPath); + $fileLoader = new FileLoader(new Filesystem, $langPath); // Step 3: Create a Translator instance with the loader and locale // The Translator is responsible for translating text using the loaded language files - $translator = new Translator($loader, $locale); + $translator = new Translator($fileLoader, $locale); // Step 4: Create and return a ValidatorFactory instance // The ValidatorFactory is the main entry point for the validation process diff --git a/tests/Unit/Services/ShippingServiceTest.php b/tests/Unit/Services/ShippingServiceTest.php index 6b0d248..6ce1288 100644 --- a/tests/Unit/Services/ShippingServiceTest.php +++ b/tests/Unit/Services/ShippingServiceTest.php @@ -42,10 +42,10 @@ it('return true if credentials are valid', function (): void { - $shippingService = Mockery::mock(ShippingService::class); - $shippingService->shouldReceive('testCredentials')->andReturn(true); + $mock = Mockery::mock(ShippingService::class); + $mock->shouldReceive('testCredentials')->andReturn(true); - expect($shippingService->testCredentials())->toBeTrue(); + expect($mock->testCredentials())->toBeTrue(); }); @@ -53,12 +53,12 @@ $courier = new CourierDZ; - $zr = $courier->provider(ShippingProvider::ZREXPRESS, [ + $shippingService = $courier->provider(ShippingProvider::ZREXPRESS, [ 'token' => '1234567890', 'key' => '1234567890', ]); - expect($zr->getCreateOrderValidationRules())->toBeArray(); + expect($shippingService->getCreateOrderValidationRules())->toBeArray(); }); @@ -66,21 +66,21 @@ $courier = new CourierDZ; - $zr = $courier->provider(ShippingProvider::ZREXPRESS, [ + $shippingService = $courier->provider(ShippingProvider::ZREXPRESS, [ 'token' => '1234567890', 'key' => '1234567890', ]); - $zr->createOrder([]); + $shippingService->createOrder([]); })->throws(CreateOrderValidationException::class); test('create order', function (): void { - $shippingService = Mockery::mock(ShippingService::class); - $shippingService->shouldReceive('createOrder')->andReturn([]); + $mock = Mockery::mock(ShippingService::class); + $mock->shouldReceive('createOrder')->andReturn([]); - expect($shippingService->createOrder([]))->toBeArray(); + expect($mock->createOrder([]))->toBeArray(); }); @@ -92,10 +92,10 @@ it('return array for getRates', function (): void { - $shippingService = Mockery::mock(ShippingService::class); - $shippingService->shouldReceive('getRates')->andReturn([]); + $mock = Mockery::mock(ShippingService::class); + $mock->shouldReceive('getRates')->andReturn([]); - expect($shippingService->getRates())->toBeArray(); + expect($mock->getRates())->toBeArray(); }); @@ -110,11 +110,11 @@ $courier = new CourierDZ; - $zr = $courier->provider(ShippingProvider::ZREXPRESS, [ + $shippingService = $courier->provider(ShippingProvider::ZREXPRESS, [ 'token' => '1234567890', 'key' => '1234567890', ]); - expect($zr->metaData())->toBeArray(); + expect($shippingService->metaData())->toBeArray(); }); From afdc626ea4ce49ccae8a094ce738786dfbf5788c Mon Sep 17 00:00:00 2001 From: n4ss1m Date: Sun, 2 Feb 2025 23:54:30 +0100 Subject: [PATCH 3/4] refactor: adding strict_types=1 --- rector.php | 21 +++++++++++-------- src/Contracts/ShippingProviderContract.php | 2 ++ src/CourierDZ.php | 2 ++ src/Enum/ShippingProvider.php | 2 ++ src/Exceptions/CreateOrderException.php | 2 ++ .../CreateOrderValidationException.php | 2 ++ src/Exceptions/CredentialsException.php | 2 ++ .../FunctionNotSupportedException.php | 2 ++ src/Exceptions/HttpException.php | 2 ++ src/Exceptions/InvalidProviderException.php | 2 ++ src/Exceptions/NotImplementedException.php | 2 ++ .../TrackingIdNotFoundException.php | 2 ++ .../EcotrackProviderIntegration.php | 2 ++ .../ProcolisProviderIntegration.php | 2 ++ .../YalidineProviderIntegration.php | 2 ++ src/Services/ShippingService.php | 2 ++ src/ShippingProviders/ConexlogProvider.php | 2 ++ src/ShippingProviders/DhdProvider.php | 2 ++ .../MaystroDeliveryProvider.php | 2 ++ src/ShippingProviders/YalidineProvider.php | 2 ++ src/ShippingProviders/YalitecProvider.php | 2 ++ src/ShippingProviders/ZRExpressProvider.php | 2 ++ src/Support/ShippingProviderValidation.php | 2 ++ src/Support/ValidatorSetup.php | 2 ++ src/Support/lang/fr/validation.php | 2 ++ tests/Unit/Services/ShippingServiceTest.php | 2 ++ 26 files changed, 62 insertions(+), 9 deletions(-) diff --git a/rector.php b/rector.php index cf70d16..82547d1 100644 --- a/rector.php +++ b/rector.php @@ -3,18 +3,21 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Set\ValueObject\SetList; return RectorConfig::configure() ->withPaths([ __DIR__.'/src', __DIR__.'/tests', ]) - ->withPreparedSets( - deadCode: true, - codeQuality: true, - codingStyle: true, - typeDeclarations: true, - privatization: true, - naming: true, - //rectorPreset: true - )->withPhpSets(); + ->withSets([ + SetList::DEAD_CODE, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::TYPE_DECLARATION, + SetList::PRIVATIZATION, + SetList::NAMING, + SetList::RECTOR_PRESET, + SetList::STRICT_BOOLEANS, + ]) + ->withPhpSets(); diff --git a/src/Contracts/ShippingProviderContract.php b/src/Contracts/ShippingProviderContract.php index 6bff4ef..269ddfe 100644 --- a/src/Contracts/ShippingProviderContract.php +++ b/src/Contracts/ShippingProviderContract.php @@ -1,5 +1,7 @@ 'is required.', 'string' => 'must be a string.', diff --git a/tests/Unit/Services/ShippingServiceTest.php b/tests/Unit/Services/ShippingServiceTest.php index 6ce1288..082e2a4 100644 --- a/tests/Unit/Services/ShippingServiceTest.php +++ b/tests/Unit/Services/ShippingServiceTest.php @@ -1,5 +1,7 @@ Date: Sun, 2 Feb 2025 23:57:16 +0100 Subject: [PATCH 4/4] refactor: adding rector STRICT_BOOLEANS,EARLY_RETURN, INSTANCEOF --- rector.php | 2 ++ src/ProviderIntegrations/EcotrackProviderIntegration.php | 2 +- src/ProviderIntegrations/ProcolisProviderIntegration.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index 82547d1..db0845d 100644 --- a/rector.php +++ b/rector.php @@ -19,5 +19,7 @@ SetList::NAMING, SetList::RECTOR_PRESET, SetList::STRICT_BOOLEANS, + SetList::EARLY_RETURN, + SetList::INSTANCEOF, ]) ->withPhpSets(); diff --git a/src/ProviderIntegrations/EcotrackProviderIntegration.php b/src/ProviderIntegrations/EcotrackProviderIntegration.php index 9159da1..018cdd4 100644 --- a/src/ProviderIntegrations/EcotrackProviderIntegration.php +++ b/src/ProviderIntegrations/EcotrackProviderIntegration.php @@ -144,7 +144,7 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array $result = json_decode($body, true); // If the to_wilaya_id is specified, filter the result to only include the specified wilaya - if ($to_wilaya_id) { + if ($to_wilaya_id !== null && $to_wilaya_id !== 0) { foreach ($result['livraison'] as $wilaya) { if ($wilaya['wilaya_id'] == $to_wilaya_id) { // Return the first matching wilaya diff --git a/src/ProviderIntegrations/ProcolisProviderIntegration.php b/src/ProviderIntegrations/ProcolisProviderIntegration.php index 5316b6e..c96422e 100644 --- a/src/ProviderIntegrations/ProcolisProviderIntegration.php +++ b/src/ProviderIntegrations/ProcolisProviderIntegration.php @@ -144,7 +144,7 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array $result = json_decode($body, true); // If the to_wilaya_id is specified, filter the result to only include the specified wilaya - if ($to_wilaya_id) { + if ($to_wilaya_id !== null && $to_wilaya_id !== 0) { $filteredResult = []; foreach ($result as $wilaya) { if ($wilaya['IDWilaya'] == $to_wilaya_id) {