Skip to content

Commit

Permalink
refactor: run rector
Browse files Browse the repository at this point in the history
  • Loading branch information
n4ss1m committed Feb 2, 2025
1 parent 2000c7c commit 2b0f79a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 44 deletions.
28 changes: 12 additions & 16 deletions src/ProviderIntegrations/EcotrackProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,20 @@ public function testCredentials(): bool
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/wilayas', [
$response = $client->request('GET', static::apiDomain().'api/v1/get/wilayas', [
'headers' => $headers,
'Content-Type' => 'application/json',
]);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return true;
case 401:
case 403:
// If the request returns a 401 or 403 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException('Ecotrack '.$this->metadata()['name'].', Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => true,
// If the request returns a 401 or 403 status code, return false
401, 403 => false,
// 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) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand All @@ -134,7 +130,7 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/fees', [
$response = $client->request('GET', static::apiDomain().'api/v1/get/fees', [
'headers' => $headers,
'Content-Type' => 'application/json',
]);
Expand Down Expand Up @@ -200,7 +196,7 @@ public function createOrder(array $orderData): array
];

// Make the POST request
$request = new Request('POST', $this->apiDomain().'api/v1/create/order', $headers, $requestBody);
$request = new Request('POST', static::apiDomain().'api/v1/create/order', $headers, $requestBody);

$response = $client->send($request);

Expand Down Expand Up @@ -239,7 +235,7 @@ public function orderLabel(string $orderId): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/order/label?tracking='.$orderId, [
$response = $client->request('GET', static::apiDomain().'api/v1/get/order/label?tracking='.$orderId, [
'headers' => $headers,
'Content-Type' => 'application/json',
]);
Expand Down
19 changes: 8 additions & 11 deletions src/ProviderIntegrations/ProcolisProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,14 @@ public function testCredentials(): bool
$data = json_decode($body, true);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return $data['Statut'] === 'Accès activé';
case 401:
// If the request returns a 401 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException('Procolis, Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => $data['Statut'] === 'Accès activé',
// If the request returns a 401 status code, return false
401 => false,
// If the request returns any other status code, throw an HttpException
default => throw new HttpException('Procolis, Unexpected error occurred.'),
};
} catch (GuzzleException $e) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand Down
6 changes: 3 additions & 3 deletions src/ProviderIntegrations/YalidineProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testCredentials(): bool
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'/v1/wilayas/', [
$response = $client->request('GET', static::apiDomain().'/v1/wilayas/', [
'headers' => $headers,
]);

Expand Down Expand Up @@ -149,7 +149,7 @@ public function getRates($from_wilaya_id, $to_wilaya_id): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'/v1/fees/?from_wilaya_id='.$from_wilaya_id.'&to_wilaya_id='.$to_wilaya_id, [
$response = $client->request('GET', static::apiDomain().'/v1/fees/?from_wilaya_id='.$from_wilaya_id.'&to_wilaya_id='.$to_wilaya_id, [
'headers' => $headers,
]);

Expand Down Expand Up @@ -191,7 +191,7 @@ public function createOrder(array $orderData): array
throw new CreateOrderException('Create Order failed : JSON encoding error');
}

$request = new Request('POST', $this->apiDomain().'/v1/parcels/', $headers, $requestBody);
$request = new Request('POST', static::apiDomain().'/v1/parcels/', $headers, $requestBody);

$response = $client->send($request);

Expand Down
2 changes: 1 addition & 1 deletion src/Services/ShippingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ShippingService
{
private ShippingProviderContract $provider;
private readonly ShippingProviderContract $provider;

/**
* Create a new ShippingService instance for the given provider.
Expand Down
20 changes: 8 additions & 12 deletions src/ShippingProviders/MaystroDeliveryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ public function testCredentials(): bool
]);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return true;
case 401:
case 403:
// If the request returns a 401 or 403 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException($this->metadata()['name'].', Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => true,
// If the request returns a 401 or 403 status code, return false
401, 403 => false,
// If the request returns any other status code, throw an HttpException
default => throw new HttpException(static::metadata()['name'].', Unexpected error occurred.'),
};
} catch (GuzzleException $e) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/Support/ValidatorSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ValidatorSetup
public static function makeValidator(?string $langPath = null, string $locale = 'fr'): ValidatorFactory
{
// Step 1: Set default language files directory
$langPath = $langPath ?? __DIR__.'/lang';
$langPath ??= __DIR__.'/lang';

// Step 2: Create a FileLoader instance to load language files
// The FileLoader is responsible for loading language files from the specified directory
Expand Down

0 comments on commit 2b0f79a

Please sign in to comment.