diff --git a/.gitattributes b/.gitattributes index aa8ebc7..89ae305 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,9 @@ # Path-based git attributes # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + # Ignore all test and documentation with "export-ignore". /.github export-ignore /.gitattributes export-ignore diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml deleted file mode 100644 index 56d54d3..0000000 --- a/.github/workflows/fix-php-code-style-issues.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Fix PHP code style issues - -on: - push: - paths: - - '**.php' - -permissions: - contents: write - -jobs: - php-code-styling: - runs-on: ubuntu-latest - timeout-minutes: 5 - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@2.4 - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 01ae751..acc4951 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,15 +1,10 @@ name: Tests on: - push: - paths: - - '**.php' - - '.github/workflows/run-tests.yml' - - 'phpunit.xml.dist' - - 'composer.json' - - 'composer.lock' pull_request: - branches: [ "*" ] + branches: [ "main" ] + push: + branches: [ "main" ] jobs: test: @@ -18,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] php: [8.2, 8.3, 8.4] stability: [prefer-lowest, prefer-stable] @@ -33,7 +28,10 @@ jobs: with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo - coverage: none + coverage: xdebug + + - name: Validate composer.json + run: composer validate --strict - name: Setup problem matchers run: | @@ -46,8 +44,10 @@ jobs: - name: List Installed Dependencies run: composer show -D - - name: PHPStan Analyse - run: composer analyse - - name: Execute tests - run: vendor/bin/pest + run: composer test + + - name: Upload coverage results to Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: vendor/bin/php-coveralls -v --coverage_clover=build/logs/clover.xml diff --git a/.gitignore b/.gitignore index c69d8ef..c99b550 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ testbench.yaml /docs /coverage /demo +.coveralls.yml diff --git a/README.md b/README.md index f97147d..dc0bc8b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ CourierDZ Banner -[![Latest Version on Packagist](https://img.shields.io/packagist/v/piteurstudio/courierdz.svg?style=flat-square)](https://packagist.org/packages/piteurstudio/courierdz) -[![Tests](https://img.shields.io/github/actions/workflow/status/piteurstudio/courierdz/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/piteurstudio/courierdz/actions/workflows/run-tests.yml) -[![Total Downloads](https://img.shields.io/packagist/dt/piteurstudio/courierdz.svg?style=flat-square)](https://packagist.org/packages/piteurstudio/courierdz) +

+ PHP 8.2 + Latest Version on Packagist + Tests + Coverage Status + Total Downloads +

# CourierDZ diff --git a/composer.json b/composer.json index d0cbba9..bca90be 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,12 @@ "illuminate/validation": "^9|^10|^11" }, "require-dev": { - "laravel/pint": "^1.0", + "laravel/pint": "^1.20.0", "mockery/mockery": "^1.6", - "pestphp/pest": "^1.0|^2.0|^3.0", + "pestphp/pest": "^2.20 || ^3.0", + "php-coveralls/php-coveralls": "^2.7.0", "phpstan/phpstan": "^2.0", + "rector/rector": "^2.0", "spatie/ray": "^1.28" }, "autoload": { @@ -51,10 +53,18 @@ } }, "scripts": { - "test": "vendor/bin/pest", - "test-coverage": "vendor/bin/pest --coverage", - "analyse": "vendor/bin/phpstan", - "format": "vendor/bin/pint" + "lint": "pint", + "refactor": "rector", + "test:unit": "pest --coverage --min=25", + "test:lint": "pint --test", + "test:refactor": "rector --dry-run", + "test:types": "phpstan", + "test": [ + "@test:unit", + "@test:lint", + "@test:types", + "@test:refactor" + ] }, "config": { "sort-packages": true, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6a901b6..779e6b3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ backupStaticProperties="false" > - + tests diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..c1cbd7b --- /dev/null +++ b/rector.php @@ -0,0 +1,12 @@ +withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withPhpSets(); diff --git a/src/ProviderIntegrations/EcotrackProviderIntegration.php b/src/ProviderIntegrations/EcotrackProviderIntegration.php index c212795..4b9ef92 100644 --- a/src/ProviderIntegrations/EcotrackProviderIntegration.php +++ b/src/ProviderIntegrations/EcotrackProviderIntegration.php @@ -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()); @@ -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', ]); @@ -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); @@ -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', ]); diff --git a/src/ProviderIntegrations/ProcolisProviderIntegration.php b/src/ProviderIntegrations/ProcolisProviderIntegration.php index 31d3931..ce38edc 100644 --- a/src/ProviderIntegrations/ProcolisProviderIntegration.php +++ b/src/ProviderIntegrations/ProcolisProviderIntegration.php @@ -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()); diff --git a/src/ProviderIntegrations/YalidineProviderIntegration.php b/src/ProviderIntegrations/YalidineProviderIntegration.php index 5fba5ab..d80c4ca 100644 --- a/src/ProviderIntegrations/YalidineProviderIntegration.php +++ b/src/ProviderIntegrations/YalidineProviderIntegration.php @@ -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, ]); @@ -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, ]); @@ -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); diff --git a/src/Services/ShippingService.php b/src/Services/ShippingService.php index dec721c..39faf99 100644 --- a/src/Services/ShippingService.php +++ b/src/Services/ShippingService.php @@ -7,7 +7,7 @@ class ShippingService { - private ShippingProviderContract $provider; + private readonly ShippingProviderContract $provider; /** * Create a new ShippingService instance for the given provider. diff --git a/src/ShippingProviders/MaystroDeliveryProvider.php b/src/ShippingProviders/MaystroDeliveryProvider.php index a6f4c44..c2c4012 100644 --- a/src/ShippingProviders/MaystroDeliveryProvider.php +++ b/src/ShippingProviders/MaystroDeliveryProvider.php @@ -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()); diff --git a/src/Support/ValidatorSetup.php b/src/Support/ValidatorSetup.php index 80d6f78..b6705dc 100644 --- a/src/Support/ValidatorSetup.php +++ b/src/Support/ValidatorSetup.php @@ -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 diff --git a/tests/Services/ShippingServiceTest.php b/tests/Unit/Services/ShippingServiceTest.php similarity index 100% rename from tests/Services/ShippingServiceTest.php rename to tests/Unit/Services/ShippingServiceTest.php