Skip to content

Commit

Permalink
preparing 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Mar 14, 2024
1 parent c9356fd commit ede02a9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 67 deletions.
16 changes: 1 addition & 15 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@

declare(strict_types=1);

$header = <<<'EOF'
This file is part of the Numverify API Client for PHP.
(c) 2024 Eric Sizemore <admin@secondversion.com>
(c) 2018-2021 Mark Rogoyski <mark@rogoyski.com>
@license The MIT License
For the full copyright and license information, please view the LICENSE.md
file that was distributed with this source code.
EOF;

$config = new PhpCsFixer\Config();

$config
->setRiskyAllowed(true)
->setRules([
Expand Down Expand Up @@ -65,8 +52,7 @@
'declare_equal_normalize' => ['space' => 'none'],
'declare_parentheses' => true,
'declare_strict_types' => true,
'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'separate' => 'top'],
//'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
])
->setLineEnding("\n")
->setFinder(
Expand Down
51 changes: 29 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
## CHANGELOG
# CHANGELOG
A not so exhaustive list of changes for each release.

For a more detailed listing of changes between each version,
you can use the following url: https://github.com/ericsizemore/api/compare/v3.0.0...v3.0.1.

Simply replace the version numbers depending on which set of changes you wish to see.

### 3.0.1 (Not released, in progress)

#### Changed
## 3.0.1 (2024-03-13)

### Added

* `vimeo/psalm` added into dev-dependencies and workflow
* `TestDox` attribute used for all unit tests instead of '@testCase' (work in progress)

### Changed

* Updates throughout to fix psalm-reported issues.
* Initially level 2, now should be valid on Psalm level 1.
Expand All @@ -17,22 +23,32 @@ Simply replace the version numbers depending on which set of changes you wish to
* `validateAndDecodeResponse`
* `getUrl`
* Modifed `Numverify\PhoneNumber\PhoneNumberInterface` to extend `JsonSerializable`, `Stringable`
* Refactored `validateAndDecodeResponse` and `buildCacheHandler`

#### Added

* `vimeo/psalm` added into dev-dependencies and workflow
* `TestDox` attribute used for all unit tests instead of '@testCase' (work in progress)

#### Removed
### Removed

* Removed unnecessary constructor and properties from `Numverify\Exception\NumverifyApiResponseException`
* Removed '@testCase' annotation from all unit tests.

### 3.0.0 (2024-03-10)
### TODO

* At the moment the cache middleware for Guzzle is using files. For 3.1, perhaps I could look into supporting Redis, Memcached, etc.


## 3.0.0 (2024-03-10)

Forked from [`markrogoyski/numverify-api-client-php`](https://github.com/markrogoyski/numverify-api-client-php) v2.2.0.

#### Changed
### Added

* Guzzle cache support via `kevinrob/guzzle-cache-middleware` and `symfony/cache`.
* New function `Api::buildCacheHandler` which will add the cache middleware to the handler stack if $options['cachePath'] is passed to Api's constructor.
* Imports for all used functions, constants, and class names.
* dev-dependencies for PHP-CS-Fixer and PHPStan (w/extensions for phpunit, strict rules)
* New workflow for static analysis: `.github/workflows/analysis.yml`
* CHANGELOG.md, SECURITY.md

### Changed

* Updated composer.json
* Bumped minimum PHP version to 8.2
Expand All @@ -54,22 +70,13 @@ Forked from [`markrogoyski/numverify-api-client-php`](https://github.com/markrog
* Any class implementing `JsonSerializable` now also implements `Stringable`.
* Updated README.md

#### Added

* Guzzle cache support via `kevinrob/guzzle-cache-middleware` and `symfony/cache`.
* New function `Api::buildCacheHandler` which will add the cache middleware to the handler stack if $options['cachePath'] is passed to Api's constructor.
* Imports for all used functions, constants, and class names.
* dev-dependencies for PHP-CS-Fixer and PHPStan (w/extensions for phpunit, strict rules)
* New workflow for static analysis: `.github/workflows/analysis.yml`
* CHANGELOG.md, SECURITY.md

#### Removed
### Removed

* `.github/workflows/test_develop_and_master.yml`, replaced with `.github/workflows/tests.yml`
* `.github/workflows/test_other_branches.yml`, replaced with `.github/workflows/tests.yml`
* `.github/workflows/test_pull_request.yml`, replaced with `.github/workflows/tests.yml`
* `tests/bootstrap.php`, `tests/phpunit.xml`, `tests/coding_standard.xml`

#### TODO/WIP
### TODO/WIP

* Documentation improvements.
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 20 additions & 22 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
*/
class Api
{
/**
* Current version of the Numverify package.
*
* @var string
*/
public const LIBRARY_VERSION = '3.0.1';

/**
* URL for Numverify's "Free" plan.
*
Expand Down Expand Up @@ -150,8 +157,7 @@ public function validatePhoneNumber(string $phoneNumber, string $countryCode = '
]);
} catch (ServerException $serverException) {
// >= 400 <= 500 status code
// wrapping ServerException with NumverifyApiFailureException as just checking
// getStatusCode() !== 200, like in self::validateAndDecodeResponse(), won't work on server error codes.
// wrap ServerException with NumverifyApiFailureException
throw new NumverifyApiFailureException($serverException->getResponse());
}

Expand All @@ -177,8 +183,7 @@ public function getCountries(): Collection
]);
} catch (ServerException $serverException) {
// >= 400 <= 500 status code
// wrapping ServerException with NumverifyApiFailureException as just checking
// getStatusCode() !== 200, like in self::validateAndDecodeResponse(), won't work on server error codes.
// wrap ServerException with NumverifyApiFailureException
throw new NumverifyApiFailureException($serverException->getResponse());
}

Expand Down Expand Up @@ -220,28 +225,22 @@ private static function validateAndDecodeResponse(ResponseInterface $response, b
throw new NumverifyApiFailureException($response);
}

if ($asArray) {
/**
* @var ApiJsonArray $body
*/
$body = json_decode($response->getBody()->getContents(), true);

if (isset($body['success']) && $body['success'] === false) {
throw new NumverifyApiFailureException($response);
}

return $body;
}
/**
* @var ApiJsonArray | ApiCountryJsonArray | stdClass $body
*/
$body = json_decode($response->getBody()->getContents(), $asArray);

/**
* @var stdClass $body
* @var ApiJsonArray | ApiCountryJsonArray $data
*/
$body = json_decode($response->getBody()->getContents());
$data = $asArray ? $body : (array) $body;

if (isset($body->success) && $body->success === false) {
if (isset($data['success']) && $data['success'] === false) {
throw new NumverifyApiFailureException($response);
}

unset($data);

return $body;
}

Expand All @@ -258,10 +257,9 @@ private static function validateAndDecodeResponse(ResponseInterface $response, b
*/
private static function buildCacheHandler(array $options): array
{
/** @var string|null $cachePath */
$cachePath = $options['cachePath'] ?? null;
$cachePath = (string) ($options['cachePath'] ?? null); // @phpstan-ignore-line

if ($cachePath !== null && is_dir($cachePath) && is_writable($cachePath)) {
if (is_dir($cachePath) && is_writable($cachePath)) {
$handlerStack = HandlerStack::create();
$handlerStack->push(middleware: new CacheMiddleware(cacheStrategy: new PrivateCacheStrategy(
cache: new Psr6CacheStorage(cachePool: new FilesystemAdapter(namespace: 'numverify', defaultLifetime: 300, directory: $cachePath))
Expand Down
13 changes: 13 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,21 @@
#[CoversClass(Api::class)]
class ApiTest extends TestCase
{
/**
* Current version of the Numverify package.
*
* @var string
*/
public const LIBRARY_VERSION = '3.0.1';

private const ACCESS_KEY = 'SomeAccessKey';

#[TestDox('Verifies the Api::LIBRARY_VERSION constant returns the correct version string.')]
public function testApiReturnsCurrentLibraryVersion(): void
{
self::assertEquals(self::LIBRARY_VERSION, Api::LIBRARY_VERSION);
}

#[DataProvider('dataProviderForHttp')]
#[TestDox('Construction with default Guzzle client with $useHttps.')]
public function testConstructionWithDefaultClient(bool $useHttps): void
Expand Down

0 comments on commit ede02a9

Please sign in to comment.