From e526f2d3c69683140d15a7f94f799c4d2281290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Mon, 21 Oct 2024 17:17:17 +0200 Subject: [PATCH 1/5] feat: make response available in FoxentryException --- composer.lock | 116 ++++++++++++++-------------- src/Exception/FoxentryException.php | 50 ++++++++---- 2 files changed, 94 insertions(+), 72 deletions(-) diff --git a/composer.lock b/composer.lock index ca60f57..516fcb6 100644 --- a/composer.lock +++ b/composer.lock @@ -134,16 +134,16 @@ }, { "name": "guzzlehttp/promises", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8" + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", - "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "url": "https://api.github.com/repos/guzzle/promises/zipball/f9c436286ab2892c7db7be8c8da4ef61ccf7b455", + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455", "shasum": "" }, "require": { @@ -197,7 +197,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.3" + "source": "https://github.com/guzzle/promises/tree/2.0.4" }, "funding": [ { @@ -213,7 +213,7 @@ "type": "tidelift" } ], - "time": "2024-07-18T10:29:17+00:00" + "time": "2024-10-17T10:06:22+00:00" }, { "name": "guzzlehttp/psr7", @@ -666,16 +666,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.1.0", + "version": "v5.3.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b", + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b", "shasum": "" }, "require": { @@ -718,9 +718,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1" }, - "time": "2024-07-01T20:03:41+00:00" + "time": "2024-10-08T18:51:32+00:00" }, { "name": "phar-io/manifest", @@ -842,35 +842,35 @@ }, { "name": "phpunit/php-code-coverage", - "version": "11.0.6", + "version": "11.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45" + "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ebdffc9e09585dafa71b9bffcdb0a229d4704c45", - "reference": "ebdffc9e09585dafa71b9bffcdb0a229d4704c45", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7f08030e8811582cc459871d28d6f5a1a4d35ca", + "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^5.1.0", + "nikic/php-parser": "^5.3.1", "php": ">=8.2", - "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-text-template": "^4.0.1", "sebastian/code-unit-reverse-lookup": "^4.0.1", "sebastian/complexity": "^4.0.1", "sebastian/environment": "^7.2.0", "sebastian/lines-of-code": "^3.0.1", - "sebastian/version": "^5.0.1", + "sebastian/version": "^5.0.2", "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.4.1" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -908,7 +908,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.6" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.7" }, "funding": [ { @@ -916,7 +916,7 @@ "type": "github" } ], - "time": "2024-08-22T04:37:56+00:00" + "time": "2024-10-09T06:21:38+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1165,16 +1165,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.3.1", + "version": "11.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fe179875ef0c14e90b75617002767eae0a742641" + "reference": "1863643c3f04ad03dcb9c6996c294784cdda4805" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fe179875ef0c14e90b75617002767eae0a742641", - "reference": "fe179875ef0c14e90b75617002767eae0a742641", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1863643c3f04ad03dcb9c6996c294784cdda4805", + "reference": "1863643c3f04ad03dcb9c6996c294784cdda4805", "shasum": "" }, "require": { @@ -1188,21 +1188,21 @@ "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.2", - "phpunit/php-code-coverage": "^11.0.5", - "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-code-coverage": "^11.0.7", + "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-invoker": "^5.0.1", "phpunit/php-text-template": "^4.0.1", "phpunit/php-timer": "^7.0.1", "sebastian/cli-parser": "^3.0.2", "sebastian/code-unit": "^3.0.1", - "sebastian/comparator": "^6.0.2", + "sebastian/comparator": "^6.1.1", "sebastian/diff": "^6.0.2", "sebastian/environment": "^7.2.0", "sebastian/exporter": "^6.1.3", "sebastian/global-state": "^7.0.2", "sebastian/object-enumerator": "^6.0.1", - "sebastian/type": "^5.0.1", - "sebastian/version": "^5.0.1" + "sebastian/type": "^5.1.0", + "sebastian/version": "^5.0.2" }, "suggest": { "ext-soap": "To be able to generate mocks based on WSDL files" @@ -1213,7 +1213,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "11.3-dev" + "dev-main": "11.4-dev" } }, "autoload": { @@ -1245,7 +1245,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.1" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.4.2" }, "funding": [ { @@ -1261,7 +1261,7 @@ "type": "tidelift" } ], - "time": "2024-08-13T06:14:23+00:00" + "time": "2024-10-19T13:05:19+00:00" }, { "name": "sebastian/cli-parser", @@ -1435,16 +1435,16 @@ }, { "name": "sebastian/comparator", - "version": "6.0.2", + "version": "6.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81" + "reference": "5ef523a49ae7a302b87b2102b72b1eda8918d686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81", - "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5ef523a49ae7a302b87b2102b72b1eda8918d686", + "reference": "5ef523a49ae7a302b87b2102b72b1eda8918d686", "shasum": "" }, "require": { @@ -1455,12 +1455,12 @@ "sebastian/exporter": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "6.0-dev" + "dev-main": "6.1-dev" } }, "autoload": { @@ -1500,7 +1500,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2" + "source": "https://github.com/sebastianbergmann/comparator/tree/6.1.1" }, "funding": [ { @@ -1508,7 +1508,7 @@ "type": "github" } ], - "time": "2024-08-12T06:07:25+00:00" + "time": "2024-10-18T15:00:48+00:00" }, { "name": "sebastian/complexity", @@ -2077,28 +2077,28 @@ }, { "name": "sebastian/type", - "version": "5.0.1", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa" + "reference": "461b9c5da241511a2a0e8f240814fb23ce5c0aac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb6a6566f9589e86661291d13eba708cce5eb4aa", - "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/461b9c5da241511a2a0e8f240814fb23ce5c0aac", + "reference": "461b9c5da241511a2a0e8f240814fb23ce5c0aac", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -2122,7 +2122,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/type/issues", "security": "https://github.com/sebastianbergmann/type/security/policy", - "source": "https://github.com/sebastianbergmann/type/tree/5.0.1" + "source": "https://github.com/sebastianbergmann/type/tree/5.1.0" }, "funding": [ { @@ -2130,20 +2130,20 @@ "type": "github" } ], - "time": "2024-07-03T05:11:49+00:00" + "time": "2024-09-17T13:12:04+00:00" }, { "name": "sebastian/version", - "version": "5.0.1", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4" + "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/45c9debb7d039ce9b97de2f749c2cf5832a06ac4", - "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874", + "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874", "shasum": "" }, "require": { @@ -2176,7 +2176,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/version/issues", "security": "https://github.com/sebastianbergmann/version/security/policy", - "source": "https://github.com/sebastianbergmann/version/tree/5.0.1" + "source": "https://github.com/sebastianbergmann/version/tree/5.0.2" }, "funding": [ { @@ -2184,7 +2184,7 @@ "type": "github" } ], - "time": "2024-07-03T05:13:08+00:00" + "time": "2024-10-09T05:16:32+00:00" }, { "name": "theseer/tokenizer", @@ -2239,13 +2239,13 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=7.4", "ext-json": "*" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/src/Exception/FoxentryException.php b/src/Exception/FoxentryException.php index 440957f..a1d6962 100644 --- a/src/Exception/FoxentryException.php +++ b/src/Exception/FoxentryException.php @@ -2,6 +2,7 @@ namespace Foxentry\Exception; use GuzzleHttp\Exception\RequestException; +use Psr\Http\Message\ResponseInterface; /** * Foxentry exception handler @@ -10,6 +11,8 @@ */ class FoxentryException extends \Exception { + protected ?ResponseInterface $response = null; + /** * Create a FoxentryException based on the given RequestException. * @@ -20,32 +23,51 @@ public static function fromRequestException(RequestException $e) // Check if the exception has a response if ($e->hasResponse()) { $statusCode = $e->getResponse()->getStatusCode(); - // Switch based on the status code of the response switch ($statusCode) { case 400: - return new BadRequestException("Request was invalid or cannot be processed."); + $foxentryException = new BadRequestException("Request was invalid or cannot be processed."); + break; case 401: - return new UnauthorizedException("Unauthorized. Did you set your API key?"); + $foxentryException = new UnauthorizedException("Unauthorized. Did you set your API key?"); + break; case 402: - return new PaymentRequiredException("Payment is required to access this resource."); + $foxentryException = new PaymentRequiredException("Payment is required to access this resource."); + break; case 403: - return new ForbiddenException("Forbidden."); + $foxentryException = new ForbiddenException("Forbidden."); + break; case 404: - return new NotFoundException("Resource or endpoint requested is not found on the server."); + $foxentryException = new NotFoundException("Resource or endpoint requested is not found on the server."); + break; case 429: - return new TooManyRequestsException("Too many requests have been made in the given time frame or the daily limit has been reached."); + $foxentryException = new TooManyRequestsException("Too many requests have been made in the given time frame or the daily limit has been reached."); + break; case 500: - return new ServerErrorException("Internal server error."); + $foxentryException = new ServerErrorException("Internal server error."); + break; case 503: - return new ServiceUnavailableException("The server is temporarily unable to handle the request"); + $foxentryException = new ServiceUnavailableException("The server is temporarily unable to handle the request"); + break; default: // Handle the rest with generic FoxentryException class - return new self("Request exception: " . $e->getResponse()->getBody()->getContents(), $statusCode); + $foxentryException = new self("Request exception: " . $e->getResponse()->getBody()->getContents(), $statusCode); + break; } - } else { - // Return a generic exception with the original exception message - return new self("Exception: " . $e->getMessage()); + return $foxentryException->setResponse($e->getResponse()); } + + // Return a generic exception with the original exception message + return new self( "Exception: " . $e->getMessage()); + } + + public function setResponse(ResponseInterface $response): self + { + $this->response = $response; + return $this; + } + + public function getResponse(): ?ResponseInterface { + return $this->response; } -} \ No newline at end of file +} From cce8dc863b70298c34b47e2e216de9c3803ff3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Tue, 22 Oct 2024 09:51:22 +0200 Subject: [PATCH 2/5] fix: fix all lint issues --- .gitignore | 1 + composer.json | 21 +- composer.lock | 330 +++++++++++++++++- phpcs.xml | 57 +++ phpstan.neon | 13 + src/ApiClient.php | 41 ++- src/Exception/BadRequestException.php | 5 +- src/Exception/ForbiddenException.php | 5 +- src/Exception/FoxentryException.php | 15 +- src/Exception/NotFoundException.php | 7 +- src/Exception/PaymentRequiredException.php | 5 +- src/Exception/ServerErrorException.php | 5 +- src/Exception/ServiceUnavailableException.php | 5 +- src/Exception/TooManyRequestsException.php | 5 +- src/Exception/UnauthorizedException.php | 5 +- src/Request.php | 52 +-- src/Resource/BaseResource.php | 30 +- src/Resource/Company.php | 67 +++- src/Resource/Email.php | 53 ++- src/Resource/Location.php | 76 +++- src/Resource/Name.php | 37 +- src/Resource/Phone.php | 39 ++- src/Response.php | 55 +-- tests/Base.php | 3 + tests/Unit/Company/CompanyGetTest.php | 38 +- tests/Unit/Company/CompanySearchTest.php | 38 +- tests/Unit/Company/CompanyValidateTest.php | 34 +- tests/Unit/Email/EmailSearchTest.php | 12 +- tests/Unit/Email/EmailValidateTest.php | 42 +-- tests/Unit/Location/LocationGetTest.php | 32 +- tests/Unit/Location/LocationLocalizeTest.php | 20 +- tests/Unit/Location/LocationSearchTest.php | 44 +-- tests/Unit/Location/LocationValidateTest.php | 38 +- tests/Unit/Name/NameValidateTest.php | 42 +-- tests/Unit/Phone/PhoneValidateTest.php | 38 +- 35 files changed, 1010 insertions(+), 300 deletions(-) create mode 100644 phpcs.xml create mode 100644 phpstan.neon diff --git a/.gitignore b/.gitignore index f8aa5af..009984c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .phpunit.result.cache phpunit.xml vendor +var diff --git a/composer.json b/composer.json index 7cc698a..645d2e4 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,15 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "guzzlehttp/guzzle": "^7.8", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^11.3.1" + "phpunit/phpunit": "^11.3.1", + "phpstan/phpstan": "^1.12", + "squizlabs/php_codesniffer": "^3.10", + "slevomat/coding-standard": "^8.15" }, "autoload": { "psr-4": { @@ -30,5 +33,19 @@ "Tests\\": "tests/", "Tests\\Unit\\": "tests/Unit/" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "scripts": { + "lint": "phpcs", + "lint-fix": "phpcbf", + "phpstan": "phpstan analyse -c phpstan.neon", + "check-quality": [ + "@lint", + "@phpstan" + ] } } diff --git a/composer.lock b/composer.lock index 516fcb6..fd34166 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "29eac92058cf77d0b55646c736502637", + "content-hash": "56102ca8fcca341dfbe833601c23eab3", "packages": [ { "name": "guzzlehttp/guzzle", @@ -604,6 +604,84 @@ } ], "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.12.0", @@ -840,6 +918,111 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.33.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + }, + "time": "2024-10-13T11:25:22+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.12.7", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-10-18T11:12:07+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.7", @@ -2186,6 +2369,151 @@ ], "time": "2024-10-09T05:16:32+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "8.15.0", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "7d1d957421618a3803b593ec31ace470177d7817" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/7d1d957421618a3803b593ec31ace470177d7817", + "reference": "7d1d957421618a3803b593ec31ace470177d7817", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.23.1", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.60", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.16", + "phpstan/phpstan-strict-rules": "1.5.2", + "phpunit/phpunit": "8.5.21|9.6.8|10.5.11" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.15.0" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2024-03-09T15:20:58+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.10.3", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-09-18T10:38:58+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.3", diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..2c3f0fb --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,57 @@ + + + Slim coding standard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + 0 + + + + + + + + + + + + src + tests + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..86c2c6c --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +parameters: + level: 8 + phpVersion: 70400 + + tmpDir: %currentWorkingDirectory%/var/tmp/phpstan + + fileExtensions: + - php + - phpt + + paths: + - src + - tests diff --git a/src/ApiClient.php b/src/ApiClient.php index ab13b52..aaf5c06 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -1,5 +1,7 @@ setAuth($apiKey); } @@ -35,7 +38,8 @@ public function __construct( ?string $apiKey = null ) { * * @param string $apiKey The API key to set */ - public function setAuth( string $apiKey ): void { + public function setAuth(string $apiKey): void + { $this->apiKey = $apiKey; } @@ -44,34 +48,39 @@ public function setAuth( string $apiKey ): void { * * @param string $version The API version to set */ - public function setApiVersion( string $version ): void { + public function setApiVersion(string $version): void + { $this->apiVersion = $version; } - function company() { + public function company(): Company + { $request = new Request($this->apiVersion, $this->apiKey); - return new Company( $request ); + return new Company($request); } - function email() { + public function email(): Email + { $request = new Request($this->apiVersion, $this->apiKey); - return new Email( $request ); + return new Email($request); } - function location() { + public function location(): Location + { $request = new Request($this->apiVersion, $this->apiKey); - return new Location( $request ); + return new Location($request); } - function name() { + public function name(): Name + { $request = new Request($this->apiVersion, $this->apiKey); - return new Name( $request ); + return new Name($request); } - function phone() { + public function phone(): Phone + { $request = new Request($this->apiVersion, $this->apiKey); - return new Phone( $request ); + return new Phone($request); } - } diff --git a/src/Exception/BadRequestException.php b/src/Exception/BadRequestException.php index 0965bdd..9eba63f 100644 --- a/src/Exception/BadRequestException.php +++ b/src/Exception/BadRequestException.php @@ -1,5 +1,7 @@ hasResponse()) { @@ -41,7 +43,9 @@ public static function fromRequestException(RequestException $e) $foxentryException = new NotFoundException("Resource or endpoint requested is not found on the server."); break; case 429: - $foxentryException = new TooManyRequestsException("Too many requests have been made in the given time frame or the daily limit has been reached."); + $foxentryException = new TooManyRequestsException( + "Too many requests have been made in the given time frame or the daily limit has been reached." + ); break; case 500: $foxentryException = new ServerErrorException("Internal server error."); @@ -58,7 +62,7 @@ public static function fromRequestException(RequestException $e) } // Return a generic exception with the original exception message - return new self( "Exception: " . $e->getMessage()); + return new self("Exception: " . $e->getMessage()); } public function setResponse(ResponseInterface $response): self @@ -67,7 +71,8 @@ public function setResponse(ResponseInterface $response): self return $this; } - public function getResponse(): ?ResponseInterface { + public function getResponse(): ?ResponseInterface + { return $this->response; } } diff --git a/src/Exception/NotFoundException.php b/src/Exception/NotFoundException.php index f27ee67..93d80d1 100644 --- a/src/Exception/NotFoundException.php +++ b/src/Exception/NotFoundException.php @@ -1,5 +1,7 @@ */ private array $headers = [ "Foxentry-Include-Request-Details" => false, "Content-Type" => "application/json", "Accept" => "application/json", - "User-Agent" => "FoxentrySdk (PHP/2.3.0; ApiReference/2.0)" + "User-Agent" => "FoxentrySdk (PHP/2.3.0; ApiReference/2.0)", ]; /** * The request body data to send to the API. * - * @var object */ private object $body; /** * A custom ID for the request (optional). * - * @var string|null */ private ?string $customId = null; /** * The query parameters for the API request. * - * @var array + * @var array */ private array $query; /** * Additional options for the API request (optional). * - * @var array|null + * @var array|null */ private ?array $options = null; /** * The API endpoint to send the request to. * - * @var string */ private string $endpoint; /** * The HTTP client for making requests. * - * @var HttpClient */ private HttpClient $httpClient; /** * The API key used for authentication. * - * @var string */ private string $apiKey; /** * Information about the client making the request (optional). * - * @var object|null */ private ?object $client = null; - public function __construct(string $apiVersion, ?string $apiKey) { + public function __construct(string $apiVersion, ?string $apiKey) + { $this->setHeader("Api-Version", $apiVersion); - if ($apiKey){ + if ($apiKey) { $this->setAuth($apiKey); } @@ -132,7 +127,7 @@ public function setAuth(string $apiKey): void * @param string $key The header key * @param mixed $value The header value */ - public function setHeader(string $key, $value): void + public function setHeader(string $key, mixed $value): void { $this->headers[$key] = $value; } @@ -150,7 +145,7 @@ public function setCustomId(string $id): void /** * Set query parameters for the request. * - * @param array $query The query parameters to set + * @param array $query The query parameters to set */ public function setQuery(array $query): void { @@ -160,7 +155,7 @@ public function setQuery(array $query): void /** * Set options for the request. * - * @param array $options The options to set + * @param array $options The options to set */ public function setOptions(array $options): void { @@ -184,11 +179,13 @@ public function setEndpoint(string $endpoint): void */ public function setClientIP(string $ip): void { - if(!filter_var($ip, FILTER_VALIDATE_IP)) + if (!filter_var($ip, FILTER_VALIDATE_IP)) { throw new \InvalidArgumentException("The specified IP address is not valid."); + } - if(empty($this->client)) + if (empty($this->client)) { $this->client = new \stdClass(); + } $this->client->ip = $ip; } @@ -200,11 +197,13 @@ public function setClientIP(string $ip): void */ public function setClientCountry(string $country): void { - if(strlen($country) != 2) + if (strlen($country) != 2) { throw new \InvalidArgumentException("The provided country code does not conform to the ISO-3166-1 alpha-2 format."); + } - if(empty($this->client)) + if (empty($this->client)) { $this->client = new \stdClass(); + } $this->client->country = $country; } @@ -222,8 +221,9 @@ public function setClientLocation(float $lat, float $lon): void "lon" => $lon, ]; - if(empty($this->client)) + if (empty($this->client)) { $this->client = new \stdClass(); + } $this->client->location = (object)$location; } @@ -251,7 +251,7 @@ public function send(): Response $response = $this->httpClient->request($this->method, $this->endpoint, [ "headers" => $this->headers, - "body" => json_encode($this->body) + "body" => json_encode($this->body), ]); $responseHeaders = $response->getHeaders(); @@ -273,8 +273,8 @@ private function buildBody(): void "customId" => $this->customId, "query" => $this->query, "options" => $this->options, - "client" => $this->client - ] + "client" => $this->client, + ], ]; $this->body = (object)$body; diff --git a/src/Resource/BaseResource.php b/src/Resource/BaseResource.php index 25a88f5..7c2266c 100644 --- a/src/Resource/BaseResource.php +++ b/src/Resource/BaseResource.php @@ -1,9 +1,20 @@ request->setHeader( "Foxentry-Include-Request-Details", $value ); + public function includeRequestDetails(bool $value = true): self + { + $this->request->setHeader("Foxentry-Include-Request-Details", $value); return $this; } @@ -50,7 +62,7 @@ public function setCustomId(string $id): BaseResource /** * Set options for the resource request. * - * @param array $options The options to set + * @param array $options The options to set * * @return BaseResource Returns $this for method chaining */ @@ -104,10 +116,18 @@ public function setClientLocation(float $lat, float $lon): BaseResource /** * Send a request to the API with the given query parameters. * - * @param array $query The query parameters for the request + * @param array $query The query parameters for the request * * @return Response The response from the API - * @throws \Exception + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ protected function send(array $query): Response { diff --git a/src/Resource/Company.php b/src/Resource/Company.php index 14ae403..a93b7ea 100644 --- a/src/Resource/Company.php +++ b/src/Resource/Company.php @@ -1,8 +1,19 @@ $query Query parameters for the validation request * * @return Response The response from the validation request + * + * @return Response The response from the API + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function validate(array $query): Response { @@ -26,9 +48,20 @@ public function validate(array $query): Response /** * Search for a company. * - * @param array $query Query parameters for the search request + * @param array $query Query parameters for the search request + * + * @return Response The response from the API * * @return Response The response from the API + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function search(array $query): Response { @@ -38,9 +71,20 @@ public function search(array $query): Response /** * Get company details. * - * @param array $query Query parameters for the get request + * @param array $query Query parameters for the get request * * @return Response The response from the API + * + * @return Response The response from the API + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function get(array $query): Response { @@ -50,12 +94,23 @@ public function get(array $query): Response /** * Send a request to the API with the given query parameters. * - * @param array $query Query parameters for the request + * @param array $query Query parameters for the request + * + * @return Response The response from the API * * @return Response The response from the API + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ private function sendRequest(array $query): Response { - return parent::send($query); + return $this->send($query); } -} \ No newline at end of file +} diff --git a/src/Resource/Email.php b/src/Resource/Email.php index 5746313..b63393d 100644 --- a/src/Resource/Email.php +++ b/src/Resource/Email.php @@ -1,8 +1,19 @@ $query Email address to validate * * @return Response The response from the validation request + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ - public function validate($query): Response + public function validate(string|array $query): Response { $query = is_array($query) ? $query : ["email" => $query]; return $this->sendRequest($query); @@ -27,11 +48,21 @@ public function validate($query): Response /** * Search for information related to an email address. * - * @param string|array $query Email address to search for + * @param string|array $query Email address to search for * * @return Response The response from the search request + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ - public function search($query): Response + public function search(string|array $query): Response { $query = is_array($query) ? $query : ["value" => $query]; return $this->sendRequest($query); @@ -40,12 +71,22 @@ public function search($query): Response /** * Send a request to the API with the given query parameters. * - * @param array $query Query parameters for the request + * @param array $query Query parameters for the request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ private function sendRequest(array $query): Response { - return parent::send($query); + return $this->send($query); } } diff --git a/src/Resource/Location.php b/src/Resource/Location.php index 7012f94..f52ca74 100644 --- a/src/Resource/Location.php +++ b/src/Resource/Location.php @@ -1,8 +1,19 @@ $query Query parameters for the validation request + * * @return Response The response from the validation request + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function validate(array $query): Response { @@ -25,9 +47,19 @@ public function validate(array $query): Response /** * Search for a location. * - * @param array $query Query parameters for the search request + * @param array $query Query parameters for the search request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function search(array $query): Response { @@ -37,9 +69,19 @@ public function search(array $query): Response /** * Get location details. * - * @param array $query Query parameters for the get request + * @param array $query Query parameters for the get request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function get(array $query): Response { @@ -49,9 +91,19 @@ public function get(array $query): Response /** * Localize a location. * - * @param array $query Query parameters for the localize request + * @param array $query Query parameters for the localize request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function localize(array $query): Response { @@ -61,12 +113,22 @@ public function localize(array $query): Response /** * Send a request to the API with the given query parameters. * - * @param array $query Query parameters for the request + * @param array $query Query parameters for the request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ private function sendRequest(array $query): Response { - return parent::send($query); + return $this->send($query); } -} \ No newline at end of file +} diff --git a/src/Resource/Name.php b/src/Resource/Name.php index 04c7722..3339118 100644 --- a/src/Resource/Name.php +++ b/src/Resource/Name.php @@ -1,8 +1,19 @@ $query Query parameters for the validation request * * @return Response The response from the validation request + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function validate(array $query): Response { @@ -26,12 +47,22 @@ public function validate(array $query): Response /** * Send a request to the API with the given query parameters. * - * @param array $query Query parameters for the request + * @param array $query Query parameters for the request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ private function sendRequest(array $query): Response { - return parent::send($query); + return $this->send($query); } } diff --git a/src/Resource/Phone.php b/src/Resource/Phone.php index 689f194..57f7fd4 100644 --- a/src/Resource/Phone.php +++ b/src/Resource/Phone.php @@ -1,8 +1,19 @@ $query Query parameters for the validation request * * @return Response The response from the validation request + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ public function validate(array $query): Response { @@ -26,12 +47,22 @@ public function validate(array $query): Response /** * Send a request to the API with the given query parameters. * - * @param array $query Query parameters for the request + * @param array $query Query parameters for the request * * @return Response The response from the API + * + * @throws TooManyRequestsException + * @throws BadRequestException + * @throws ForbiddenException + * @throws NotFoundException + * @throws PaymentRequiredException + * @throws ServerErrorException + * @throws UnauthorizedException + * @throws FoxentryException + * @throws GuzzleException */ private function sendRequest(array $query): Response { - return parent::send($query); + return $this->send($query); } -} \ No newline at end of file +} diff --git a/src/Response.php b/src/Response.php index f85d347..7d38c7c 100644 --- a/src/Response.php +++ b/src/Response.php @@ -1,5 +1,7 @@ data->status ?? null; } @@ -52,7 +52,7 @@ public function getStatus() /** * Get headers received from the API response. * - * @return array Response headers + * @return string[][] Response headers */ public function getHeaders(): array { @@ -64,7 +64,8 @@ public function getHeaders(): array * * @return int Rate limit number */ - public function getRateLimit(): int { + public function getRateLimit(): int + { return reset($this->headers['foxentry-rate-limit']); } @@ -73,7 +74,8 @@ public function getRateLimit(): int { * * @return int Time period in seconds of how long it will take before the rate limit is restored */ - public function getRateLimitPeriod(): int { + public function getRateLimitPeriod(): int + { return reset($this->headers['foxentry-rate-limit-period']); } @@ -82,7 +84,8 @@ public function getRateLimitPeriod(): int { * * @return int Remaining rate limit */ - public function getRateLimitRemaining(): int { + public function getRateLimitRemaining(): int + { return reset($this->headers['foxentry-rate-limit-remaining']); } @@ -91,8 +94,9 @@ public function getRateLimitRemaining(): int { * * @return ?float Remaining daily credits, null if no limit is set */ - public function getDailyCreditsLeft(): ?float { - if (!isset($this->headers['foxentry-daily-credits-left'])){ + public function getDailyCreditsLeft(): ?float + { + if (!isset($this->headers['foxentry-daily-credits-left'])) { return null; } @@ -104,8 +108,9 @@ public function getDailyCreditsLeft(): ?float { * * @return ?int Daily credits limit, null if no limit is set */ - public function getDailyCreditsLimit(): ?int { - if (!isset($this->headers['foxentry-daily-credits-limit'])){ + public function getDailyCreditsLimit(): ?int + { + if (!isset($this->headers['foxentry-daily-credits-limit'])) { return null; } @@ -117,7 +122,8 @@ public function getDailyCreditsLimit(): ?int { * * @return float API version */ - public function getApiVersion(): float { + public function getApiVersion(): float + { return reset($this->headers['foxentry-api-version']); } @@ -126,7 +132,7 @@ public function getApiVersion(): float { * * @return mixed|null The request details or null if not present in the response */ - public function getRequest() + public function getRequest(): mixed { return $this->data->request ?? null; } @@ -136,7 +142,7 @@ public function getRequest() * * @return mixed|null The response data or null if not present in the response */ - public function getResponse() + public function getResponse(): mixed { return $this->data->response ?? null; } @@ -146,11 +152,12 @@ public function getResponse() * * @return mixed|null The result or null if not present in the response */ - public function getResult() + public function getResult(): mixed { $result = $this->getResponse()->result ?? null; - if(empty($result)) + if (empty($result)) { $result = $this->getResponse()->results ?? null; + } return $result; } @@ -160,7 +167,7 @@ public function getResult() * * @return mixed|null The corrected result or null if not present in the response */ - public function getResultCorrected() + public function getResultCorrected(): mixed { return $this->getResponse()->resultCorrected ?? null; } @@ -170,7 +177,7 @@ public function getResultCorrected() * * @return mixed|null The suggestions or null if not present in the response */ - public function getSuggestions() + public function getSuggestions(): mixed { return $this->getResponse()->suggestions ?? null; } @@ -180,7 +187,7 @@ public function getSuggestions() * * @return mixed|null The errors or null if not present in the response */ - public function getErrors() + public function getErrors(): mixed { return $this->data->errors ?? null; } diff --git a/tests/Base.php b/tests/Base.php index 7a4aba3..6e4ec8f 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -1,4 +1,7 @@ "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data retrieval. @@ -39,17 +41,17 @@ public function testBasicDataScope() /** * Test retrieval of extended data scope by country and registration number. */ - public function testExtendedDataScope() + public function testExtendedDataScope(): void { // Query parameters for retrieving company data by country and registration number. $query = [ "country" => "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "extended" + "dataScope" => "extended", ]; // Perform company data retrieval. @@ -65,17 +67,17 @@ public function testExtendedDataScope() /** * Test retrieval of full data scope by country and registration number. */ - public function testFullDataScope() + public function testFullDataScope(): void { // Query parameters for retrieving company data by country and registration number. $query = [ "country" => "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "full" + "dataScope" => "full", ]; // Perform company data retrieval. @@ -91,7 +93,7 @@ public function testFullDataScope() /** * Test company data retrieval with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -99,12 +101,12 @@ public function testWithCustomId() // Query parameters for company data retrieval. $query = [ "country" => "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data retrieval. @@ -124,17 +126,17 @@ public function testWithCustomId() /** * Test company data retrieval with client information. */ - public function testWithClient() + public function testWithClient(): void { // Query parameters for company data retrieval. $query = [ "country" => "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data retrieval with client information. @@ -156,17 +158,17 @@ public function testWithClient() /** * Settings should not persist between calls. */ - public function testInstanceSettings() + public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ "country" => "CZ", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform name validation with client information. diff --git a/tests/Unit/Company/CompanySearchTest.php b/tests/Unit/Company/CompanySearchTest.php index b904850..8715459 100644 --- a/tests/Unit/Company/CompanySearchTest.php +++ b/tests/Unit/Company/CompanySearchTest.php @@ -1,5 +1,7 @@ "name", - "value" => "Web" + "value" => "Web", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform company name search. @@ -41,17 +43,17 @@ public function testSearchName() /** * Test valid registration number search. */ - public function testSearchRegistrationNumber() + public function testSearchRegistrationNumber(): void { // Input parameters for registration number search. $query = [ "type" => "registrationNumber", - "value" => "10" + "value" => "10", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform registration number search. @@ -69,17 +71,17 @@ public function testSearchRegistrationNumber() /** * Test valid tax number search. */ - public function testSearchTaxNumber() + public function testSearchTaxNumber(): void { // Input parameters for tax number search. $query = [ "type" => "taxNumber", - "value" => "10" + "value" => "10", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform tax number search. @@ -97,17 +99,17 @@ public function testSearchTaxNumber() /** * Test valid VAT number search. */ - public function testSearchVatNumber() + public function testSearchVatNumber(): void { // Input parameters for VAT number search. $query = [ "type" => "vatNumber", - "value" => "CZ04997476" + "value" => "CZ04997476", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform VAT number search. @@ -125,7 +127,7 @@ public function testSearchVatNumber() /** * Test company data search with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -133,12 +135,12 @@ public function testWithCustomId() // Input parameters for company name search. $query = [ "type" => "name", - "value" => "Web" + "value" => "Web", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform company data search. @@ -160,17 +162,17 @@ public function testWithCustomId() /** * Test company data search with client information. */ - public function testWithClient() + public function testWithClient(): void { // Input parameters for company name search. $query = [ "type" => "name", - "value" => "Web" + "value" => "Web", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform company data search with client information. diff --git a/tests/Unit/Company/CompanyValidateTest.php b/tests/Unit/Company/CompanyValidateTest.php index 223cb08..f09b01e 100644 --- a/tests/Unit/Company/CompanyValidateTest.php +++ b/tests/Unit/Company/CompanyValidateTest.php @@ -1,5 +1,7 @@ "AVANTRO s.r.o.", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data validation. @@ -41,12 +43,12 @@ public function testValid() /** * Test invalid company data. */ - public function testInvalid() + public function testInvalid(): void { // Query parameters for validating company data. $query = [ "name" => "AVANTRO", - "registrationNumber" => "25547" + "registrationNumber" => "25547", ]; // Options that will be sent within the request. @@ -69,12 +71,12 @@ public function testInvalid() /** * Test invalid company data with correction. */ - public function testInvalidWithCorrection() + public function testInvalidWithCorrection(): void { // Query parameters for validating company data. $query = [ "name" => "AVANTRO", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. @@ -97,16 +99,16 @@ public function testInvalidWithCorrection() /** * Test invalid company data with suggestion. */ - public function testInvalidWithSuggestion() + public function testInvalidWithSuggestion(): void { // Query parameters for validating company data. $query = [ - "registrationNumber" => "0499747" + "registrationNumber" => "0499747", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data validation. @@ -124,7 +126,7 @@ public function testInvalidWithSuggestion() /** * Test company data validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -132,12 +134,12 @@ public function testWithCustomId() // Query parameters for validating company data. $query = [ "name" => "AVANTRO s.r.o.", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data validation. @@ -157,17 +159,17 @@ public function testWithCustomId() /** * Test company data validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Query parameters for validating company data. $query = [ "name" => "AVANTRO s.r.o.", - "registrationNumber" => "04997476" + "registrationNumber" => "04997476", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform company data validation with client information. diff --git a/tests/Unit/Email/EmailSearchTest.php b/tests/Unit/Email/EmailSearchTest.php index 4f01183..0c04491 100644 --- a/tests/Unit/Email/EmailSearchTest.php +++ b/tests/Unit/Email/EmailSearchTest.php @@ -1,5 +1,7 @@ 5 + "resultsLimit" => 5, ]; // Perform email search. @@ -40,16 +42,16 @@ public function testSearchResults() /** * Test email search when the input parameter is specified as the entire query. */ - public function testQueryInput() + public function testQueryInput(): void { // Query that will be sent to the API for validation. $query = [ - "value" => "info@" + "value" => "info@", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 5 + "resultsLimit" => 5, ]; // Perform email validation. diff --git a/tests/Unit/Email/EmailValidateTest.php b/tests/Unit/Email/EmailValidateTest.php index 92663c2..b42357a 100644 --- a/tests/Unit/Email/EmailValidateTest.php +++ b/tests/Unit/Email/EmailValidateTest.php @@ -1,5 +1,7 @@ "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -38,14 +40,14 @@ public function testValid() /** * Test invalid email. */ - public function testInvalid() + public function testInvalid(): void { // Email that will be sent to the API for validation. $email = "invalidUser@foxentry.com"; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -63,14 +65,14 @@ public function testInvalid() /** * Test invalid email with suggestion. */ - public function testInvalidWithSuggestion() + public function testInvalidWithSuggestion(): void { // Email that will be sent to the API for validation. $email = "info@gmali.com"; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -88,14 +90,14 @@ public function testInvalidWithSuggestion() /** * Test invalid email with correction. */ - public function testInvalidWithCorrection() + public function testInvalidWithCorrection(): void { // Email that will be sent to the API for validation. $email = "info@foxentry,com"; // Notice the "," instead of "." before the com // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -113,14 +115,14 @@ public function testInvalidWithCorrection() /** * Test invalid email with partial correction. */ - public function testInvalidWithPartialCorrection() + public function testInvalidWithPartialCorrection(): void { // Email that will be sent to the API for validation. $email = "infogmail.com"; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -138,7 +140,7 @@ public function testInvalidWithPartialCorrection() /** * Test disallowed disposable email. */ - public function testDisallowedDisposable() + public function testDisallowedDisposable(): void { // Email that will be sent to the API for validation. $email = "rasini3451@naymedia.com"; @@ -164,7 +166,7 @@ public function testDisallowedDisposable() /** * Test disallowed freemail. */ - public function testDisallowedFreemails() + public function testDisallowedFreemails(): void { // Email that will be sent to the API for validation. $email = "info@gmail.com"; @@ -190,7 +192,7 @@ public function testDisallowedFreemails() /** * Test email validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'orderEmailValidation'; @@ -214,7 +216,7 @@ public function testWithCustomId() /** * Test email validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Email that will be sent to the API for validation. $email = 'info@foxentry.com'; @@ -237,16 +239,16 @@ public function testWithClient() /** * Test email validation when the input parameter is specified as the entire query. */ - public function testQueryInput() + public function testQueryInput(): void { // Query that will be sent to the API for validation. $query = [ - "email" => "info@foxentry.com" + "email" => "info@foxentry.com", ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation. @@ -260,14 +262,14 @@ public function testQueryInput() /** * Test of receiving response headers */ - public function testResponseHeaders() + public function testResponseHeaders(): void { // Email that will be sent to the API for validation. $email = "info@foxentry.com"; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform email validation and get headers of the response. @@ -290,7 +292,7 @@ public function testResponseHeaders() /** * Settings should not persist between calls. */ - public function testInstanceSettings() + public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $email = "info@foxentry.com"; diff --git a/tests/Unit/Location/LocationGetTest.php b/tests/Unit/Location/LocationGetTest.php index d8721d0..7722fc8 100644 --- a/tests/Unit/Location/LocationGetTest.php +++ b/tests/Unit/Location/LocationGetTest.php @@ -1,5 +1,7 @@ "CZ", - "id" => "d2ade877-1e95-4a83-baa6-5431ce5b3ca8" + "id" => "d2ade877-1e95-4a83-baa6-5431ce5b3ca8", ]; // Options that will be sent within the request. $options = [ "idType" => "internal", - "dataScope" => "full" + "dataScope" => "full", ]; // Perform location data retrieval. @@ -40,18 +42,18 @@ public function testGetFullDataScopeByInternalID() /** * Test retrieval of full data scope by external ID. */ - public function getFullDataScopeByExternalID() + public function getFullDataScopeByExternalID(): void { // Query parameters for retrieving location data by external ID. $query = [ "country" => "CZ", - "id" => "22349995" + "id" => "22349995", ]; // Options that will be sent within the request. $options = [ "idType" => "external", - "dataScope" => "full" + "dataScope" => "full", ]; // Perform location data retrieval. @@ -67,7 +69,7 @@ public function getFullDataScopeByExternalID() /** * Test location data retrieval with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -75,13 +77,13 @@ public function testWithCustomId() // Query parameters for location data retrieval. $query = [ "country" => "CZ", - "id" => "22349995" + "id" => "22349995", ]; // Options that will be sent within the request. $options = [ "idType" => "external", - "dataScope" => "full" + "dataScope" => "full", ]; // Perform location data retrieval. @@ -101,18 +103,18 @@ public function testWithCustomId() /** * Test location data retrieval with client information. */ - public function testWithClient() + public function testWithClient(): void { // Query parameters for location data retrieval. $query = [ "country" => "CZ", - "id" => "22349995" + "id" => "22349995", ]; // Options that will be sent within the request. $options = [ "idType" => "external", - "dataScope" => "full" + "dataScope" => "full", ]; // Perform location data retrieval with client information. @@ -134,18 +136,18 @@ public function testWithClient() /** * Settings should not persist between calls. */ - public function testInstanceSettings() + public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ "country" => "CZ", - "id" => "22349995" + "id" => "22349995", ]; // Options that will be sent within the request. $options = [ "idType" => "external", - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform name validation with client information. diff --git a/tests/Unit/Location/LocationLocalizeTest.php b/tests/Unit/Location/LocationLocalizeTest.php index ae670d6..cc69274 100644 --- a/tests/Unit/Location/LocationLocalizeTest.php +++ b/tests/Unit/Location/LocationLocalizeTest.php @@ -1,5 +1,7 @@ 50.0919999, - "lon" => 14.4527403 + "lon" => 14.4527403, ]; // Options that will be sent within the request. $options = [ "resultsLimit" => 10, "radius" => 15, - "acceptNearest" => false + "acceptNearest" => false, ]; // Perform location data localization. @@ -43,7 +45,7 @@ public function testLocalizationResults() /** * Test location data localization with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -51,14 +53,14 @@ public function testWithCustomId() // Query parameters for localizing location data. $query = [ "lat" => 50.0919999, - "lon" => 14.4527403 + "lon" => 14.4527403, ]; // Options that will be sent within the request. $options = [ "resultsLimit" => 10, "radius" => 15, - "acceptNearest" => false + "acceptNearest" => false, ]; // Perform location data localization. @@ -80,19 +82,19 @@ public function testWithCustomId() /** * Test location data localization with client information. */ - public function testWithClient() + public function testWithClient(): void { // Query parameters for localizing location data. $query = [ "lat" => 50.0919999, - "lon" => 14.4527403 + "lon" => 14.4527403, ]; // Options that will be sent within the request. $options = [ "resultsLimit" => 10, "radius" => 15, - "acceptNearest" => false + "acceptNearest" => false, ]; // Perform location data localization with client information. diff --git a/tests/Unit/Location/LocationSearchTest.php b/tests/Unit/Location/LocationSearchTest.php index f63356a..02bfe8f 100644 --- a/tests/Unit/Location/LocationSearchTest.php +++ b/tests/Unit/Location/LocationSearchTest.php @@ -1,5 +1,7 @@ "street", - "value" => "tha" + "value" => "tha", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform street search. @@ -41,17 +43,17 @@ public function testSearchStreet() /** * Test valid city search. */ - public function testSearchCity() + public function testSearchCity(): void { // Input parameters for city search. $query = [ "type" => "city", - "value" => "pra" + "value" => "pra", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform city search. @@ -69,17 +71,17 @@ public function testSearchCity() /** * Test valid street with number search. */ - public function testSearchStreetWithNumber() + public function testSearchStreetWithNumber(): void { // Input parameters for street with number search. $query = [ "type" => "streetWithNumber", - "value" => "Jeseniova 56" + "value" => "Jeseniova 56", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform street with number search. @@ -97,17 +99,17 @@ public function testSearchStreetWithNumber() /** * Test valid ZIP code search. */ - public function testSearchZip() + public function testSearchZip(): void { // Input parameters for ZIP code search. $query = [ "type" => "zip", - "value" => "1" + "value" => "1", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform ZIP code search. @@ -125,17 +127,17 @@ public function testSearchZip() /** * Test valid full address search. */ - public function testSearchFull() + public function testSearchFull(): void { // Input parameters for full location search. $query = [ "type" => "full", - "value" => "Jeseniova Praha" + "value" => "Jeseniova Praha", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform full location search. @@ -153,7 +155,7 @@ public function testSearchFull() /** * Test location data validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -161,12 +163,12 @@ public function testWithCustomId() // Input parameters for street search. $query = [ "type" => "street", - "value" => "tha" + "value" => "tha", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform location data validation. @@ -188,17 +190,17 @@ public function testWithCustomId() /** * Test location data validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Input parameters for street search. $query = [ "type" => "street", - "value" => "tha" + "value" => "tha", ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10 + "resultsLimit" => 10, ]; // Perform location data validation with client information. diff --git a/tests/Unit/Location/LocationValidateTest.php b/tests/Unit/Location/LocationValidateTest.php index e358213..fd248ae 100644 --- a/tests/Unit/Location/LocationValidateTest.php +++ b/tests/Unit/Location/LocationValidateTest.php @@ -1,5 +1,7 @@ "Thámova 137/16", "city" => "Praha", - "zip" => "186 00" + "zip" => "186 00", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation. @@ -44,20 +46,20 @@ public function testValid() /** * Test invalid location data. */ - public function testInvalid() + public function testInvalid(): void { // Query parameters for validating location data. $query = [ "streetWithNumber" => "Thámova 123456789", "city" => "Parharlin", - "zip" => "457545754" + "zip" => "457545754", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation. @@ -75,20 +77,20 @@ public function testInvalid() /** * Test invalid location data with correction. */ - public function testInvalidWithCorrection() + public function testInvalidWithCorrection(): void { // Query parameters for validating location data. $query = [ "streetWithNumber" => "Thámova 137", "city" => "Praha", - "zip" => "18600" + "zip" => "18600", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation. @@ -106,20 +108,20 @@ public function testInvalidWithCorrection() /** * Test invalid location data with suggestion. */ - public function testInvalidWithSuggestion() + public function testInvalidWithSuggestion(): void { // Query parameters for validating location data. $query = [ "streetWithNumber" => "Olšanská 2898/4", "city" => "Praha", - "zip" => "130 00" + "zip" => "130 00", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation. @@ -137,7 +139,7 @@ public function testInvalidWithSuggestion() /** * Test location data validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; @@ -146,14 +148,14 @@ public function testWithCustomId() $query = [ "streetWithNumber" => "Thámova 123456789", "city" => "Parharlin", - "zip" => "457545754" + "zip" => "457545754", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation. @@ -173,20 +175,20 @@ public function testWithCustomId() /** * Test location data validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Query parameters for validating location data. $query = [ "streetWithNumber" => "Thámova 137/16", "city" => "Praha", - "zip" => "186 00" + "zip" => "186 00", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", "cityFormat" => "minimal", - "zipFormat" => true + "zipFormat" => true, ]; // Perform location data validation with client information. diff --git a/tests/Unit/Name/NameValidateTest.php b/tests/Unit/Name/NameValidateTest.php index 7c25558..7e32fb0 100644 --- a/tests/Unit/Name/NameValidateTest.php +++ b/tests/Unit/Name/NameValidateTest.php @@ -1,5 +1,7 @@ "Pavel" + "name" => "Pavel", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform name validation. @@ -40,17 +42,17 @@ public function testValid() /** * Test invalid name. */ - public function testInvalid() + public function testInvalid(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Paeeewas" + "name" => "Paeeewas", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", - "validationDepth" => "strict" + "validationDepth" => "strict", ]; // Perform name validation. @@ -68,17 +70,17 @@ public function testInvalid() /** * Test invalid name with correction. */ - public function testInvalidWithCorrection() + public function testInvalidWithCorrection(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Palve" + "name" => "Palve", ]; // Options that will be sent within the request. $options = [ "dataScope" => "basic", - "validationDepth" => "strict" + "validationDepth" => "strict", ]; // Perform name validation. @@ -96,16 +98,16 @@ public function testInvalidWithCorrection() /** * Test valid full name validation. */ - public function tesValidNameSurnameFullDataScope() + public function tesValidNameSurnameFullDataScope(): void { // Full name that will be sent to the API for validation. $query = [ - "nameSurname" => "Pavel Novák" + "nameSurname" => "Pavel Novák", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "full" + "dataScope" => "full", ]; // Perform full name validation. @@ -123,14 +125,14 @@ public function tesValidNameSurnameFullDataScope() /** * Test name validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'MyCustomID'; // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel" + "name" => "Pavel", ]; // Perform name validation. @@ -149,16 +151,16 @@ public function testWithCustomId() /** * Test name validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel" + "name" => "Pavel", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform name validation with client information. @@ -180,16 +182,16 @@ public function testWithClient() /** * Settings should not persist between calls. */ - public function testInstanceSettings() + public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel" + "name" => "Pavel", ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic" + "dataScope" => "basic", ]; // Perform name validation with client information. diff --git a/tests/Unit/Phone/PhoneValidateTest.php b/tests/Unit/Phone/PhoneValidateTest.php index dde82c4..b127378 100644 --- a/tests/Unit/Phone/PhoneValidateTest.php +++ b/tests/Unit/Phone/PhoneValidateTest.php @@ -1,5 +1,7 @@ "+420607123456" + "numberWithPrefix" => "+420607123456", ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform phone number validation. @@ -40,16 +42,16 @@ public function testValid() /** * Test invalid phone number. */ - public function testInvalid() + public function testInvalid(): void { // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+42060712345" + "numberWithPrefix" => "+42060712345", ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform phone number validation. @@ -67,17 +69,17 @@ public function testInvalid() /** * Test valid phone number with suggestion. */ - public function testValidWithSuggestion() + public function testValidWithSuggestion(): void { // Phone number and prefix that will be sent to the API for validation. $query = [ "prefix" => "+48", - "number" => "728984101" + "number" => "728984101", ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform phone number validation. @@ -95,17 +97,17 @@ public function testValidWithSuggestion() /** * Test invalid phone number with correction. */ - public function testInvalidWithCorrection() + public function testInvalidWithCorrection(): void { // Phone number and prefix that will be sent to the API for validation. $query = [ "prefix" => "+421", - "number" => "607123456" + "number" => "607123456", ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended" + "validationType" => "extended", ]; // Perform phone number validation. @@ -123,14 +125,14 @@ public function testInvalidWithCorrection() /** * Test phone number validation with custom ID. */ - public function testWithCustomId() + public function testWithCustomId(): void { // Custom ID to identify the request. $customRequestID = 'orderPhoneValidation'; // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456" + "numberWithPrefix" => "+420607123456", ]; // Perform phone number validation. @@ -149,11 +151,11 @@ public function testWithCustomId() /** * Test phone number validation with client information. */ - public function testWithClient() + public function testWithClient(): void { // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456" + "numberWithPrefix" => "+420607123456", ]; // Perform phone number validation with client information. @@ -174,11 +176,11 @@ public function testWithClient() /** * Settings should not persist between calls. */ - public function testInstanceSettings() + public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456" + "numberWithPrefix" => "+420607123456", ]; // Perform name validation with client information. From 5f7b4c8557ce49eaf6a15515195f6002b28361ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Tue, 22 Oct 2024 10:35:10 +0200 Subject: [PATCH 3/5] fix: solve static analysis issues --- composer.json | 10 +- composer.lock | 108 +++++++++++++++++- phpstan.neon | 2 +- src/Exception/BadRequestException.php | 5 +- src/Exception/ForbiddenException.php | 5 +- src/Exception/FoxentryException.php | 7 +- src/Exception/NotFoundException.php | 5 +- src/Exception/PaymentRequiredException.php | 5 +- src/Exception/ServerErrorException.php | 5 +- src/Exception/ServiceUnavailableException.php | 5 +- src/Exception/TooManyRequestsException.php | 5 +- src/Exception/UnauthorizedException.php | 5 +- src/Request.php | 21 ++-- src/Resource/BaseResource.php | 22 ++-- src/Response.php | 12 +- tests/Base.php | 9 +- tests/Unit/Company/CompanyGetTest.php | 16 +-- tests/Unit/Company/CompanySearchTest.php | 12 +- tests/Unit/Company/CompanyValidateTest.php | 14 +-- tests/Unit/Email/EmailSearchTest.php | 4 +- tests/Unit/Email/EmailValidateTest.php | 26 ++--- tests/Unit/Location/LocationGetTest.php | 12 +- tests/Unit/Location/LocationLocalizeTest.php | 6 +- tests/Unit/Location/LocationSearchTest.php | 14 +-- tests/Unit/Location/LocationValidateTest.php | 12 +- tests/Unit/Name/NameValidateTest.php | 16 +-- tests/Unit/Phone/PhoneValidateTest.php | 72 ++++++------ 27 files changed, 282 insertions(+), 153 deletions(-) diff --git a/composer.json b/composer.json index 645d2e4..fd3d197 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,9 @@ "phpunit/phpunit": "^11.3.1", "phpstan/phpstan": "^1.12", "squizlabs/php_codesniffer": "^3.10", - "slevomat/coding-standard": "^8.15" + "slevomat/coding-standard": "^8.15", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/extension-installer": "^1.4" }, "autoload": { "psr-4": { @@ -36,13 +38,15 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } }, "scripts": { - "lint": "phpcs", + "lint": "phpcs -s", "lint-fix": "phpcbf", "phpstan": "phpstan analyse -c phpstan.neon", + "test": "phpunit", "check-quality": [ "@lint", "@phpstan" diff --git a/composer.lock b/composer.lock index fd34166..4791c39 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "56102ca8fcca341dfbe833601c23eab3", + "content-hash": "48fd746ba0dd40952e1ee6c95ea3cb48", "packages": [ { "name": "guzzlehttp/guzzle", @@ -918,6 +918,54 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "1.33.0", @@ -1023,6 +1071,58 @@ ], "time": "2024-10-18T11:12:07+00:00" }, + { + "name": "phpstan/phpstan-phpunit", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-phpunit.git", + "reference": "f3ea021866f4263f07ca3636bf22c64be9610c11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/f3ea021866f4263f07ca3636bf22c64be9610c11", + "reference": "f3ea021866f4263f07ca3636bf22c64be9610c11", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.11" + }, + "conflict": { + "phpunit/phpunit": "<7.0" + }, + "require-dev": { + "nikic/php-parser": "^4.13.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-strict-rules": "^1.5.1", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPUnit extensions and rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-phpunit/issues", + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.0" + }, + "time": "2024-04-20T06:39:00+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.7", @@ -2567,13 +2667,13 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.4", + "php": ">=8.1", "ext-json": "*" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/phpstan.neon b/phpstan.neon index 86c2c6c..47a2029 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: level: 8 - phpVersion: 70400 + phpVersion: 80100 tmpDir: %currentWorkingDirectory%/var/tmp/phpstan diff --git a/src/Exception/BadRequestException.php b/src/Exception/BadRequestException.php index 9eba63f..20e2a01 100644 --- a/src/Exception/BadRequestException.php +++ b/src/Exception/BadRequestException.php @@ -17,6 +17,9 @@ final class BadRequestException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 400; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 400; } diff --git a/src/Exception/ForbiddenException.php b/src/Exception/ForbiddenException.php index 297fb66..f18f162 100644 --- a/src/Exception/ForbiddenException.php +++ b/src/Exception/ForbiddenException.php @@ -17,6 +17,9 @@ final class ForbiddenException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 403; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 403; } diff --git a/src/Exception/FoxentryException.php b/src/Exception/FoxentryException.php index 05bcef0..d4ee37f 100644 --- a/src/Exception/FoxentryException.php +++ b/src/Exception/FoxentryException.php @@ -24,7 +24,7 @@ public static function fromRequestException(RequestException $e): self { // Check if the exception has a response if ($e->hasResponse()) { - $statusCode = $e->getResponse()->getStatusCode(); + $statusCode = $e->getResponse()?->getStatusCode() ?? -1; // Switch based on the status code of the response switch ($statusCode) { case 400: @@ -55,9 +55,10 @@ public static function fromRequestException(RequestException $e): self break; default: // Handle the rest with generic FoxentryException class - $foxentryException = new self("Request exception: " . $e->getResponse()->getBody()->getContents(), $statusCode); + $foxentryException = new self("Request exception: " . $e->getMessage(), $statusCode); break; } + return $foxentryException->setResponse($e->getResponse()); } @@ -65,7 +66,7 @@ public static function fromRequestException(RequestException $e): self return new self("Exception: " . $e->getMessage()); } - public function setResponse(ResponseInterface $response): self + public function setResponse(?ResponseInterface $response): self { $this->response = $response; return $this; diff --git a/src/Exception/NotFoundException.php b/src/Exception/NotFoundException.php index 93d80d1..8bb6db5 100644 --- a/src/Exception/NotFoundException.php +++ b/src/Exception/NotFoundException.php @@ -17,6 +17,9 @@ final class NotFoundException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 404; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 404; } diff --git a/src/Exception/PaymentRequiredException.php b/src/Exception/PaymentRequiredException.php index 374bc55..a804ed1 100644 --- a/src/Exception/PaymentRequiredException.php +++ b/src/Exception/PaymentRequiredException.php @@ -17,6 +17,9 @@ final class PaymentRequiredException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 402; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 402; } diff --git a/src/Exception/ServerErrorException.php b/src/Exception/ServerErrorException.php index 8576626..3987871 100644 --- a/src/Exception/ServerErrorException.php +++ b/src/Exception/ServerErrorException.php @@ -17,6 +17,9 @@ final class ServerErrorException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 500; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 500; } diff --git a/src/Exception/ServiceUnavailableException.php b/src/Exception/ServiceUnavailableException.php index e1b9349..76726d1 100644 --- a/src/Exception/ServiceUnavailableException.php +++ b/src/Exception/ServiceUnavailableException.php @@ -17,6 +17,9 @@ final class ServiceUnavailableException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 503; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 503; } diff --git a/src/Exception/TooManyRequestsException.php b/src/Exception/TooManyRequestsException.php index a4cfe17..d76e8ba 100644 --- a/src/Exception/TooManyRequestsException.php +++ b/src/Exception/TooManyRequestsException.php @@ -17,6 +17,9 @@ final class TooManyRequestsException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 429; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 429; } diff --git a/src/Exception/UnauthorizedException.php b/src/Exception/UnauthorizedException.php index 295f535..79b5852 100644 --- a/src/Exception/UnauthorizedException.php +++ b/src/Exception/UnauthorizedException.php @@ -17,6 +17,9 @@ final class UnauthorizedException extends FoxentryException /** * The HTTP status code associated with this exception. * + * @var int */ - protected int $code = 401; + // Native typehint missing, because definition needs to match the native Exception class. + // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint + protected $code = 401; } diff --git a/src/Request.php b/src/Request.php index 2c25c2e..39136c9 100644 --- a/src/Request.php +++ b/src/Request.php @@ -94,8 +94,9 @@ class Request /** * Information about the client making the request (optional). * + * @var array */ - private ?object $client = null; + private ?array $client = null; public function __construct(string $apiVersion, ?string $apiKey) { @@ -183,11 +184,11 @@ public function setClientIP(string $ip): void throw new \InvalidArgumentException("The specified IP address is not valid."); } - if (empty($this->client)) { - $this->client = new \stdClass(); + if ($this->client === null) { + $this->client = []; } - $this->client->ip = $ip; + $this->client['ip'] = $ip; } /** @@ -201,11 +202,11 @@ public function setClientCountry(string $country): void throw new \InvalidArgumentException("The provided country code does not conform to the ISO-3166-1 alpha-2 format."); } - if (empty($this->client)) { - $this->client = new \stdClass(); + if ($this->client === null) { + $this->client = []; } - $this->client->country = $country; + $this->client['country'] = $country; } /** @@ -221,11 +222,11 @@ public function setClientLocation(float $lat, float $lon): void "lon" => $lon, ]; - if (empty($this->client)) { - $this->client = new \stdClass(); + if ($this->client === null) { + $this->client = []; } - $this->client->location = (object)$location; + $this->client['location'] = $location; } /** diff --git a/src/Resource/BaseResource.php b/src/Resource/BaseResource.php index 7c2266c..1cc92c6 100644 --- a/src/Resource/BaseResource.php +++ b/src/Resource/BaseResource.php @@ -40,7 +40,7 @@ public function __construct(Request $request) * * @param bool $value Whether to include request details (default: true) */ - public function includeRequestDetails(bool $value = true): self + public function includeRequestDetails(bool $value = true): static { $this->request->setHeader("Foxentry-Include-Request-Details", $value); return $this; @@ -51,9 +51,9 @@ public function includeRequestDetails(bool $value = true): self * * @param string $id The custom ID to set * - * @return BaseResource Returns $this for method chaining + * @return $this Returns $this for method chaining */ - public function setCustomId(string $id): BaseResource + public function setCustomId(string $id): self { $this->request->setCustomId($id); return $this; @@ -64,9 +64,9 @@ public function setCustomId(string $id): BaseResource * * @param array $options The options to set * - * @return BaseResource Returns $this for method chaining + * @return $this Returns $this for method chaining */ - public function setOptions(array $options): BaseResource + public function setOptions(array $options): self { $this->request->setOptions($options); return $this; @@ -77,9 +77,9 @@ public function setOptions(array $options): BaseResource * * @param string $ip The client IP address * - * @return BaseResource Returns $this for method chaining + * @return $this Returns $this for method chaining */ - public function setClientIP(string $ip): BaseResource + public function setClientIP(string $ip): self { $this->request->setClientIP($ip); return $this; @@ -90,10 +90,10 @@ public function setClientIP(string $ip): BaseResource * * @param string $country The client country code in format ISO-3166-1 alpha-2. * - * @return BaseResource Returns $this for method chaining + * @return $this Returns $this for method chaining * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO-3166-1 alpha-2 country code format */ - public function setClientCountry(string $country): BaseResource + public function setClientCountry(string $country): self { $this->request->setClientCountry($country); return $this; @@ -105,9 +105,9 @@ public function setClientCountry(string $country): BaseResource * @param float $lon The client's longitude * @param float $lat The client's latitude * - * @return BaseResource Returns $this for method chaining + * @return $this Returns $this for method chaining */ - public function setClientLocation(float $lat, float $lon): BaseResource + public function setClientLocation(float $lat, float $lon): self { $this->request->setClientLocation($lat, $lon); return $this; diff --git a/src/Response.php b/src/Response.php index 7d38c7c..11f061e 100644 --- a/src/Response.php +++ b/src/Response.php @@ -66,7 +66,7 @@ public function getHeaders(): array */ public function getRateLimit(): int { - return reset($this->headers['foxentry-rate-limit']); + return (int) reset($this->headers['foxentry-rate-limit']); } /** @@ -76,7 +76,7 @@ public function getRateLimit(): int */ public function getRateLimitPeriod(): int { - return reset($this->headers['foxentry-rate-limit-period']); + return (int) reset($this->headers['foxentry-rate-limit-period']); } /** @@ -86,7 +86,7 @@ public function getRateLimitPeriod(): int */ public function getRateLimitRemaining(): int { - return reset($this->headers['foxentry-rate-limit-remaining']); + return (int) reset($this->headers['foxentry-rate-limit-remaining']); } /** @@ -100,7 +100,7 @@ public function getDailyCreditsLeft(): ?float return null; } - return reset($this->headers['foxentry-daily-credits-left']); + return (float) reset($this->headers['foxentry-daily-credits-left']); } /** @@ -114,7 +114,7 @@ public function getDailyCreditsLimit(): ?int return null; } - return reset($this->headers['foxentry-daily-credits-limit']); + return (int) reset($this->headers['foxentry-daily-credits-limit']); } /** @@ -124,7 +124,7 @@ public function getDailyCreditsLimit(): ?int */ public function getApiVersion(): float { - return reset($this->headers['foxentry-api-version']); + return (float) reset($this->headers['foxentry-api-version']); } /** diff --git a/tests/Base.php b/tests/Base.php index 6e4ec8f..e18f3c9 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -12,12 +12,11 @@ class Base extends TestCase /** * @var ApiClient $api Foxentry API client. */ - protected ApiClient $api; + protected static ApiClient $api; - public function __construct(string $name) + public static function setUpBeforeClass(): void { - parent::__construct($name); - $this->assertNotEmpty($_ENV['API_KEY'], 'You didn\'t set your API key in .env file'); - $this->api = new ApiClient($_ENV['API_KEY']); + self::assertNotEmpty($_ENV['API_KEY'], 'You didn\'t set your API key in .env file'); + self::$api = new ApiClient($_ENV['API_KEY']); } } diff --git a/tests/Unit/Company/CompanyGetTest.php b/tests/Unit/Company/CompanyGetTest.php index 6dd51f4..b612517 100644 --- a/tests/Unit/Company/CompanyGetTest.php +++ b/tests/Unit/Company/CompanyGetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Unit\Location; +namespace Tests\Unit\Company; use Foxentry\Response; use Tests\Base; @@ -29,7 +29,7 @@ public function testBasicDataScope(): void ]; // Perform company data retrieval. - $response = $this->api->company()->setOptions($options)->get($query); + $response = self::$api->company()->setOptions($options)->get($query); $result = $response->getResult(); // Assertions. @@ -55,7 +55,7 @@ public function testExtendedDataScope(): void ]; // Perform company data retrieval. - $response = $this->api->company()->setOptions($options)->get($query); + $response = self::$api->company()->setOptions($options)->get($query); $result = $response->getResult(); // Assertions. @@ -81,7 +81,7 @@ public function testFullDataScope(): void ]; // Perform company data retrieval. - $response = $this->api->company()->setOptions($options)->get($query); + $response = self::$api->company()->setOptions($options)->get($query); $result = $response->getResult(); // Assertions. @@ -110,7 +110,7 @@ public function testWithCustomId(): void ]; // Perform company data retrieval. - $response = $this->api->company() + $response = self::$api->company() ->setCustomId($customRequestID) ->setOptions($options) ->get($query); @@ -140,7 +140,7 @@ public function testWithClient(): void ]; // Perform company data retrieval with client information. - $response = $this->api->company() + $response = self::$api->company() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") @@ -172,7 +172,7 @@ public function testInstanceSettings(): void ]; // Perform name validation with client information. - $response = $this->api->company() + $response = self::$api->company() ->setOptions($options) ->includeRequestDetails() ->get($query); @@ -182,7 +182,7 @@ public function testInstanceSettings(): void $this->assertObjectHasProperty('query', $result); - $response = $this->api->company() + $response = self::$api->company() ->setOptions($options) ->get($query); diff --git a/tests/Unit/Company/CompanySearchTest.php b/tests/Unit/Company/CompanySearchTest.php index 8715459..025f347 100644 --- a/tests/Unit/Company/CompanySearchTest.php +++ b/tests/Unit/Company/CompanySearchTest.php @@ -29,7 +29,7 @@ public function testSearchName(): void ]; // Perform company name search. - $response = $this->api->company()->setOptions($options)->search($query); + $response = self::$api->company()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -57,7 +57,7 @@ public function testSearchRegistrationNumber(): void ]; // Perform registration number search. - $response = $this->api->company()->setOptions($options)->search($query); + $response = self::$api->company()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -85,7 +85,7 @@ public function testSearchTaxNumber(): void ]; // Perform tax number search. - $response = $this->api->company()->setOptions($options)->search($query); + $response = self::$api->company()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -113,7 +113,7 @@ public function testSearchVatNumber(): void ]; // Perform VAT number search. - $response = $this->api->company()->setOptions($options)->search($query); + $response = self::$api->company()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -144,7 +144,7 @@ public function testWithCustomId(): void ]; // Perform company data search. - $response = $this->api->company() + $response = self::$api->company() ->setCustomId($customRequestID) ->setOptions($options) ->search($query); @@ -176,7 +176,7 @@ public function testWithClient(): void ]; // Perform company data search with client information. - $response = $this->api->company() + $response = self::$api->company() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") diff --git a/tests/Unit/Company/CompanyValidateTest.php b/tests/Unit/Company/CompanyValidateTest.php index f09b01e..92f034a 100644 --- a/tests/Unit/Company/CompanyValidateTest.php +++ b/tests/Unit/Company/CompanyValidateTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Unit\Location; +namespace Tests\Unit\Company; use Foxentry\Response; use Tests\Base; @@ -29,7 +29,7 @@ public function testValid(): void ]; // Perform company data validation. - $response = $this->api->company()->setOptions($options)->validate($query); + $response = self::$api->company()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -57,7 +57,7 @@ public function testInvalid(): void ]; // Perform company data validation. - $response = $this->api->company()->setOptions($options)->validate($query); + $response = self::$api->company()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -85,7 +85,7 @@ public function testInvalidWithCorrection(): void ]; // Perform company data validation. - $response = $this->api->company()->setOptions($options)->validate($query); + $response = self::$api->company()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -112,7 +112,7 @@ public function testInvalidWithSuggestion(): void ]; // Perform company data validation. - $response = $this->api->company()->setOptions($options)->validate($query); + $response = self::$api->company()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -143,7 +143,7 @@ public function testWithCustomId(): void ]; // Perform company data validation. - $response = $this->api->company() + $response = self::$api->company() ->setCustomId($customRequestID) ->setOptions($options) ->validate($query); @@ -173,7 +173,7 @@ public function testWithClient(): void ]; // Perform company data validation with client information. - $response = $this->api->company() + $response = self::$api->company() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") diff --git a/tests/Unit/Email/EmailSearchTest.php b/tests/Unit/Email/EmailSearchTest.php index 0c04491..7d63509 100644 --- a/tests/Unit/Email/EmailSearchTest.php +++ b/tests/Unit/Email/EmailSearchTest.php @@ -28,7 +28,7 @@ public function testSearchResults(): void ]; // Perform email search. - $response = $this->api->email()->setOptions($options)->search($input); + $response = self::$api->email()->setOptions($options)->search($input); $result = $response->getResult(); // Assertions. @@ -55,7 +55,7 @@ public function testQueryInput(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->search($query); + $response = self::$api->email()->setOptions($options)->search($query); // Assertions. $this->assertInstanceOf(Response::class, $response); diff --git a/tests/Unit/Email/EmailValidateTest.php b/tests/Unit/Email/EmailValidateTest.php index b42357a..0765779 100644 --- a/tests/Unit/Email/EmailValidateTest.php +++ b/tests/Unit/Email/EmailValidateTest.php @@ -26,7 +26,7 @@ public function testValid(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -51,7 +51,7 @@ public function testInvalid(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -76,7 +76,7 @@ public function testInvalidWithSuggestion(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -101,7 +101,7 @@ public function testInvalidWithCorrection(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -126,7 +126,7 @@ public function testInvalidWithPartialCorrection(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -151,7 +151,7 @@ public function testDisallowedDisposable(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -177,7 +177,7 @@ public function testDisallowedFreemails(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $result = $response->getResult(); // Assertions. @@ -201,7 +201,7 @@ public function testWithCustomId(): void $email = 'info@foxentry.com'; // Perform email validation. - $response = $this->api->email() + $response = self::$api->email() ->setCustomId($customRequestID) ->validate($email); @@ -222,7 +222,7 @@ public function testWithClient(): void $email = 'info@foxentry.com'; // Perform email validation with client information. - $response = $this->api->email() + $response = self::$api->email() ->setClientCountry("CZ") ->setClientIP("127.0.0.1") ->setClientLocation(50.073658, 14.418540) @@ -252,7 +252,7 @@ public function testQueryInput(): void ]; // Perform email validation. - $response = $this->api->email()->setOptions($options)->validate($query); + $response = self::$api->email()->setOptions($options)->validate($query); // Assertions. $this->assertInstanceOf(Response::class, $response); @@ -273,7 +273,7 @@ public function testResponseHeaders(): void ]; // Perform email validation and get headers of the response. - $response = $this->api->email()->setOptions($options)->validate($email); + $response = self::$api->email()->setOptions($options)->validate($email); $headers = $response->getHeaders(); $rateLimit = $response->getRateLimit(); $rateLimitPeriod = $response->getRateLimitPeriod(); @@ -298,7 +298,7 @@ public function testInstanceSettings(): void $email = "info@foxentry.com"; // Perform name validation with client information. - $response = $this->api->email() + $response = self::$api->email() ->includeRequestDetails() ->validate($email); @@ -307,7 +307,7 @@ public function testInstanceSettings(): void $this->assertObjectHasProperty('query', $result); - $response = $this->api->email() + $response = self::$api->email() ->validate($email); $result = $response->getRequest(); diff --git a/tests/Unit/Location/LocationGetTest.php b/tests/Unit/Location/LocationGetTest.php index 7722fc8..5a2bd78 100644 --- a/tests/Unit/Location/LocationGetTest.php +++ b/tests/Unit/Location/LocationGetTest.php @@ -30,7 +30,7 @@ public function testGetFullDataScopeByInternalID(): void ]; // Perform location data retrieval. - $response = $this->api->location()->setOptions($options)->get($query); + $response = self::$api->location()->setOptions($options)->get($query); $result = $response->getResult(); // Assertions. @@ -57,7 +57,7 @@ public function getFullDataScopeByExternalID(): void ]; // Perform location data retrieval. - $response = $this->api->location()->setOptions($options)->get($query); + $response = self::$api->location()->setOptions($options)->get($query); $result = $response->getResult(); // Assertions. @@ -87,7 +87,7 @@ public function testWithCustomId(): void ]; // Perform location data retrieval. - $response = $this->api->location() + $response = self::$api->location() ->setCustomId($customRequestID) ->setOptions($options) ->get($query); @@ -118,7 +118,7 @@ public function testWithClient(): void ]; // Perform location data retrieval with client information. - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") @@ -151,7 +151,7 @@ public function testInstanceSettings(): void ]; // Perform name validation with client information. - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->includeRequestDetails() ->get($query); @@ -161,7 +161,7 @@ public function testInstanceSettings(): void $this->assertObjectHasProperty('query', $result); - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->get($query); diff --git a/tests/Unit/Location/LocationLocalizeTest.php b/tests/Unit/Location/LocationLocalizeTest.php index cc69274..b8240ef 100644 --- a/tests/Unit/Location/LocationLocalizeTest.php +++ b/tests/Unit/Location/LocationLocalizeTest.php @@ -31,7 +31,7 @@ public function testLocalizationResults(): void ]; // Perform location data localization. - $response = $this->api->location()->setOptions($options)->localize($query); + $response = self::$api->location()->setOptions($options)->localize($query); $result = $response->getResult(); // Assertions. @@ -64,7 +64,7 @@ public function testWithCustomId(): void ]; // Perform location data localization. - $response = $this->api->location() + $response = self::$api->location() ->setCustomId($customRequestID) ->setOptions($options) ->localize($query); @@ -98,7 +98,7 @@ public function testWithClient(): void ]; // Perform location data localization with client information. - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") diff --git a/tests/Unit/Location/LocationSearchTest.php b/tests/Unit/Location/LocationSearchTest.php index 02bfe8f..a42ccb6 100644 --- a/tests/Unit/Location/LocationSearchTest.php +++ b/tests/Unit/Location/LocationSearchTest.php @@ -29,7 +29,7 @@ public function testSearchStreet(): void ]; // Perform street search. - $response = $this->api->location()->setOptions($options)->search($query); + $response = self::$api->location()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -57,7 +57,7 @@ public function testSearchCity(): void ]; // Perform city search. - $response = $this->api->location()->setOptions($options)->search($query); + $response = self::$api->location()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -85,7 +85,7 @@ public function testSearchStreetWithNumber(): void ]; // Perform street with number search. - $response = $this->api->location()->setOptions($options)->search($query); + $response = self::$api->location()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -113,7 +113,7 @@ public function testSearchZip(): void ]; // Perform ZIP code search. - $response = $this->api->location()->setOptions($options)->search($query); + $response = self::$api->location()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -141,7 +141,7 @@ public function testSearchFull(): void ]; // Perform full location search. - $response = $this->api->location()->setOptions($options)->search($query); + $response = self::$api->location()->setOptions($options)->search($query); $result = $response->getResult(); // Assertions. @@ -172,7 +172,7 @@ public function testWithCustomId(): void ]; // Perform location data validation. - $response = $this->api->location() + $response = self::$api->location() ->setCustomId($customRequestID) ->setOptions($options) ->search($query); @@ -204,7 +204,7 @@ public function testWithClient(): void ]; // Perform location data validation with client information. - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") diff --git a/tests/Unit/Location/LocationValidateTest.php b/tests/Unit/Location/LocationValidateTest.php index fd248ae..18d4441 100644 --- a/tests/Unit/Location/LocationValidateTest.php +++ b/tests/Unit/Location/LocationValidateTest.php @@ -32,7 +32,7 @@ public function testValid(): void ]; // Perform location data validation. - $response = $this->api->location()->setOptions($options)->validate($query); + $response = self::$api->location()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -63,7 +63,7 @@ public function testInvalid(): void ]; // Perform location data validation. - $response = $this->api->location()->setOptions($options)->validate($query); + $response = self::$api->location()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -94,7 +94,7 @@ public function testInvalidWithCorrection(): void ]; // Perform location data validation. - $response = $this->api->location()->setOptions($options)->validate($query); + $response = self::$api->location()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -125,7 +125,7 @@ public function testInvalidWithSuggestion(): void ]; // Perform location data validation. - $response = $this->api->location()->setOptions($options)->validate($query); + $response = self::$api->location()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -159,7 +159,7 @@ public function testWithCustomId(): void ]; // Perform location data validation. - $response = $this->api->location() + $response = self::$api->location() ->setCustomId($customRequestID) ->setOptions($options) ->validate($query); @@ -192,7 +192,7 @@ public function testWithClient(): void ]; // Perform location data validation with client information. - $response = $this->api->location() + $response = self::$api->location() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") diff --git a/tests/Unit/Name/NameValidateTest.php b/tests/Unit/Name/NameValidateTest.php index 7e32fb0..d650e04 100644 --- a/tests/Unit/Name/NameValidateTest.php +++ b/tests/Unit/Name/NameValidateTest.php @@ -28,7 +28,7 @@ public function testValid(): void ]; // Perform name validation. - $response = $this->api->name()->setOptions($options)->validate($query); + $response = self::$api->name()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -56,7 +56,7 @@ public function testInvalid(): void ]; // Perform name validation. - $response = $this->api->name()->setOptions($options)->validate($query); + $response = self::$api->name()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -84,7 +84,7 @@ public function testInvalidWithCorrection(): void ]; // Perform name validation. - $response = $this->api->name()->setOptions($options)->validate($query); + $response = self::$api->name()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -111,7 +111,7 @@ public function tesValidNameSurnameFullDataScope(): void ]; // Perform full name validation. - $response = $this->api->name()->setOptions($options)->validate($query); + $response = self::$api->name()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. @@ -136,7 +136,7 @@ public function testWithCustomId(): void ]; // Perform name validation. - $response = $this->api->name() + $response = self::$api->name() ->setCustomId($customRequestID) ->validate($query); @@ -164,7 +164,7 @@ public function testWithClient(): void ]; // Perform name validation with client information. - $response = $this->api->name() + $response = self::$api->name() ->setOptions($options) ->setClientCountry("CZ") ->setClientIP("127.0.0.1") @@ -195,7 +195,7 @@ public function testInstanceSettings(): void ]; // Perform name validation with client information. - $response = $this->api->name() + $response = self::$api->name() ->setOptions($options) ->includeRequestDetails() ->validate($query); @@ -205,7 +205,7 @@ public function testInstanceSettings(): void $this->assertObjectHasProperty('query', $result); - $response = $this->api->name() + $response = self::$api->name() ->setOptions($options) ->validate($query); diff --git a/tests/Unit/Phone/PhoneValidateTest.php b/tests/Unit/Phone/PhoneValidateTest.php index b127378..ff339f6 100644 --- a/tests/Unit/Phone/PhoneValidateTest.php +++ b/tests/Unit/Phone/PhoneValidateTest.php @@ -28,15 +28,15 @@ public function testValid(): void ]; // Perform phone number validation. - $response = $this->api->phone()->setOptions($options)->validate($query); + $response = self::$api->phone()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertTrue($result->isValid); - $this->assertEquals("valid", $result->proposal); - $this->assertNotEmpty($result->data); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertTrue($result->isValid); + self::assertEquals("valid", $result->proposal); + self::assertNotEmpty($result->data); } /** @@ -55,15 +55,15 @@ public function testInvalid(): void ]; // Perform phone number validation. - $response = $this->api->phone()->setOptions($options)->validate($query); + $response = self::$api->phone()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); - $this->assertNotEmpty($result->errors); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertFalse($result->isValid); + self::assertEquals("invalid", $result->proposal); + self::assertNotEmpty($result->errors); } /** @@ -83,15 +83,15 @@ public function testValidWithSuggestion(): void ]; // Perform phone number validation. - $response = $this->api->phone()->setOptions($options)->validate($query); + $response = self::$api->phone()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertTrue($result->isValid); - $this->assertEquals("validWithSuggestion", $result->proposal); - $this->assertNotEmpty($response->getSuggestions()); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertTrue($result->isValid); + self::assertEquals("validWithSuggestion", $result->proposal); + self::assertNotEmpty($response->getSuggestions()); } /** @@ -111,15 +111,15 @@ public function testInvalidWithCorrection(): void ]; // Perform phone number validation. - $response = $this->api->phone()->setOptions($options)->validate($query); + $response = self::$api->phone()->setOptions($options)->validate($query); $result = $response->getResult(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithCorrection", $result->proposal); - $this->assertNotEmpty($response->getResultCorrected()); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertFalse($result->isValid); + self::assertEquals("invalidWithCorrection", $result->proposal); + self::assertNotEmpty($response->getResultCorrected()); } /** @@ -136,16 +136,16 @@ public function testWithCustomId(): void ]; // Perform phone number validation. - $response = $this->api->phone() + $response = self::$api->phone() ->setCustomId($customRequestID) ->validate($query); $request = $response->getRequest(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertNotEmpty($request->customId); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertNotEmpty($request->customId); } /** @@ -159,7 +159,7 @@ public function testWithClient(): void ]; // Perform phone number validation with client information. - $response = $this->api->phone() + $response = self::$api->phone() ->setClientCountry("CZ") ->setClientIP("127.0.0.1") ->setClientLocation(50.073658, 14.418540) @@ -168,9 +168,9 @@ public function testWithClient(): void $result = $response->getResult(); // Assertions. - $this->assertInstanceOf(Response::class, $response); - $this->assertEquals(200, $response->getStatus()); - $this->assertTrue($result->isValid); + self::assertInstanceOf(Response::class, $response); + self::assertEquals(200, $response->getStatus()); + self::assertTrue($result->isValid); } /** @@ -184,20 +184,20 @@ public function testInstanceSettings(): void ]; // Perform name validation with client information. - $response = $this->api->phone() + $response = self::$api->phone() ->includeRequestDetails() ->validate($query); $result = $response->getRequest(); - $this->assertObjectHasProperty('query', $result); + self::assertObjectHasProperty('query', $result); - $response = $this->api->phone() + $response = self::$api->phone() ->validate($query); $result = $response->getRequest(); - $this->assertObjectNotHasProperty('query', $result); + self::assertObjectNotHasProperty('query', $result); } } From 223e1042f2f0b3c6bb914e55a1eb0e63826e0ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Tue, 22 Oct 2024 10:36:52 +0200 Subject: [PATCH 4/5] feat: autorun all quality checks --- .github/workflows/test.yml | 2 +- composer.json | 107 +++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8c22e0..8ceb93b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,6 @@ jobs: with: php-version: 8.3 - run: composer install --no-progress --prefer-dist - - run: vendor/bin/phpunit + - run: composer run check-quality env: API_KEY: ${{ secrets.API_KEY }} diff --git a/composer.json b/composer.json index fd3d197..1c9ad4f 100644 --- a/composer.json +++ b/composer.json @@ -1,55 +1,60 @@ { - "name": "foxentry/php-api-client", - "description": "Foxentry.com PHP API client", - "keywords": ["Foxentry", "Foxentry.com"], - "license": "GPL-3.0-or-later", - "authors": [ - { - "name": "Dominik Hošic", - "email": "hosic@avantro.cz" - },{ - "name": "Vojtěch Sajdl", - "email": "sajdl@avantro.cz" - } - ], - "require": { - "php": ">=8.1", - "guzzlehttp/guzzle": "^7.8", - "ext-json": "*" + "name": "foxentry/php-api-client", + "description": "Foxentry.com PHP API client", + "keywords": [ + "Foxentry", + "Foxentry.com" + ], + "license": "GPL-3.0-or-later", + "authors": [ + { + "name": "Dominik Hošic", + "email": "hosic@avantro.cz" }, - "require-dev": { - "phpunit/phpunit": "^11.3.1", - "phpstan/phpstan": "^1.12", - "squizlabs/php_codesniffer": "^3.10", - "slevomat/coding-standard": "^8.15", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/extension-installer": "^1.4" - }, - "autoload": { - "psr-4": { - "Foxentry\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/", - "Tests\\Unit\\": "tests/Unit/" - } - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true - } - }, - "scripts": { - "lint": "phpcs -s", - "lint-fix": "phpcbf", - "phpstan": "phpstan analyse -c phpstan.neon", - "test": "phpunit", - "check-quality": [ - "@lint", - "@phpstan" - ] + { + "name": "Vojtěch Sajdl", + "email": "sajdl@avantro.cz" + } + ], + "require": { + "php": ">=8.1", + "guzzlehttp/guzzle": "^7.8", + "ext-json": "*" + }, + "require-dev": { + "phpunit/phpunit": "^11.3.1", + "phpstan/phpstan": "^1.12", + "squizlabs/php_codesniffer": "^3.10", + "slevomat/coding-standard": "^8.15", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/extension-installer": "^1.4" + }, + "autoload": { + "psr-4": { + "Foxentry\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/", + "Tests\\Unit\\": "tests/Unit/" + } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } + }, + "scripts": { + "lint": "phpcs -s", + "lint-fix": "phpcbf", + "phpstan": "phpstan analyse -c phpstan.neon", + "test": "phpunit", + "check-quality": [ + "@lint", + "@phpstan", + "@test" + ] + } } From 9bc8953653b865351b0cf25e2e3fdee3992f6d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Tue, 22 Oct 2024 10:51:54 +0200 Subject: [PATCH 5/5] chore: prefer single quotes --- phpcs.xml | 2 + src/ApiClient.php | 2 +- src/Exception/FoxentryException.php | 20 ++--- src/Request.php | 38 ++++----- src/Resource/BaseResource.php | 4 +- src/Resource/Email.php | 4 +- tests/Unit/Company/CompanyGetTest.php | 40 +++++----- tests/Unit/Company/CompanySearchTest.php | 40 +++++----- tests/Unit/Company/CompanyValidateTest.php | 46 +++++------ tests/Unit/Email/EmailSearchTest.php | 6 +- tests/Unit/Email/EmailValidateTest.php | 56 ++++++------- tests/Unit/Location/LocationGetTest.php | 44 +++++----- tests/Unit/Location/LocationLocalizeTest.php | 34 ++++---- tests/Unit/Location/LocationSearchTest.php | 46 +++++------ tests/Unit/Location/LocationValidateTest.php | 84 ++++++++++---------- tests/Unit/Name/NameValidateTest.php | 42 +++++----- tests/Unit/Phone/PhoneValidateTest.php | 38 ++++----- 17 files changed, 274 insertions(+), 272 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 2c3f0fb..7f17f87 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -50,6 +50,8 @@ + + src tests diff --git a/src/ApiClient.php b/src/ApiClient.php index aaf5c06..cb6e55b 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -18,7 +18,7 @@ class ApiClient { protected string $apiKey; - protected string $apiVersion = "2.0"; + protected string $apiVersion = '2.0'; /** * ApiClient constructor. diff --git a/src/Exception/FoxentryException.php b/src/Exception/FoxentryException.php index d4ee37f..382b691 100644 --- a/src/Exception/FoxentryException.php +++ b/src/Exception/FoxentryException.php @@ -28,34 +28,34 @@ public static function fromRequestException(RequestException $e): self // Switch based on the status code of the response switch ($statusCode) { case 400: - $foxentryException = new BadRequestException("Request was invalid or cannot be processed."); + $foxentryException = new BadRequestException('Request was invalid or cannot be processed.'); break; case 401: - $foxentryException = new UnauthorizedException("Unauthorized. Did you set your API key?"); + $foxentryException = new UnauthorizedException('Unauthorized. Did you set your API key?'); break; case 402: - $foxentryException = new PaymentRequiredException("Payment is required to access this resource."); + $foxentryException = new PaymentRequiredException('Payment is required to access this resource.'); break; case 403: - $foxentryException = new ForbiddenException("Forbidden."); + $foxentryException = new ForbiddenException('Forbidden.'); break; case 404: - $foxentryException = new NotFoundException("Resource or endpoint requested is not found on the server."); + $foxentryException = new NotFoundException('Resource or endpoint requested is not found on the server.'); break; case 429: $foxentryException = new TooManyRequestsException( - "Too many requests have been made in the given time frame or the daily limit has been reached." + 'Too many requests have been made in the given time frame or the daily limit has been reached.' ); break; case 500: - $foxentryException = new ServerErrorException("Internal server error."); + $foxentryException = new ServerErrorException('Internal server error.'); break; case 503: - $foxentryException = new ServiceUnavailableException("The server is temporarily unable to handle the request"); + $foxentryException = new ServiceUnavailableException('The server is temporarily unable to handle the request'); break; default: // Handle the rest with generic FoxentryException class - $foxentryException = new self("Request exception: " . $e->getMessage(), $statusCode); + $foxentryException = new self('Request exception: ' . $e->getMessage(), $statusCode); break; } @@ -63,7 +63,7 @@ public static function fromRequestException(RequestException $e): self } // Return a generic exception with the original exception message - return new self("Exception: " . $e->getMessage()); + return new self('Exception: ' . $e->getMessage()); } public function setResponse(?ResponseInterface $response): self diff --git a/src/Request.php b/src/Request.php index 39136c9..bd79d45 100644 --- a/src/Request.php +++ b/src/Request.php @@ -27,13 +27,13 @@ class Request * The base URI for the Foxentry API. * */ - private string $baseUri = "https://api.foxentry.com/"; + private string $baseUri = 'https://api.foxentry.com/'; /** * The HTTP request method (e.g., "GET" or "POST"). * */ - private string $method = "POST"; + private string $method = 'POST'; /** * The HTTP headers for the API request. @@ -41,10 +41,10 @@ class Request * @var array */ private array $headers = [ - "Foxentry-Include-Request-Details" => false, - "Content-Type" => "application/json", - "Accept" => "application/json", - "User-Agent" => "FoxentrySdk (PHP/2.3.0; ApiReference/2.0)", + 'Foxentry-Include-Request-Details' => false, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'User-Agent' => 'FoxentrySdk (PHP/2.3.0; ApiReference/2.0)', ]; /** @@ -100,7 +100,7 @@ class Request public function __construct(string $apiVersion, ?string $apiKey) { - $this->setHeader("Api-Version", $apiVersion); + $this->setHeader('Api-Version', $apiVersion); if ($apiKey) { $this->setAuth($apiKey); @@ -119,7 +119,7 @@ public function __construct(string $apiVersion, ?string $apiKey) public function setAuth(string $apiKey): void { $this->apiKey = $apiKey; - $this->setHeader("Authorization", "Bearer $this->apiKey"); + $this->setHeader('Authorization', sprintf('Bearer %s', $this->apiKey)); } /** @@ -181,7 +181,7 @@ public function setEndpoint(string $endpoint): void public function setClientIP(string $ip): void { if (!filter_var($ip, FILTER_VALIDATE_IP)) { - throw new \InvalidArgumentException("The specified IP address is not valid."); + throw new \InvalidArgumentException('The specified IP address is not valid.'); } if ($this->client === null) { @@ -199,7 +199,7 @@ public function setClientIP(string $ip): void public function setClientCountry(string $country): void { if (strlen($country) != 2) { - throw new \InvalidArgumentException("The provided country code does not conform to the ISO-3166-1 alpha-2 format."); + throw new \InvalidArgumentException('The provided country code does not conform to the ISO-3166-1 alpha-2 format.'); } if ($this->client === null) { @@ -218,8 +218,8 @@ public function setClientCountry(string $country): void public function setClientLocation(float $lat, float $lon): void { $location = [ - "lat" => $lat, - "lon" => $lon, + 'lat' => $lat, + 'lon' => $lon, ]; if ($this->client === null) { @@ -251,8 +251,8 @@ public function send(): Response $this->validate(); $response = $this->httpClient->request($this->method, $this->endpoint, [ - "headers" => $this->headers, - "body" => json_encode($this->body), + 'headers' => $this->headers, + 'body' => json_encode($this->body), ]); $responseHeaders = $response->getHeaders(); @@ -270,11 +270,11 @@ public function send(): Response private function buildBody(): void { $body = [ - "request" => [ - "customId" => $this->customId, - "query" => $this->query, - "options" => $this->options, - "client" => $this->client, + 'request' => [ + 'customId' => $this->customId, + 'query' => $this->query, + 'options' => $this->options, + 'client' => $this->client, ], ]; diff --git a/src/Resource/BaseResource.php b/src/Resource/BaseResource.php index 1cc92c6..59c33db 100644 --- a/src/Resource/BaseResource.php +++ b/src/Resource/BaseResource.php @@ -42,7 +42,7 @@ public function __construct(Request $request) */ public function includeRequestDetails(bool $value = true): static { - $this->request->setHeader("Foxentry-Include-Request-Details", $value); + $this->request->setHeader('Foxentry-Include-Request-Details', $value); return $this; } @@ -149,6 +149,6 @@ private function getCallerEndpoint(): string $class = strtolower($class); $method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4)[3]['function']; - return "$class/$method"; + return $class . '/' . $method; } } diff --git a/src/Resource/Email.php b/src/Resource/Email.php index b63393d..a1675a4 100644 --- a/src/Resource/Email.php +++ b/src/Resource/Email.php @@ -41,7 +41,7 @@ final class Email extends BaseResource */ public function validate(string|array $query): Response { - $query = is_array($query) ? $query : ["email" => $query]; + $query = is_array($query) ? $query : ['email' => $query]; return $this->sendRequest($query); } @@ -64,7 +64,7 @@ public function validate(string|array $query): Response */ public function search(string|array $query): Response { - $query = is_array($query) ? $query : ["value" => $query]; + $query = is_array($query) ? $query : ['value' => $query]; return $this->sendRequest($query); } diff --git a/tests/Unit/Company/CompanyGetTest.php b/tests/Unit/Company/CompanyGetTest.php index b612517..e6d6a00 100644 --- a/tests/Unit/Company/CompanyGetTest.php +++ b/tests/Unit/Company/CompanyGetTest.php @@ -19,13 +19,13 @@ public function testBasicDataScope(): void { // Query parameters for retrieving company data by country and registration number. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data retrieval. @@ -45,13 +45,13 @@ public function testExtendedDataScope(): void { // Query parameters for retrieving company data by country and registration number. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "extended", + 'dataScope' => 'extended', ]; // Perform company data retrieval. @@ -71,13 +71,13 @@ public function testFullDataScope(): void { // Query parameters for retrieving company data by country and registration number. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "full", + 'dataScope' => 'full', ]; // Perform company data retrieval. @@ -100,13 +100,13 @@ public function testWithCustomId(): void // Query parameters for company data retrieval. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data retrieval. @@ -130,20 +130,20 @@ public function testWithClient(): void { // Query parameters for company data retrieval. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data retrieval with client information. $response = self::$api->company() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->get($query); @@ -162,13 +162,13 @@ public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "country" => "CZ", - "registrationNumber" => "04997476", + 'country' => 'CZ', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform name validation with client information. diff --git a/tests/Unit/Company/CompanySearchTest.php b/tests/Unit/Company/CompanySearchTest.php index 025f347..c1edfe7 100644 --- a/tests/Unit/Company/CompanySearchTest.php +++ b/tests/Unit/Company/CompanySearchTest.php @@ -19,13 +19,13 @@ public function testSearchName(): void { // Input parameters for company name search. $query = [ - "type" => "name", - "value" => "Web", + 'type' => 'name', + 'value' => 'Web', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform company name search. @@ -47,13 +47,13 @@ public function testSearchRegistrationNumber(): void { // Input parameters for registration number search. $query = [ - "type" => "registrationNumber", - "value" => "10", + 'type' => 'registrationNumber', + 'value' => '10', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform registration number search. @@ -75,13 +75,13 @@ public function testSearchTaxNumber(): void { // Input parameters for tax number search. $query = [ - "type" => "taxNumber", - "value" => "10", + 'type' => 'taxNumber', + 'value' => '10', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform tax number search. @@ -103,13 +103,13 @@ public function testSearchVatNumber(): void { // Input parameters for VAT number search. $query = [ - "type" => "vatNumber", - "value" => "CZ04997476", + 'type' => 'vatNumber', + 'value' => 'CZ04997476', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform VAT number search. @@ -134,13 +134,13 @@ public function testWithCustomId(): void // Input parameters for company name search. $query = [ - "type" => "name", - "value" => "Web", + 'type' => 'name', + 'value' => 'Web', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform company data search. @@ -166,20 +166,20 @@ public function testWithClient(): void { // Input parameters for company name search. $query = [ - "type" => "name", - "value" => "Web", + 'type' => 'name', + 'value' => 'Web', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform company data search with client information. $response = self::$api->company() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->search($query); diff --git a/tests/Unit/Company/CompanyValidateTest.php b/tests/Unit/Company/CompanyValidateTest.php index 92f034a..9e8e3bd 100644 --- a/tests/Unit/Company/CompanyValidateTest.php +++ b/tests/Unit/Company/CompanyValidateTest.php @@ -19,13 +19,13 @@ public function testValid(): void { // Query parameters for validating company data. $query = [ - "name" => "AVANTRO s.r.o.", - "registrationNumber" => "04997476", + 'name' => 'AVANTRO s.r.o.', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation. @@ -36,7 +36,7 @@ public function testValid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertTrue($result->isValid); - $this->assertEquals("valid", $result->proposal); + $this->assertEquals('valid', $result->proposal); $this->assertNotEmpty($result->data); } @@ -47,13 +47,13 @@ public function testInvalid(): void { // Query parameters for validating company data. $query = [ - "name" => "AVANTRO", - "registrationNumber" => "25547", + 'name' => 'AVANTRO', + 'registrationNumber' => '25547', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation. @@ -64,7 +64,7 @@ public function testInvalid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertNotEmpty($result->errors); } @@ -75,13 +75,13 @@ public function testInvalidWithCorrection(): void { // Query parameters for validating company data. $query = [ - "name" => "AVANTRO", - "registrationNumber" => "04997476", + 'name' => 'AVANTRO', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation. @@ -92,7 +92,7 @@ public function testInvalidWithCorrection(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithCorrection", $result->proposal); + $this->assertEquals('invalidWithCorrection', $result->proposal); $this->assertNotEmpty($response->getResultCorrected()); } @@ -103,12 +103,12 @@ public function testInvalidWithSuggestion(): void { // Query parameters for validating company data. $query = [ - "registrationNumber" => "0499747", + 'registrationNumber' => '0499747', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation. @@ -119,7 +119,7 @@ public function testInvalidWithSuggestion(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithSuggestion", $result->proposal); + $this->assertEquals('invalidWithSuggestion', $result->proposal); $this->assertNotEmpty($response->getSuggestions()); } @@ -133,13 +133,13 @@ public function testWithCustomId(): void // Query parameters for validating company data. $query = [ - "name" => "AVANTRO s.r.o.", - "registrationNumber" => "04997476", + 'name' => 'AVANTRO s.r.o.', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation. @@ -163,20 +163,20 @@ public function testWithClient(): void { // Query parameters for validating company data. $query = [ - "name" => "AVANTRO s.r.o.", - "registrationNumber" => "04997476", + 'name' => 'AVANTRO s.r.o.', + 'registrationNumber' => '04997476', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform company data validation with client information. $response = self::$api->company() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->validate($query); diff --git a/tests/Unit/Email/EmailSearchTest.php b/tests/Unit/Email/EmailSearchTest.php index 7d63509..ac02347 100644 --- a/tests/Unit/Email/EmailSearchTest.php +++ b/tests/Unit/Email/EmailSearchTest.php @@ -24,7 +24,7 @@ public function testSearchResults(): void // Options that will be sent within the request. $options = [ - "resultsLimit" => 5, + 'resultsLimit' => 5, ]; // Perform email search. @@ -46,12 +46,12 @@ public function testQueryInput(): void { // Query that will be sent to the API for validation. $query = [ - "value" => "info@", + 'value' => 'info@', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 5, + 'resultsLimit' => 5, ]; // Perform email validation. diff --git a/tests/Unit/Email/EmailValidateTest.php b/tests/Unit/Email/EmailValidateTest.php index 0765779..0c9c2dc 100644 --- a/tests/Unit/Email/EmailValidateTest.php +++ b/tests/Unit/Email/EmailValidateTest.php @@ -18,11 +18,11 @@ class EmailValidateTest extends Base public function testValid(): void { // Email that will be sent to the API for validation. - $email = "info@foxentry.com"; + $email = 'info@foxentry.com'; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -33,7 +33,7 @@ public function testValid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertTrue($result->isValid); - $this->assertEquals("valid", $result->proposal); + $this->assertEquals('valid', $result->proposal); $this->assertNotEmpty($result->data); } @@ -43,11 +43,11 @@ public function testValid(): void public function testInvalid(): void { // Email that will be sent to the API for validation. - $email = "invalidUser@foxentry.com"; + $email = 'invalidUser@foxentry.com'; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -58,7 +58,7 @@ public function testInvalid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertNotEmpty($result->errors); } @@ -68,11 +68,11 @@ public function testInvalid(): void public function testInvalidWithSuggestion(): void { // Email that will be sent to the API for validation. - $email = "info@gmali.com"; + $email = 'info@gmali.com'; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -83,7 +83,7 @@ public function testInvalidWithSuggestion(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithSuggestion", $result->proposal); + $this->assertEquals('invalidWithSuggestion', $result->proposal); $this->assertNotEmpty($response->getSuggestions()); } @@ -93,11 +93,11 @@ public function testInvalidWithSuggestion(): void public function testInvalidWithCorrection(): void { // Email that will be sent to the API for validation. - $email = "info@foxentry,com"; // Notice the "," instead of "." before the com + $email = 'info@foxentry,com'; // Notice the "," instead of "." before the com // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -108,7 +108,7 @@ public function testInvalidWithCorrection(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithCorrection", $result->proposal); + $this->assertEquals('invalidWithCorrection', $result->proposal); $this->assertNotEmpty($response->getResultCorrected()); } @@ -118,11 +118,11 @@ public function testInvalidWithCorrection(): void public function testInvalidWithPartialCorrection(): void { // Email that will be sent to the API for validation. - $email = "infogmail.com"; + $email = 'infogmail.com'; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -133,7 +133,7 @@ public function testInvalidWithPartialCorrection(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithPartialCorrection", $result->proposal); + $this->assertEquals('invalidWithPartialCorrection', $result->proposal); $this->assertNotEmpty($response->getResultCorrected()); } @@ -143,11 +143,11 @@ public function testInvalidWithPartialCorrection(): void public function testDisallowedDisposable(): void { // Email that will be sent to the API for validation. - $email = "rasini3451@naymedia.com"; + $email = 'rasini3451@naymedia.com'; // Options that will be sent within the request. $options = [ - "acceptDisposableEmails" => false, + 'acceptDisposableEmails' => false, ]; // Perform email validation. @@ -158,7 +158,7 @@ public function testDisallowedDisposable(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertTrue($result->flags->isDisposableEmailAddress); $this->assertNotEmpty($result->errors); } @@ -169,11 +169,11 @@ public function testDisallowedDisposable(): void public function testDisallowedFreemails(): void { // Email that will be sent to the API for validation. - $email = "info@gmail.com"; + $email = 'info@gmail.com'; // Options that will be sent within the request. $options = [ - "acceptFreemails" => false, + 'acceptFreemails' => false, ]; // Perform email validation. @@ -184,7 +184,7 @@ public function testDisallowedFreemails(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertTrue($result->flags->isFreemail); $this->assertNotEmpty($result->errors); } @@ -223,8 +223,8 @@ public function testWithClient(): void // Perform email validation with client information. $response = self::$api->email() - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->validate($email); @@ -243,12 +243,12 @@ public function testQueryInput(): void { // Query that will be sent to the API for validation. $query = [ - "email" => "info@foxentry.com", + 'email' => 'info@foxentry.com', ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation. @@ -265,11 +265,11 @@ public function testQueryInput(): void public function testResponseHeaders(): void { // Email that will be sent to the API for validation. - $email = "info@foxentry.com"; + $email = 'info@foxentry.com'; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform email validation and get headers of the response. @@ -295,7 +295,7 @@ public function testResponseHeaders(): void public function testInstanceSettings(): void { // Name that will be sent to the API for validation. - $email = "info@foxentry.com"; + $email = 'info@foxentry.com'; // Perform name validation with client information. $response = self::$api->email() diff --git a/tests/Unit/Location/LocationGetTest.php b/tests/Unit/Location/LocationGetTest.php index 5a2bd78..208499d 100644 --- a/tests/Unit/Location/LocationGetTest.php +++ b/tests/Unit/Location/LocationGetTest.php @@ -19,14 +19,14 @@ public function testGetFullDataScopeByInternalID(): void { // Query parameters for retrieving location data by internal ID. $query = [ - "country" => "CZ", - "id" => "d2ade877-1e95-4a83-baa6-5431ce5b3ca8", + 'country' => 'CZ', + 'id' => 'd2ade877-1e95-4a83-baa6-5431ce5b3ca8', ]; // Options that will be sent within the request. $options = [ - "idType" => "internal", - "dataScope" => "full", + 'idType' => 'internal', + 'dataScope' => 'full', ]; // Perform location data retrieval. @@ -46,14 +46,14 @@ public function getFullDataScopeByExternalID(): void { // Query parameters for retrieving location data by external ID. $query = [ - "country" => "CZ", - "id" => "22349995", + 'country' => 'CZ', + 'id' => '22349995', ]; // Options that will be sent within the request. $options = [ - "idType" => "external", - "dataScope" => "full", + 'idType' => 'external', + 'dataScope' => 'full', ]; // Perform location data retrieval. @@ -76,14 +76,14 @@ public function testWithCustomId(): void // Query parameters for location data retrieval. $query = [ - "country" => "CZ", - "id" => "22349995", + 'country' => 'CZ', + 'id' => '22349995', ]; // Options that will be sent within the request. $options = [ - "idType" => "external", - "dataScope" => "full", + 'idType' => 'external', + 'dataScope' => 'full', ]; // Perform location data retrieval. @@ -107,21 +107,21 @@ public function testWithClient(): void { // Query parameters for location data retrieval. $query = [ - "country" => "CZ", - "id" => "22349995", + 'country' => 'CZ', + 'id' => '22349995', ]; // Options that will be sent within the request. $options = [ - "idType" => "external", - "dataScope" => "full", + 'idType' => 'external', + 'dataScope' => 'full', ]; // Perform location data retrieval with client information. $response = self::$api->location() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->get($query); @@ -140,14 +140,14 @@ public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "country" => "CZ", - "id" => "22349995", + 'country' => 'CZ', + 'id' => '22349995', ]; // Options that will be sent within the request. $options = [ - "idType" => "external", - "dataScope" => "basic", + 'idType' => 'external', + 'dataScope' => 'basic', ]; // Perform name validation with client information. diff --git a/tests/Unit/Location/LocationLocalizeTest.php b/tests/Unit/Location/LocationLocalizeTest.php index b8240ef..ad52781 100644 --- a/tests/Unit/Location/LocationLocalizeTest.php +++ b/tests/Unit/Location/LocationLocalizeTest.php @@ -19,15 +19,15 @@ public function testLocalizationResults(): void { // Query parameters for localizing location data. $query = [ - "lat" => 50.0919999, - "lon" => 14.4527403, + 'lat' => 50.0919999, + 'lon' => 14.4527403, ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, - "radius" => 15, - "acceptNearest" => false, + 'resultsLimit' => 10, + 'radius' => 15, + 'acceptNearest' => false, ]; // Perform location data localization. @@ -52,15 +52,15 @@ public function testWithCustomId(): void // Query parameters for localizing location data. $query = [ - "lat" => 50.0919999, - "lon" => 14.4527403, + 'lat' => 50.0919999, + 'lon' => 14.4527403, ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, - "radius" => 15, - "acceptNearest" => false, + 'resultsLimit' => 10, + 'radius' => 15, + 'acceptNearest' => false, ]; // Perform location data localization. @@ -86,22 +86,22 @@ public function testWithClient(): void { // Query parameters for localizing location data. $query = [ - "lat" => 50.0919999, - "lon" => 14.4527403, + 'lat' => 50.0919999, + 'lon' => 14.4527403, ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, - "radius" => 15, - "acceptNearest" => false, + 'resultsLimit' => 10, + 'radius' => 15, + 'acceptNearest' => false, ]; // Perform location data localization with client information. $response = self::$api->location() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->localize($query); diff --git a/tests/Unit/Location/LocationSearchTest.php b/tests/Unit/Location/LocationSearchTest.php index a42ccb6..9774d1a 100644 --- a/tests/Unit/Location/LocationSearchTest.php +++ b/tests/Unit/Location/LocationSearchTest.php @@ -19,13 +19,13 @@ public function testSearchStreet(): void { // Input parameters for street search. $query = [ - "type" => "street", - "value" => "tha", + 'type' => 'street', + 'value' => 'tha', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform street search. @@ -47,13 +47,13 @@ public function testSearchCity(): void { // Input parameters for city search. $query = [ - "type" => "city", - "value" => "pra", + 'type' => 'city', + 'value' => 'pra', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform city search. @@ -75,13 +75,13 @@ public function testSearchStreetWithNumber(): void { // Input parameters for street with number search. $query = [ - "type" => "streetWithNumber", - "value" => "Jeseniova 56", + 'type' => 'streetWithNumber', + 'value' => 'Jeseniova 56', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform street with number search. @@ -103,13 +103,13 @@ public function testSearchZip(): void { // Input parameters for ZIP code search. $query = [ - "type" => "zip", - "value" => "1", + 'type' => 'zip', + 'value' => '1', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform ZIP code search. @@ -131,13 +131,13 @@ public function testSearchFull(): void { // Input parameters for full location search. $query = [ - "type" => "full", - "value" => "Jeseniova Praha", + 'type' => 'full', + 'value' => 'Jeseniova Praha', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform full location search. @@ -162,13 +162,13 @@ public function testWithCustomId(): void // Input parameters for street search. $query = [ - "type" => "street", - "value" => "tha", + 'type' => 'street', + 'value' => 'tha', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform location data validation. @@ -194,20 +194,20 @@ public function testWithClient(): void { // Input parameters for street search. $query = [ - "type" => "street", - "value" => "tha", + 'type' => 'street', + 'value' => 'tha', ]; // Options that will be sent within the request. $options = [ - "resultsLimit" => 10, + 'resultsLimit' => 10, ]; // Perform location data validation with client information. $response = self::$api->location() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->search($query); diff --git a/tests/Unit/Location/LocationValidateTest.php b/tests/Unit/Location/LocationValidateTest.php index 18d4441..153d484 100644 --- a/tests/Unit/Location/LocationValidateTest.php +++ b/tests/Unit/Location/LocationValidateTest.php @@ -19,16 +19,16 @@ public function testValid(): void { // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Thámova 137/16", - "city" => "Praha", - "zip" => "186 00", + 'streetWithNumber' => 'Thámova 137/16', + 'city' => 'Praha', + 'zip' => '186 00', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation. @@ -39,7 +39,7 @@ public function testValid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertTrue($result->isValid); - $this->assertEquals("valid", $result->proposal); + $this->assertEquals('valid', $result->proposal); $this->assertNotEmpty($result->data); } @@ -50,16 +50,16 @@ public function testInvalid(): void { // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Thámova 123456789", - "city" => "Parharlin", - "zip" => "457545754", + 'streetWithNumber' => 'Thámova 123456789', + 'city' => 'Parharlin', + 'zip' => '457545754', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation. @@ -70,7 +70,7 @@ public function testInvalid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertNotEmpty($result->errors); } @@ -81,16 +81,16 @@ public function testInvalidWithCorrection(): void { // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Thámova 137", - "city" => "Praha", - "zip" => "18600", + 'streetWithNumber' => 'Thámova 137', + 'city' => 'Praha', + 'zip' => '18600', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation. @@ -101,7 +101,7 @@ public function testInvalidWithCorrection(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithCorrection", $result->proposal); + $this->assertEquals('invalidWithCorrection', $result->proposal); $this->assertNotEmpty($response->getResultCorrected()); } @@ -112,16 +112,16 @@ public function testInvalidWithSuggestion(): void { // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Olšanská 2898/4", - "city" => "Praha", - "zip" => "130 00", + 'streetWithNumber' => 'Olšanská 2898/4', + 'city' => 'Praha', + 'zip' => '130 00', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation. @@ -132,7 +132,7 @@ public function testInvalidWithSuggestion(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithSuggestion", $result->proposal); + $this->assertEquals('invalidWithSuggestion', $result->proposal); $this->assertNotEmpty($response->getSuggestions()); } @@ -146,16 +146,16 @@ public function testWithCustomId(): void // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Thámova 123456789", - "city" => "Parharlin", - "zip" => "457545754", + 'streetWithNumber' => 'Thámova 123456789', + 'city' => 'Parharlin', + 'zip' => '457545754', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation. @@ -179,23 +179,23 @@ public function testWithClient(): void { // Query parameters for validating location data. $query = [ - "streetWithNumber" => "Thámova 137/16", - "city" => "Praha", - "zip" => "186 00", + 'streetWithNumber' => 'Thámova 137/16', + 'city' => 'Praha', + 'zip' => '186 00', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "cityFormat" => "minimal", - "zipFormat" => true, + 'dataScope' => 'basic', + 'cityFormat' => 'minimal', + 'zipFormat' => true, ]; // Perform location data validation with client information. $response = self::$api->location() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->validate($query); diff --git a/tests/Unit/Name/NameValidateTest.php b/tests/Unit/Name/NameValidateTest.php index d650e04..7123723 100644 --- a/tests/Unit/Name/NameValidateTest.php +++ b/tests/Unit/Name/NameValidateTest.php @@ -19,12 +19,12 @@ public function testValid(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel", + 'name' => 'Pavel', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform name validation. @@ -35,7 +35,7 @@ public function testValid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertTrue($result->isValid); - $this->assertEquals("valid", $result->proposal); + $this->assertEquals('valid', $result->proposal); $this->assertNotEmpty($result->data); } @@ -46,13 +46,13 @@ public function testInvalid(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Paeeewas", + 'name' => 'Paeeewas', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "validationDepth" => "strict", + 'dataScope' => 'basic', + 'validationDepth' => 'strict', ]; // Perform name validation. @@ -63,7 +63,7 @@ public function testInvalid(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalid", $result->proposal); + $this->assertEquals('invalid', $result->proposal); $this->assertNotEmpty($result->errors); } @@ -74,13 +74,13 @@ public function testInvalidWithCorrection(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Palve", + 'name' => 'Palve', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", - "validationDepth" => "strict", + 'dataScope' => 'basic', + 'validationDepth' => 'strict', ]; // Perform name validation. @@ -91,7 +91,7 @@ public function testInvalidWithCorrection(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("invalidWithCorrection", $result->proposal); + $this->assertEquals('invalidWithCorrection', $result->proposal); $this->assertNotEmpty($response->getResultCorrected()); } @@ -102,12 +102,12 @@ public function tesValidNameSurnameFullDataScope(): void { // Full name that will be sent to the API for validation. $query = [ - "nameSurname" => "Pavel Novák", + 'nameSurname' => 'Pavel Novák', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "full", + 'dataScope' => 'full', ]; // Perform full name validation. @@ -118,7 +118,7 @@ public function tesValidNameSurnameFullDataScope(): void $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->getStatus()); $this->assertFalse($result->isValid); - $this->assertEquals("valid", $result->proposal); + $this->assertEquals('valid', $result->proposal); $this->assertNotEmpty($result->details); } @@ -132,7 +132,7 @@ public function testWithCustomId(): void // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel", + 'name' => 'Pavel', ]; // Perform name validation. @@ -155,19 +155,19 @@ public function testWithClient(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel", + 'name' => 'Pavel', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform name validation with client information. $response = self::$api->name() ->setOptions($options) - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->validate($query); @@ -186,12 +186,12 @@ public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "name" => "Pavel", + 'name' => 'Pavel', ]; // Options that will be sent within the request. $options = [ - "dataScope" => "basic", + 'dataScope' => 'basic', ]; // Perform name validation with client information. diff --git a/tests/Unit/Phone/PhoneValidateTest.php b/tests/Unit/Phone/PhoneValidateTest.php index ff339f6..b2daa9d 100644 --- a/tests/Unit/Phone/PhoneValidateTest.php +++ b/tests/Unit/Phone/PhoneValidateTest.php @@ -19,12 +19,12 @@ public function testValid(): void { // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456", + 'numberWithPrefix' => '+420607123456', ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform phone number validation. @@ -35,7 +35,7 @@ public function testValid(): void self::assertInstanceOf(Response::class, $response); self::assertEquals(200, $response->getStatus()); self::assertTrue($result->isValid); - self::assertEquals("valid", $result->proposal); + self::assertEquals('valid', $result->proposal); self::assertNotEmpty($result->data); } @@ -46,12 +46,12 @@ public function testInvalid(): void { // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+42060712345", + 'numberWithPrefix' => '+42060712345', ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform phone number validation. @@ -62,7 +62,7 @@ public function testInvalid(): void self::assertInstanceOf(Response::class, $response); self::assertEquals(200, $response->getStatus()); self::assertFalse($result->isValid); - self::assertEquals("invalid", $result->proposal); + self::assertEquals('invalid', $result->proposal); self::assertNotEmpty($result->errors); } @@ -73,13 +73,13 @@ public function testValidWithSuggestion(): void { // Phone number and prefix that will be sent to the API for validation. $query = [ - "prefix" => "+48", - "number" => "728984101", + 'prefix' => '+48', + 'number' => '728984101', ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform phone number validation. @@ -90,7 +90,7 @@ public function testValidWithSuggestion(): void self::assertInstanceOf(Response::class, $response); self::assertEquals(200, $response->getStatus()); self::assertTrue($result->isValid); - self::assertEquals("validWithSuggestion", $result->proposal); + self::assertEquals('validWithSuggestion', $result->proposal); self::assertNotEmpty($response->getSuggestions()); } @@ -101,13 +101,13 @@ public function testInvalidWithCorrection(): void { // Phone number and prefix that will be sent to the API for validation. $query = [ - "prefix" => "+421", - "number" => "607123456", + 'prefix' => '+421', + 'number' => '607123456', ]; // Options that will be sent within the request. $options = [ - "validationType" => "extended", + 'validationType' => 'extended', ]; // Perform phone number validation. @@ -118,7 +118,7 @@ public function testInvalidWithCorrection(): void self::assertInstanceOf(Response::class, $response); self::assertEquals(200, $response->getStatus()); self::assertFalse($result->isValid); - self::assertEquals("invalidWithCorrection", $result->proposal); + self::assertEquals('invalidWithCorrection', $result->proposal); self::assertNotEmpty($response->getResultCorrected()); } @@ -132,7 +132,7 @@ public function testWithCustomId(): void // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456", + 'numberWithPrefix' => '+420607123456', ]; // Perform phone number validation. @@ -155,13 +155,13 @@ public function testWithClient(): void { // Phone number with prefix that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456", + 'numberWithPrefix' => '+420607123456', ]; // Perform phone number validation with client information. $response = self::$api->phone() - ->setClientCountry("CZ") - ->setClientIP("127.0.0.1") + ->setClientCountry('CZ') + ->setClientIP('127.0.0.1') ->setClientLocation(50.073658, 14.418540) ->validate($query); @@ -180,7 +180,7 @@ public function testInstanceSettings(): void { // Name that will be sent to the API for validation. $query = [ - "numberWithPrefix" => "+420607123456", + 'numberWithPrefix' => '+420607123456', ]; // Perform name validation with client information.