From 5b53a32c5d467052a8a640e6735909a1a6be5b9c Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Wed, 21 Jun 2023 04:35:12 +0300 Subject: [PATCH 01/16] Refactor --- .github/workflows/testing.yml | 4 +- README.md | 9 +- composer.json | 2 +- src/Client.php | 45 +--------- src/Exception/API/APIException.php | 84 +++++++++++++++++++ src/Exception/API/AccountOnHoldException.php | 15 ++++ src/Exception/API/ExpectedPriceException.php | 32 +++++++ src/Exception/API/GoneException.php | 16 ++++ .../API/InvalidRequestParamsException.php | 15 ++++ .../{Api => API}/LowSuccessRateException.php | 16 +--- .../API/PaymentRequiredException.php | 18 ++++ .../ResourceBadStateException.php} | 12 ++- .../API/ResourceNotFoundException.php | 18 ++++ .../ServiceUnavailableException.php | 14 +--- .../TemporaryErrorInterface.php} | 6 +- .../TooManyActivationsPendingException.php | 14 +--- .../TooManyRequestsException.php} | 10 +-- .../API/UnauthorizedServiceException.php | 18 ++++ src/Exception/Api/ApiException.php | 34 -------- src/Exception/Api/ExpectedPriceException.php | 28 ------- src/Exception/Api/GoneException.php | 21 ----- .../Api/InvalidRequestParamsException.php | 21 ----- .../Api/PaymentRequiredException.php | 27 ------ .../Api/ResourceBadStateException.php | 35 -------- .../Api/TooManyRequestsException.php | 29 ------- .../Api/UnauthorizedServiceException.php | 27 ------ src/Exception/ClientException.php | 1 + tests/unit/ClientTest.php | 4 +- 28 files changed, 246 insertions(+), 329 deletions(-) create mode 100644 src/Exception/API/APIException.php create mode 100644 src/Exception/API/AccountOnHoldException.php create mode 100644 src/Exception/API/ExpectedPriceException.php create mode 100644 src/Exception/API/GoneException.php create mode 100644 src/Exception/API/InvalidRequestParamsException.php rename src/Exception/{Api => API}/LowSuccessRateException.php (58%) create mode 100644 src/Exception/API/PaymentRequiredException.php rename src/Exception/{Api/ResourceNotFoundException.php => API/ResourceBadStateException.php} (53%) create mode 100644 src/Exception/API/ResourceNotFoundException.php rename src/Exception/{Api => API}/ServiceUnavailableException.php (53%) rename src/Exception/{Api/TemporaryExceptionInterface.php => API/TemporaryErrorInterface.php} (80%) rename src/Exception/{Api => API}/TooManyActivationsPendingException.php (52%) rename src/Exception/{Api/AccountOnHoldException.php => API/TooManyRequestsException.php} (51%) create mode 100644 src/Exception/API/UnauthorizedServiceException.php delete mode 100644 src/Exception/Api/ApiException.php delete mode 100644 src/Exception/Api/ExpectedPriceException.php delete mode 100644 src/Exception/Api/GoneException.php delete mode 100644 src/Exception/Api/InvalidRequestParamsException.php delete mode 100644 src/Exception/Api/PaymentRequiredException.php delete mode 100644 src/Exception/Api/ResourceBadStateException.php delete mode 100644 src/Exception/Api/TooManyRequestsException.php delete mode 100644 src/Exception/Api/UnauthorizedServiceException.php diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c575252..2b8d36c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -2,9 +2,7 @@ name: PHP Test on: push: - branches: [ "master" ] pull_request: - branches: [ "master" ] permissions: contents: read @@ -21,7 +19,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - + - name: Validate composer.json and composer.lock run: composer validate --strict diff --git a/README.md b/README.md index f55b55e..0665808 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# tempnumber-api-client +# TempNumber Api Client An API client for Temp-Number service ( https://temp-number.org/ ) written in PHP. @@ -7,7 +7,7 @@ If you encounter a bug or have an idea to improve the code, feel free to open an ## Installation ```` -$ Composer require ahmedghanem00/tempnumber-api-client +$ composer require ahmedghanem00/tempnumber-api-client ```` ## Usage @@ -64,7 +64,7 @@ In case you have specific activation that needs to be retried ````php try { - $client->retryActivation($newActivation->getId()); + $client->retryActivation(181822); } catch (Exception $e) { echo $e->getMessage(); } @@ -139,5 +139,6 @@ foreach ($result->activations() as $activation) { } ```` +## LICENSE -## +Package is licensed under the [MIT License](http://opensource.org/licenses/MIT). diff --git a/composer.json b/composer.json index a0dcc99..4b8fe13 100644 --- a/composer.json +++ b/composer.json @@ -45,5 +45,5 @@ "phpstan": "@php vendor/bin/phpstan analyse src tests" }, - "minimum-stability": "dev" + "minimum-stability": "stable" } diff --git a/src/Client.php b/src/Client.php index a223be1..7e045c3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -14,19 +14,7 @@ use ahmedghanem00\TempNumberClient\Enum\Country; use ahmedghanem00\TempNumberClient\Enum\Service; use ahmedghanem00\TempNumberClient\Enum\TempNumberServer; -use ahmedghanem00\TempNumberClient\Exception\Api\AccountOnHoldException; -use ahmedghanem00\TempNumberClient\Exception\Api\ApiException; -use ahmedghanem00\TempNumberClient\Exception\Api\ExpectedPriceException; -use ahmedghanem00\TempNumberClient\Exception\Api\GoneException; -use ahmedghanem00\TempNumberClient\Exception\Api\InvalidRequestParamsException; -use ahmedghanem00\TempNumberClient\Exception\Api\LowSuccessRateException; -use ahmedghanem00\TempNumberClient\Exception\Api\PaymentRequiredException; -use ahmedghanem00\TempNumberClient\Exception\Api\ResourceBadStateException; -use ahmedghanem00\TempNumberClient\Exception\Api\ResourceNotFoundException; -use ahmedghanem00\TempNumberClient\Exception\Api\ServiceUnavailableException; -use ahmedghanem00\TempNumberClient\Exception\Api\TooManyActivationsPendingException; -use ahmedghanem00\TempNumberClient\Exception\Api\TooManyRequestsException; -use ahmedghanem00\TempNumberClient\Exception\Api\UnauthorizedServiceException; +use ahmedghanem00\TempNumberClient\Exception\API\APIException; use ahmedghanem00\TempNumberClient\Exception\ClientException; use ahmedghanem00\TempNumberClient\Result\ActivationHistoryResult; use ahmedghanem00\TempNumberClient\Result\ActivationResult; @@ -162,41 +150,12 @@ private function checkAndGetResultDataFromResponse(ResponseInterface $response): $resultData = $response->toArray(false); if (@$errorName = $resultData['errorName']) { - $this->handleApiError($errorName, $resultData, $response); + throw APIException::newFromErrorName($errorName, $response); } return $resultData; } - /** - * @param string $errorName - * @param array $resultData - * @param ResponseInterface $response - * @return void - */ - private function handleApiError(string $errorName, array $resultData, ResponseInterface $response): void - { - $exception = match ($errorName) { - 'UnauthorizedException' => new UnauthorizedServiceException(), - 'InvalidRequestParamsException' => new InvalidRequestParamsException(), - 'paymentRequired' => new PaymentRequiredException(), - 'AccountOnHoldException' => new AccountOnHoldException(), - 'ResourceNotFoundException' => new ResourceNotFoundException(), - 'ResourceBadStateException' => new ResourceBadStateException(), - 'TooManyActivationsPendingException' => new TooManyActivationsPendingException(), - 'TooManyRequestsException' => new TooManyRequestsException(), - 'expectedPriceErrorException' => new ExpectedPriceException($resultData['newPrice']), - 'GoneException' => new GoneException(), - 'lowSuccessRateException' => new LowSuccessRateException(), - 'ServiceUnavailableException' => new ServiceUnavailableException(), - default => new ApiException() - }; - - $exception->setResponse($response); - - throw $exception; - } - /** * @throws TransportExceptionInterface * @throws ServerExceptionInterface diff --git a/src/Exception/API/APIException.php b/src/Exception/API/APIException.php new file mode 100644 index 0000000..257f7fe --- /dev/null +++ b/src/Exception/API/APIException.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +use ahmedghanem00\TempNumberClient\Exception\ClientException; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\ResponseInterface; + +/** + * + */ +class APIException extends ClientException +{ + public const Description = "API Failed Action"; + + /** + * @param ResponseInterface $response + */ + public function __construct( + private ResponseInterface $response + ) + { + parent::__construct(static::Description); + } + + /** + * @param string $errorName + * @param ResponseInterface $response + * @return static + */ + public static function newFromErrorName(string $errorName, ResponseInterface $response): self + { + $exceptionClass = match (strtolower($errorName)) { + 'unauthorizedexception' => UnauthorizedServiceException::class, + 'invalidrequestparamsexception' => InvalidRequestParamsException::class, + 'paymentrequired' => PaymentRequiredException::class, + 'accountonholdexception' => AccountOnHoldException::class, + 'resourcenotfoundexception' => ResourceNotFoundException::class, + 'resourcebadstateexception' => ResourceBadStateException::class, + 'toomanyactivationspendingexception' => TooManyActivationsPendingException::class, + 'toomanyrequestsexception' => TooManyRequestsException::class, + 'expectedpriceerrorexception' => ExpectedPriceException::class, + 'goneexception' => GoneException::class, + 'lowsuccessrateexception' => LowSuccessRateException::class, + 'serviceunavailableexception' => ServiceUnavailableException::class, + + default => self::class + }; + + return new $exceptionClass($response); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function getResultData(): array + { + return $this->getResponse()->toArray(false); + } + + /** + * @return ResponseInterface + */ + public function getResponse(): ResponseInterface + { + return $this->response; + } +} diff --git a/src/Exception/API/AccountOnHoldException.php b/src/Exception/API/AccountOnHoldException.php new file mode 100644 index 0000000..b4da218 --- /dev/null +++ b/src/Exception/API/AccountOnHoldException.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +class AccountOnHoldException extends APIException +{ +} diff --git a/src/Exception/API/ExpectedPriceException.php b/src/Exception/API/ExpectedPriceException.php new file mode 100644 index 0000000..9a691de --- /dev/null +++ b/src/Exception/API/ExpectedPriceException.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; + +class ExpectedPriceException extends APIException +{ + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function getNewPrice(): float + { + return (float)$this->getResultData()['newPrice']; + } +} diff --git a/src/Exception/API/GoneException.php b/src/Exception/API/GoneException.php new file mode 100644 index 0000000..005de7e --- /dev/null +++ b/src/Exception/API/GoneException.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +class GoneException extends APIException +{ + public const Description = "The target resource is no longer available"; +} diff --git a/src/Exception/API/InvalidRequestParamsException.php b/src/Exception/API/InvalidRequestParamsException.php new file mode 100644 index 0000000..5a90cf4 --- /dev/null +++ b/src/Exception/API/InvalidRequestParamsException.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +class InvalidRequestParamsException extends APIException +{ +} diff --git a/src/Exception/Api/LowSuccessRateException.php b/src/Exception/API/LowSuccessRateException.php similarity index 58% rename from src/Exception/Api/LowSuccessRateException.php rename to src/Exception/API/LowSuccessRateException.php index 90c64f1..c69d872 100644 --- a/src/Exception/Api/LowSuccessRateException.php +++ b/src/Exception/API/LowSuccessRateException.php @@ -8,26 +8,16 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; +namespace ahmedghanem00\TempNumberClient\Exception\API; /** * * Example: 100 activations requested for Whatsapp in Germany but only 1 activation got sms. - * This is 1% delivery success rate. No more activations allowed in 24 hours to Whatsapp in the Netherlands. + * This is 1% delivery success rate. No more activations allowed in 24 hours to Whatsapp in the Germany. * */ -class LowSuccessRateException extends ApiException implements TemporaryExceptionInterface +class LowSuccessRateException extends APIException implements TemporaryErrorInterface { - /** - * - */ - public function __construct() - { - ClientException::__construct("Activations low success rate"); - } - /** * @return int */ diff --git a/src/Exception/API/PaymentRequiredException.php b/src/Exception/API/PaymentRequiredException.php new file mode 100644 index 0000000..74087b5 --- /dev/null +++ b/src/Exception/API/PaymentRequiredException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +/** + * + */ +class PaymentRequiredException extends APIException +{ +} diff --git a/src/Exception/Api/ResourceNotFoundException.php b/src/Exception/API/ResourceBadStateException.php similarity index 53% rename from src/Exception/Api/ResourceNotFoundException.php rename to src/Exception/API/ResourceBadStateException.php index 6587eab..5bfc955 100644 --- a/src/Exception/Api/ResourceNotFoundException.php +++ b/src/Exception/API/ResourceBadStateException.php @@ -8,20 +8,18 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; +namespace ahmedghanem00\TempNumberClient\Exception\API; /** * */ -class ResourceNotFoundException extends ApiException +class ResourceBadStateException extends APIException implements TemporaryErrorInterface { /** - * + * @return int */ - public function __construct() + public function retryAfter(): int { - ClientException::__construct("Resource not found"); + return 10 * 60; } } diff --git a/src/Exception/API/ResourceNotFoundException.php b/src/Exception/API/ResourceNotFoundException.php new file mode 100644 index 0000000..8dbb9b5 --- /dev/null +++ b/src/Exception/API/ResourceNotFoundException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +/** + * + */ +class ResourceNotFoundException extends APIException +{ +} diff --git a/src/Exception/Api/ServiceUnavailableException.php b/src/Exception/API/ServiceUnavailableException.php similarity index 53% rename from src/Exception/Api/ServiceUnavailableException.php rename to src/Exception/API/ServiceUnavailableException.php index 88f20a8..fbaa24f 100644 --- a/src/Exception/Api/ServiceUnavailableException.php +++ b/src/Exception/API/ServiceUnavailableException.php @@ -8,23 +8,13 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; +namespace ahmedghanem00\TempNumberClient\Exception\API; /** * */ -class ServiceUnavailableException extends ApiException implements TemporaryExceptionInterface +class ServiceUnavailableException extends APIException implements TemporaryErrorInterface { - /** - * - */ - public function __construct() - { - ClientException::__construct('Service Unavailable'); - } - /** * @return int */ diff --git a/src/Exception/Api/TemporaryExceptionInterface.php b/src/Exception/API/TemporaryErrorInterface.php similarity index 80% rename from src/Exception/Api/TemporaryExceptionInterface.php rename to src/Exception/API/TemporaryErrorInterface.php index 83b5a4d..7b3bebf 100644 --- a/src/Exception/Api/TemporaryExceptionInterface.php +++ b/src/Exception/API/TemporaryErrorInterface.php @@ -8,17 +8,15 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; +namespace ahmedghanem00\TempNumberClient\Exception\API; /** * */ -interface TemporaryExceptionInterface +interface TemporaryErrorInterface { - /** * @return int Seconds to wait before making next retry */ public function retryAfter(): int; - } diff --git a/src/Exception/Api/TooManyActivationsPendingException.php b/src/Exception/API/TooManyActivationsPendingException.php similarity index 52% rename from src/Exception/Api/TooManyActivationsPendingException.php rename to src/Exception/API/TooManyActivationsPendingException.php index 06721db..1e0a5c1 100644 --- a/src/Exception/Api/TooManyActivationsPendingException.php +++ b/src/Exception/API/TooManyActivationsPendingException.php @@ -8,23 +8,13 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; +namespace ahmedghanem00\TempNumberClient\Exception\API; /** * */ -class TooManyActivationsPendingException extends ApiException implements TemporaryExceptionInterface +class TooManyActivationsPendingException extends APIException implements TemporaryErrorInterface { - /** - * - */ - public function __construct() - { - ClientException::__construct("Too many activations pending"); - } - /** * @return int */ diff --git a/src/Exception/Api/AccountOnHoldException.php b/src/Exception/API/TooManyRequestsException.php similarity index 51% rename from src/Exception/Api/AccountOnHoldException.php rename to src/Exception/API/TooManyRequestsException.php index 5cfb8ed..a0ae066 100644 --- a/src/Exception/Api/AccountOnHoldException.php +++ b/src/Exception/API/TooManyRequestsException.php @@ -8,14 +8,12 @@ * file that was distributed with this source code. */ -namespace ahmedghanem00\TempNumberClient\Exception\Api; +namespace ahmedghanem00\TempNumberClient\Exception\API; -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -class AccountOnHoldException extends ApiException +class TooManyRequestsException extends APIException implements TemporaryErrorInterface { - public function __construct() + public function retryAfter(): int { - ClientException::__construct("Account is in hold state"); + return 0; } } diff --git a/src/Exception/API/UnauthorizedServiceException.php b/src/Exception/API/UnauthorizedServiceException.php new file mode 100644 index 0000000..a789c81 --- /dev/null +++ b/src/Exception/API/UnauthorizedServiceException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ahmedghanem00\TempNumberClient\Exception\API; + +/** + * + */ +class UnauthorizedServiceException extends APIException +{ +} diff --git a/src/Exception/Api/ApiException.php b/src/Exception/Api/ApiException.php deleted file mode 100644 index 5e9c91f..0000000 --- a/src/Exception/Api/ApiException.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; -use Symfony\Contracts\HttpClient\ResponseInterface; - -class ApiException extends ClientException -{ - private ResponseInterface $response; - - public function __construct() - { - parent::__construct('API Error'); - } - - public function getResponse(): ResponseInterface - { - return $this->response; - } - - public function setResponse(ResponseInterface $response): void - { - $this->response = $response; - } -} diff --git a/src/Exception/Api/ExpectedPriceException.php b/src/Exception/Api/ExpectedPriceException.php deleted file mode 100644 index 1bad3fa..0000000 --- a/src/Exception/Api/ExpectedPriceException.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -class ExpectedPriceException extends ApiException -{ - public function __construct( - private readonly float $newPrice - ) - { - ClientException::__construct("Activation price has changed to ( $newPrice ) which is greater than the expected"); - } - - public function getNewPrice(): float - { - return $this->newPrice; - } -} diff --git a/src/Exception/Api/GoneException.php b/src/Exception/Api/GoneException.php deleted file mode 100644 index ec0e5c0..0000000 --- a/src/Exception/Api/GoneException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -class GoneException extends ApiException -{ - public function __construct() - { - ClientException::__construct("The target resource is no longer available"); - } -} diff --git a/src/Exception/Api/InvalidRequestParamsException.php b/src/Exception/Api/InvalidRequestParamsException.php deleted file mode 100644 index 988cf67..0000000 --- a/src/Exception/Api/InvalidRequestParamsException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -class InvalidRequestParamsException extends ApiException -{ - public function __construct() - { - ClientException::__construct("Invalid request params"); - } -} diff --git a/src/Exception/Api/PaymentRequiredException.php b/src/Exception/Api/PaymentRequiredException.php deleted file mode 100644 index 6cd542f..0000000 --- a/src/Exception/Api/PaymentRequiredException.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -/** - * - */ -class PaymentRequiredException extends ApiException -{ - /** - * - */ - public function __construct() - { - ClientException::__construct("Looks like the current balance is not enough to perform this request"); - } -} diff --git a/src/Exception/Api/ResourceBadStateException.php b/src/Exception/Api/ResourceBadStateException.php deleted file mode 100644 index 71ff146..0000000 --- a/src/Exception/Api/ResourceBadStateException.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -/** - * - */ -class ResourceBadStateException extends ApiException implements TemporaryExceptionInterface -{ - /** - * - */ - public function __construct() - { - ClientException::__construct("Resource is in a bad state"); - } - - /** - * @return int - */ - public function retryAfter(): int - { - return 10 * 60; - } -} diff --git a/src/Exception/Api/TooManyRequestsException.php b/src/Exception/Api/TooManyRequestsException.php deleted file mode 100644 index d0d25e0..0000000 --- a/src/Exception/Api/TooManyRequestsException.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -class TooManyRequestsException extends ApiException implements TemporaryExceptionInterface -{ - /** - * - */ - public function __construct() - { - ClientException::__construct("Too many requests"); - } - - public function retryAfter(): int - { - return 0; - } -} diff --git a/src/Exception/Api/UnauthorizedServiceException.php b/src/Exception/Api/UnauthorizedServiceException.php deleted file mode 100644 index 18eb668..0000000 --- a/src/Exception/Api/UnauthorizedServiceException.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ahmedghanem00\TempNumberClient\Exception\Api; - -use ahmedghanem00\TempNumberClient\Exception\ClientException; - -/** - * - */ -class UnauthorizedServiceException extends ApiException -{ - /** - * - */ - public function __construct() - { - ClientException::__construct('Unauthorized access to this resource. Please recheck the configured api token'); - } -} diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index 4fa2bea..c7055d7 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -20,6 +20,7 @@ class ClientException extends RuntimeException public function __construct(string $message = "", int $code = 0, Throwable $previous = null, array $additionalData = []) { $this->additionalData = $additionalData; + parent::__construct($message, $code, $previous); } diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index bf95336..f500235 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -103,7 +103,7 @@ public function testRetryActivation() $this->client->retryActivation(7378322); $this->assertTrue(true); } catch (Exception $e) { - $this->fail($e->getMessage()); + throw $e; } } @@ -229,7 +229,7 @@ protected function setUp(): void $this->client = new Client(getenv('API_KEY'), null, $backendServer); $this->client->applyHttpClientOptions([ - #'proxy' => '127.0.0.1:9090', 'verify_peer' => false, + 'proxy' => '127.0.0.1:9090', 'verify_peer' => false, ]); } } From af0a1d479e1ccdb2503316d9c1cdcbd495adfc0d Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Wed, 21 Jun 2023 04:37:11 +0300 Subject: [PATCH 02/16] Fix --- tests/unit/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index f500235..2f70969 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -229,7 +229,7 @@ protected function setUp(): void $this->client = new Client(getenv('API_KEY'), null, $backendServer); $this->client->applyHttpClientOptions([ - 'proxy' => '127.0.0.1:9090', 'verify_peer' => false, + # 'proxy' => '127.0.0.1:9090', 'verify_peer' => false, ]); } } From 44a3afa0b1e52780f13473cbdd66c4167ed9fe72 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Fri, 11 Aug 2023 02:05:21 +0300 Subject: [PATCH 03/16] Add [SensitiveParameter] to $apiKey --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 7e045c3..744c155 100644 --- a/src/Client.php +++ b/src/Client.php @@ -53,6 +53,7 @@ class Client * @param TempNumberServer $backendServer */ public function __construct( + #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, TempNumberServer $backendServer = TempNumberServer::Production @@ -68,7 +69,7 @@ public function __construct( * @param string $apiKey * @return void */ - public function setApiKey(string $apiKey): void + public function setApiKey(#[\SensitiveParameter] string $apiKey): void { $this->applyHttpClientOptions([ 'headers' => [ From 087a2cc68916736d1362f7912b3e24a0a6f9dac1 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Wed, 1 May 2024 20:08:01 +0300 Subject: [PATCH 04/16] Allow symfony/http-client versions 6 & 7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4b8fe13..88e7c00 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "require": { "php": ">=8.2", - "symfony/http-client": "6.*", + "symfony/http-client": "6.* || 7.*", "doctrine/collections": "2.*" }, From bc1446c4647e48fe12ad4289f2ba028c89c55e7f Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 4 May 2024 01:47:31 +0300 Subject: [PATCH 05/16] Ignore PHP-CS-Fixer Cache file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8feb9b8..0233d94 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.phpunit.cache/ /composer.lock /phpunit.xml +/.php-cs-fixer.cache From b69db666258e1ae30cce788fc699faa50ff07ab1 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 4 May 2024 01:49:24 +0300 Subject: [PATCH 06/16] Reform GitHub workflows --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 31 ++++++++++++++++++++++++ .github/workflows/testing.yml | 42 -------------------------------- composer.json | 14 ++++++----- 4 files changed, 84 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a36fc96 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + - push + - pull_request + +jobs: + tests: + name: Tests + + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + + matrix: + os: + - ubuntu-latest + - windows-latest + + php-version: + - 8.2 + - 8.3 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On + + - name: Install dependencies with Composer + run: composer install --prefer-dist --no-ansi --no-interaction --no-progress + + - name: Run PHP-CS-Fixer in Linter Mode + run: composer run-script php-cs-fixer -- --dry-run --show-progress=dots --using-cache=no --verbose + + - name: Run PHPStan + run: composer run-script phpstan + + - name: Run test-suites + run: composer run-script test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..35d2b99 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Release + +on: + push: + tags: + - "**" + +jobs: + create-release: + name: Create Release + + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Determine tag + run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Create release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.RELEASE_TAG }} + name: v${{ env.RELEASE_TAG }} + generateReleaseNotes: true + diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml deleted file mode 100644 index 2b8d36c..0000000 --- a/.github/workflows/testing.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: PHP Test - -on: - push: - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run test suite - run: composer run-script test - - - name: Run PHP-Stan - run: composer run-script phpstan diff --git a/composer.json b/composer.json index 88e7c00..34f4c52 100644 --- a/composer.json +++ b/composer.json @@ -30,19 +30,21 @@ }, "require": { - "php": ">=8.2", - "symfony/http-client": "6.* || 7.*", - "doctrine/collections": "2.*" + "php": "^8.2", + "symfony/http-client": "^6.0 || ^7.0", + "doctrine/collections": "^2.0" }, "require-dev": { "phpunit/phpunit": "dev-main", - "phpstan/phpstan": "1.10.x-dev" + "phpstan/phpstan": "1.10.x-dev", + "friendsofphp/php-cs-fixer": "^3.54" }, "scripts": { - "test": "@php vendor/bin/phpunit", - "phpstan": "@php vendor/bin/phpstan analyse src tests" + "styling": "@php vendor/bin/php-cs-fixer fix src", + "phpstan": "@php vendor/bin/phpstan analyse src tests", + "test": "@php vendor/bin/phpunit" }, "minimum-stability": "stable" From 0eed5921a0592da16426fc20a52c43a7f996bd47 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:22:54 +0300 Subject: [PATCH 07/16] Add .gitattributes --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..895ffd6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +/.github/ export-ignore +/tests/ export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.php-cs-fixer.dist.php export-ignore +/phpstan.dist.neon export-ignore +/phpstan-baseline.neon export-ignore +/phpunit.xml.dist export-ignore + From b8f232366569707874268d9d0406ec34516a3d10 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:27:57 +0300 Subject: [PATCH 08/16] Add configuration file for PHPStan --- phpstan-baseline.neon | 9 +++++++++ phpstan.dist.neon | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.dist.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..bfb5304 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,9 @@ +parameters: + ignoreErrors: + - message: "#^Method ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\:\\:newFromErrorName\\(\\) should return static\\(ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\) but returns ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\.$#" + count: 1 + path: src/Exception/API/APIException.php + + - message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 2 + path: tests/unit/ClientTest.php diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..38ad328 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,11 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 5 + + paths: + - src/ + - tests/ + + reportUnmatchedIgnoredErrors: true From d7168944922a2d4bfeec604809d7d6e7c3e8065a Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:30:05 +0300 Subject: [PATCH 09/16] Refactoring ... --- composer.json | 6 +++--- src/Client.php | 2 +- src/Enum/TempNumberServer.php | 10 ++++++++++ src/Exception/API/APIException.php | 2 +- tests/unit/ClientTest.php | 22 +++++----------------- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 34f4c52..657b990 100644 --- a/composer.json +++ b/composer.json @@ -42,9 +42,9 @@ }, "scripts": { - "styling": "@php vendor/bin/php-cs-fixer fix src", - "phpstan": "@php vendor/bin/phpstan analyse src tests", - "test": "@php vendor/bin/phpunit" + "test": "vendor/bin/phpunit", + "phpstan": "vendor/bin/phpstan analyse", + "php-cs-fixer": "vendor/bin/php-cs-fixer fix" }, "minimum-stability": "stable" diff --git a/src/Client.php b/src/Client.php index 744c155..07da576 100644 --- a/src/Client.php +++ b/src/Client.php @@ -79,7 +79,7 @@ public function setApiKey(#[\SensitiveParameter] string $apiKey): void } /** - * @param array $options + * @param array $options * @return void */ public function applyHttpClientOptions(array $options): void diff --git a/src/Enum/TempNumberServer.php b/src/Enum/TempNumberServer.php index ee367f4..6b848e9 100644 --- a/src/Enum/TempNumberServer.php +++ b/src/Enum/TempNumberServer.php @@ -15,4 +15,14 @@ enum TempNumberServer: string case Production = 'https://tn-api.com/api/v1/'; case Mock = 'https://mock.temp-number.org/v1/'; + + public static function fromName(string $name): self + { + foreach (self::cases() as $status) { + if ($name === $status->name) { + return $status; + } + } + throw new \ValueError("$name is not a valid backing value for enum " . self::class); + } } diff --git a/src/Exception/API/APIException.php b/src/Exception/API/APIException.php index 257f7fe..353f3ed 100644 --- a/src/Exception/API/APIException.php +++ b/src/Exception/API/APIException.php @@ -40,7 +40,7 @@ public function __construct( * @param ResponseInterface $response * @return static */ - public static function newFromErrorName(string $errorName, ResponseInterface $response): self + public static function newFromErrorName(string $errorName, ResponseInterface $response): static { $exceptionClass = match (strtolower($errorName)) { 'unauthorizedexception' => UnauthorizedServiceException::class, diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index 2f70969..abeabe7 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -15,6 +15,7 @@ use ahmedghanem00\TempNumberClient\Enum\Service; use ahmedghanem00\TempNumberClient\Enum\TempNumberServer; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; @@ -22,9 +23,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -/** - * @covers Client - */ +#[CoversClass(Client::class)] class ClientTest extends TestCase { /** @@ -33,8 +32,6 @@ class ClientTest extends TestCase private Client $client; /** - * @covers Client::retrieveBalance - * * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface @@ -99,12 +96,8 @@ public function testRequestNewActivation() */ public function testRetryActivation() { - try { - $this->client->retryActivation(7378322); - $this->assertTrue(true); - } catch (Exception $e) { - throw $e; - } + $this->client->retryActivation(7378322); + $this->assertTrue(true); } /** @@ -217,14 +210,9 @@ public function testRetrievePriceListByCountry() } } - /** - * @return void - */ protected function setUp(): void { - $backendServer = current(array_filter(TempNumberServer::cases(), function ($case) { - return $case->name === getenv('BACKEND_SERVER'); - })); + $backendServer = TempNumberServer::fromName(getenv('BACKEND_SERVER')); $this->client = new Client(getenv('API_KEY'), null, $backendServer); From 4466caef29aef529777acef88cd7453fd375e12a Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:31:08 +0300 Subject: [PATCH 10/16] Add PHP-CS-Fixer configuration file --- .php-cs-fixer.dist.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .php-cs-fixer.dist.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..5608d5d --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +$header = << + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +$finder = PhpCsFixer\Finder::create() + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/tests') + ->ignoreVCSIgnored(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + '@PSR12:risky' => true + ]) + ->setUsingCache(true) + ->setRiskyAllowed(true) + ->setFinder($finder); From a932628ebf122a61b256e83dbdef2d4b1bcba8ee Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:35:09 +0300 Subject: [PATCH 11/16] Applying PHP-CS-Fixer --- src/Client.php | 15 ++++++++++++--- src/Enum/ActivationStatus.php | 12 +++++++++++- src/Enum/Country.php | 12 +++++++++++- src/Enum/Service.php | 12 +++++++++++- src/Enum/TempNumberServer.php | 12 +++++++++++- src/Exception/API/APIException.php | 15 ++++++++++++--- src/Exception/API/AccountOnHoldException.php | 12 +++++++++++- src/Exception/API/ExpectedPriceException.php | 12 +++++++++++- src/Exception/API/GoneException.php | 12 +++++++++++- .../API/InvalidRequestParamsException.php | 12 +++++++++++- src/Exception/API/LowSuccessRateException.php | 12 +++++++++++- src/Exception/API/PaymentRequiredException.php | 12 +++++++++++- src/Exception/API/ResourceBadStateException.php | 12 +++++++++++- src/Exception/API/ResourceNotFoundException.php | 12 +++++++++++- src/Exception/API/ServiceUnavailableException.php | 12 +++++++++++- src/Exception/API/TemporaryErrorInterface.php | 12 +++++++++++- .../API/TooManyActivationsPendingException.php | 12 +++++++++++- src/Exception/API/TooManyRequestsException.php | 12 +++++++++++- .../API/UnauthorizedServiceException.php | 12 +++++++++++- src/Exception/ClientException.php | 12 +++++++++++- src/Result/AbstractResult.php | 15 ++++++++++++--- src/Result/ActivationHistoryResult.php | 12 +++++++++++- src/Result/ActivationResult.php | 12 +++++++++++- src/Result/CountryResult.php | 12 +++++++++++- src/Result/CountryServiceInfoResult.php | 12 +++++++++++- src/Result/ServiceResult.php | 12 +++++++++++- tests/unit/ClientTest.php | 12 +++++++++++- 27 files changed, 300 insertions(+), 33 deletions(-) diff --git a/src/Client.php b/src/Client.php index 07da576..c5be1e2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * @@ -57,8 +67,7 @@ public function __construct( string $apiKey, ?HttpClientInterface $httpClient = null, TempNumberServer $backendServer = TempNumberServer::Production - ) - { + ) { $this->setHttpClient($httpClient ?? HttpClient::create()); $this->setApiKey($apiKey); $this->setBackendServer($backendServer); diff --git a/src/Enum/ActivationStatus.php b/src/Enum/ActivationStatus.php index 52d045e..3704da5 100644 --- a/src/Enum/ActivationStatus.php +++ b/src/Enum/ActivationStatus.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Enum/Country.php b/src/Enum/Country.php index 98eeafd..3b3b06b 100644 --- a/src/Enum/Country.php +++ b/src/Enum/Country.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Enum/Service.php b/src/Enum/Service.php index f4ed49d..14c0ccd 100644 --- a/src/Enum/Service.php +++ b/src/Enum/Service.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Enum/TempNumberServer.php b/src/Enum/TempNumberServer.php index 6b848e9..dd06112 100644 --- a/src/Enum/TempNumberServer.php +++ b/src/Enum/TempNumberServer.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/APIException.php b/src/Exception/API/APIException.php index 353f3ed..7996339 100644 --- a/src/Exception/API/APIException.php +++ b/src/Exception/API/APIException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * @@ -30,8 +40,7 @@ class APIException extends ClientException */ public function __construct( private ResponseInterface $response - ) - { + ) { parent::__construct(static::Description); } diff --git a/src/Exception/API/AccountOnHoldException.php b/src/Exception/API/AccountOnHoldException.php index b4da218..bec5b98 100644 --- a/src/Exception/API/AccountOnHoldException.php +++ b/src/Exception/API/AccountOnHoldException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/ExpectedPriceException.php b/src/Exception/API/ExpectedPriceException.php index 9a691de..e508041 100644 --- a/src/Exception/API/ExpectedPriceException.php +++ b/src/Exception/API/ExpectedPriceException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/GoneException.php b/src/Exception/API/GoneException.php index 005de7e..4c214d9 100644 --- a/src/Exception/API/GoneException.php +++ b/src/Exception/API/GoneException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/InvalidRequestParamsException.php b/src/Exception/API/InvalidRequestParamsException.php index 5a90cf4..71e60f6 100644 --- a/src/Exception/API/InvalidRequestParamsException.php +++ b/src/Exception/API/InvalidRequestParamsException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/LowSuccessRateException.php b/src/Exception/API/LowSuccessRateException.php index c69d872..5d26bbe 100644 --- a/src/Exception/API/LowSuccessRateException.php +++ b/src/Exception/API/LowSuccessRateException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/PaymentRequiredException.php b/src/Exception/API/PaymentRequiredException.php index 74087b5..6f8e2d9 100644 --- a/src/Exception/API/PaymentRequiredException.php +++ b/src/Exception/API/PaymentRequiredException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/ResourceBadStateException.php b/src/Exception/API/ResourceBadStateException.php index 5bfc955..4aced9b 100644 --- a/src/Exception/API/ResourceBadStateException.php +++ b/src/Exception/API/ResourceBadStateException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/ResourceNotFoundException.php b/src/Exception/API/ResourceNotFoundException.php index 8dbb9b5..54b3fb3 100644 --- a/src/Exception/API/ResourceNotFoundException.php +++ b/src/Exception/API/ResourceNotFoundException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/ServiceUnavailableException.php b/src/Exception/API/ServiceUnavailableException.php index fbaa24f..e044910 100644 --- a/src/Exception/API/ServiceUnavailableException.php +++ b/src/Exception/API/ServiceUnavailableException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/TemporaryErrorInterface.php b/src/Exception/API/TemporaryErrorInterface.php index 7b3bebf..8193122 100644 --- a/src/Exception/API/TemporaryErrorInterface.php +++ b/src/Exception/API/TemporaryErrorInterface.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/TooManyActivationsPendingException.php b/src/Exception/API/TooManyActivationsPendingException.php index 1e0a5c1..fc2bfa8 100644 --- a/src/Exception/API/TooManyActivationsPendingException.php +++ b/src/Exception/API/TooManyActivationsPendingException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/TooManyRequestsException.php b/src/Exception/API/TooManyRequestsException.php index a0ae066..2f6fb0c 100644 --- a/src/Exception/API/TooManyRequestsException.php +++ b/src/Exception/API/TooManyRequestsException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/API/UnauthorizedServiceException.php b/src/Exception/API/UnauthorizedServiceException.php index a789c81..70e7fbc 100644 --- a/src/Exception/API/UnauthorizedServiceException.php +++ b/src/Exception/API/UnauthorizedServiceException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index c7055d7..a5d2ba5 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Result/AbstractResult.php b/src/Result/AbstractResult.php index 23a631b..a4d002f 100644 --- a/src/Result/AbstractResult.php +++ b/src/Result/AbstractResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * @@ -14,7 +24,6 @@ { public function __construct( protected array $resultData, - ) - { + ) { } } diff --git a/src/Result/ActivationHistoryResult.php b/src/Result/ActivationHistoryResult.php index a3903fa..bb0bca8 100644 --- a/src/Result/ActivationHistoryResult.php +++ b/src/Result/ActivationHistoryResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Result/ActivationResult.php b/src/Result/ActivationResult.php index 50f8f43..89b85aa 100644 --- a/src/Result/ActivationResult.php +++ b/src/Result/ActivationResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Result/CountryResult.php b/src/Result/CountryResult.php index aa3e780..46a04f5 100644 --- a/src/Result/CountryResult.php +++ b/src/Result/CountryResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Result/CountryServiceInfoResult.php b/src/Result/CountryServiceInfoResult.php index a7aacdb..d3fea53 100644 --- a/src/Result/CountryServiceInfoResult.php +++ b/src/Result/CountryServiceInfoResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/src/Result/ServiceResult.php b/src/Result/ServiceResult.php index a1ac4dc..2149f1a 100644 --- a/src/Result/ServiceResult.php +++ b/src/Result/ServiceResult.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index abeabe7..aee6f67 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -1,4 +1,14 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); /* * This file is part of the TempNumberClient package. * From 672d9718fde0c0fa61d098a0ac516c1d354ba351 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 09:44:43 +0300 Subject: [PATCH 12/16] Migrate phpunit.xml to latest version --- phpunit.xml.dist | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cbd6e09..49aac05 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,32 +1,37 @@ + + + failOnWarning="true"> - - tests/unit + + tests/Unit - - + + - + - src + src - + From d371e7a9032eee854a5b497de7957bc94428c76c Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 10:03:33 +0300 Subject: [PATCH 13/16] Fix directory name --- tests/{unit => Unit}/ClientTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{unit => Unit}/ClientTest.php (100%) diff --git a/tests/unit/ClientTest.php b/tests/Unit/ClientTest.php similarity index 100% rename from tests/unit/ClientTest.php rename to tests/Unit/ClientTest.php From be851b63d1c495fab252f9e5979ab068e2b50628 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 10:06:45 +0300 Subject: [PATCH 14/16] Fix phpstan-baseline.neon --- phpstan-baseline.neon | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bfb5304..78cf974 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,9 +1,16 @@ parameters: - ignoreErrors: - - message: "#^Method ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\:\\:newFromErrorName\\(\\) should return static\\(ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\) but returns ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\.$#" - count: 1 - path: src/Exception/API/APIException.php + ignoreErrors: + - + message: "#^Method ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\:\\:newFromErrorName\\(\\) should return static\\(ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\) but returns ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\.$#" + count: 1 + path: src/Exception/API/APIException.php - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 2 - path: tests/unit/ClientTest.php + - + message: "#^Property ahmedghanem00\\\\TempNumberClient\\\\Tests\\\\unit\\\\ClientTest\\:\\:\\$client is unused\\.$#" + count: 1 + path: tests/Unit/ClientTest.php + + - + message: "#^Property ahmedghanem00\\\\TempNumberClient\\\\Tests\\\\unit\\\\ClientTest\\:\\:\\$client is unused\\.$#" + count: 1 + path: tests/unit/ClientTest.php From 525a26db33702cc130e6dfa535f3a2d8de37ac94 Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 10:09:18 +0300 Subject: [PATCH 15/16] Fix phpstan-baseline.neon 2 --- phpstan-baseline.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 78cf974..e1cdef2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -9,8 +9,3 @@ parameters: message: "#^Property ahmedghanem00\\\\TempNumberClient\\\\Tests\\\\unit\\\\ClientTest\\:\\:\\$client is unused\\.$#" count: 1 path: tests/Unit/ClientTest.php - - - - message: "#^Property ahmedghanem00\\\\TempNumberClient\\\\Tests\\\\unit\\\\ClientTest\\:\\:\\$client is unused\\.$#" - count: 1 - path: tests/unit/ClientTest.php From 8ef6c0c5a5b40ada7133f384abe6d7ca8d675c0e Mon Sep 17 00:00:00 2001 From: Ahmed Ghanem Date: Sat, 18 May 2024 10:13:31 +0300 Subject: [PATCH 16/16] Fix phpstan-baseline.neon 3 --- phpstan-baseline.neon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e1cdef2..aa7ab57 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,6 +6,6 @@ parameters: path: src/Exception/API/APIException.php - - message: "#^Property ahmedghanem00\\\\TempNumberClient\\\\Tests\\\\unit\\\\ClientTest\\:\\:\\$client is unused\\.$#" - count: 1 + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 2 path: tests/Unit/ClientTest.php