Skip to content

Commit d7be5ec

Browse files
committed
Preparing initial release
1 parent 685240f commit d7be5ec

20 files changed

Lines changed: 363 additions & 61 deletions

.php-cs-fixer.dist.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,78 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
$header = <<<'EOF'
6+
This file is part of the Numverify API Client for PHP.
7+
8+
(c) 2024 Eric Sizemore <admin@secondversion.com>
9+
(c) 2018-2021 Mark Rogoyski
10+
11+
@license The MIT License
12+
13+
For the full copyright and license information, please view the LICENSE.md
14+
file that was distributed with this source code.
15+
EOF;
16+
317
$config = new PhpCsFixer\Config();
418

519
$config
620
->setRiskyAllowed(true)
721
->setRules([
8-
'@PER-CS' => true,
9-
'@PSR12' => true,
10-
'@PHP82Migration' => true,
11-
'array_syntax' => ['syntax' => 'short'],
12-
'php_unit_internal_class' => ['types' => ['normal', 'final']],
13-
'php_unit_namespaced' => true,
14-
'php_unit_expectation' => true,
15-
'php_unit_strict' => ['assertions' => ['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']],
16-
'align_multiline_comment' => true,
17-
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
18-
'binary_operator_spaces' => [
22+
'@PER-CS' => true,
23+
'@PSR12' => true,
24+
'@PHP82Migration' => true,
25+
'array_syntax' => ['syntax' => 'short'],
26+
'php_unit_internal_class' => ['types' => ['normal', 'final']],
27+
'php_unit_namespaced' => true,
28+
'php_unit_expectation' => true,
29+
'php_unit_strict' => ['assertions' => ['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']],
30+
'php_unit_set_up_tear_down_visibility' => true,
31+
'phpdoc_align' => true,
32+
'phpdoc_indent' => true,
33+
'phpdoc_inline_tag_normalizer' => true,
34+
'phpdoc_no_access' => true,
35+
'phpdoc_no_alias_tag' => true,
36+
'phpdoc_no_empty_return' => true,
37+
'phpdoc_no_package' => true,
38+
'phpdoc_param_order' => true,
39+
'phpdoc_return_self_reference' => true,
40+
'phpdoc_scalar' => true,
41+
'phpdoc_separation' => true,
42+
'phpdoc_single_line_var_spacing' => true,
43+
'phpdoc_summary' => true,
44+
'phpdoc_tag_casing' => true,
45+
'phpdoc_tag_type' => true,
46+
'phpdoc_to_comment' => false,
47+
'phpdoc_trim' => true,
48+
'phpdoc_trim_consecutive_blank_line_separation' => true,
49+
'phpdoc_var_without_name' => true,
50+
'phpdoc_no_useless_inheritdoc' => true,
51+
'align_multiline_comment' => true,
52+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
53+
'binary_operator_spaces' => [
1954
'operators' => [
20-
'=>' => 'align',
21-
'=' => 'align',
55+
'*=' => 'align_single_space_minimal',
56+
'+=' => 'align_single_space_minimal',
57+
'-=' => 'align_single_space_minimal',
58+
'/=' => 'align_single_space_minimal',
59+
'=' => 'align_single_space_minimal',
60+
'=>' => 'align_single_space_minimal',
2261
],
2362
],
63+
'heredoc_to_nowdoc' => true,
2464
'ordered_imports' => false,
65+
'declare_equal_normalize' => ['space' => 'none'],
66+
'declare_parentheses' => true,
67+
'declare_strict_types' => true,
2568
'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
69+
'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'separate' => 'top'],
2670
])
2771
->setLineEnding("\n")
2872
->setFinder(
2973
PhpCsFixer\Finder::create()
3074
->in(__DIR__ . '/src')
3175
->in(__DIR__ . '/tests')
32-
->append([__DIR__ . '/rector.php', __DIR__ . '/.php-cs-fixer.dist.php'])
3376
)
3477
;
3578

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Forked from [`markrogoyski/numverify-api-client-php`](https://github.com/markrog
1616
* Bumped minimum PHP version to 8.2
1717
* Autoloading should follow PSR-4
1818
* Updated PHPUnit to 11.0+
19+
* Added `strict_types` declaration and PHPDoc header to all files.
1920
* `Api::__construct` has a new `$options` parameter, which is optional, that can pass options to Guzzle Client.
2021
* `NumverifyApiFailureException` is wrapped around `\GuzzleHttp\Exception\ServerException`
2122
* `Api::validateResponse()` changed to `Api::validateAndDecodeResponse()`.

src/Api.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Numverify API Client for PHP.
7+
*
8+
* (c) 2024 Eric Sizemore <admin@secondversion.com>
9+
* (c) 2018-2021 Mark Rogoyski
10+
*
11+
* @license The MIT License
12+
*
13+
* For the full copyright and license information, please view the LICENSE.md
14+
* file that was distributed with this source code.
15+
*/
16+
317
namespace Numverify;
418

519
use GuzzleHttp\{
@@ -38,6 +52,7 @@
3852
* Main API class.
3953
*
4054
* @see \Numverify\Tests\ApiTest
55+
*
4156
* @phpstan-type ApiJsonArray array{success?: bool, error?: array{code?: int, type?: string, info?: string}, valid?: bool, number?: string, local_format?: string, international_format?: string, country_prefix?: string, country_code?: string, country_name?: string, location?: string, carrier?: string, line_type?: string}
4257
*/
4358
class Api
@@ -47,17 +62,17 @@ class Api
4762
*
4863
* @see https://numverify.com/product
4964
*/
50-
private const HTTP_URL = 'http://apilayer.net/api';
65+
private const HTTP_URL = 'http://apilayer.net/api';
5166

5267
/**
53-
* URL for Numverify's paid plans. ("Basic", "Professional", or "Enterprise")
68+
* URL for Numverify's paid plans. ("Basic", "Professional", or "Enterprise").
5469
*
5570
* @see https://numverify.com/product
5671
*/
5772
private const HTTPS_URL = 'https://apilayer.net/api';
5873

5974
/**
60-
* Guzzle Client
75+
* Guzzle Client.
6176
*/
6277
private ClientInterface $client;
6378

@@ -70,10 +85,10 @@ class Api
7085
*
7186
* Note: If you are on their free plan, $useHttps = true will not work for you.
7287
*
73-
* @param string $accessKey API access key.
74-
* @param bool $useHttps (optional) Flag to determine if API calls should use http or https.
75-
* @param ClientInterface|null $client (optional) Parameter to provide your own Guzzle client.
76-
* @param array<string, mixed> $options (optional) Array of options to pass to the Guzzle client.
88+
* @param string $accessKey API access key.
89+
* @param bool $useHttps (optional) Flag to determine if API calls should use http or https.
90+
* @param ClientInterface|null $client (optional) Parameter to provide your own Guzzle client.
91+
* @param array<string, mixed> $options (optional) Array of options to pass to the Guzzle client.
7792
*/
7893
public function __construct(
7994
#[SensitiveParameter]
@@ -110,7 +125,7 @@ public function __construct(
110125
* @param string $countryCode (Optional) Use to provide a phone number in a local format (non E.164).
111126
*
112127
* @throws NumverifyApiFailureException If the response is non 200 or success field is false.
113-
* @throws GuzzleException If Guzzle encounters an issue.
128+
* @throws GuzzleException If Guzzle encounters an issue.
114129
*/
115130
public function validatePhoneNumber(string $phoneNumber, string $countryCode = ''): PhoneNumberInterface
116131
{
@@ -146,8 +161,8 @@ public function validatePhoneNumber(string $phoneNumber, string $countryCode = '
146161
/**
147162
* Get list of countries.
148163
*
149-
* @throws NumverifyApiFailureException if the response is non 200 or success field is false.
150-
* @throws GuzzleException If Guzzle encounters an issue.
164+
* @throws NumverifyApiFailureException If the response is non 200 or success field is false.
165+
* @throws GuzzleException If Guzzle encounters an issue.
151166
*/
152167
public function getCountries(): Collection
153168
{
@@ -191,7 +206,8 @@ private function getUrl(bool $useHttps): string
191206
* If everything looks good, it returns the decoded jSON data based on $asArray.
192207
*
193208
* @param ResponseInterface $response
194-
* @param bool $asArray If true, returns the decoded jSON as an assoc. array, stdClass otherwise.
209+
* @param bool $asArray If true, returns the decoded jSON as an assoc. array, stdClass otherwise.
210+
*
195211
* @return stdClass | ApiJsonArray
196212
*
197213
* @throws NumverifyApiFailureException if the response is non 200 or success field is false.
@@ -235,7 +251,8 @@ private function validateAndDecodeResponse(ResponseInterface $response, bool $as
235251
* Returns given $options as passed, minus the 'cachePath' as it is not a valid Guzzle option for
236252
* the client.
237253
*
238-
* @param array<string, mixed> $options
254+
* @param array<string, mixed> $options
255+
*
239256
* @return array<string, mixed>
240257
*/
241258
private function buildCacheHandler(array $options): array

src/Country/Collection.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Numverify API Client for PHP.
7+
*
8+
* (c) 2024 Eric Sizemore <admin@secondversion.com>
9+
* (c) 2018-2021 Mark Rogoyski
10+
*
11+
* @license The MIT License
12+
*
13+
* For the full copyright and license information, please view the LICENSE.md
14+
* file that was distributed with this source code.
15+
*/
16+
317
namespace Numverify\Country;
418

519
use Countable;
@@ -15,7 +29,7 @@
1529

1630
/**
1731
* Country Collection
18-
* Role: Collection of callable countries
32+
* Role: Collection of callable countries.
1933
*
2034
* @implements Iterator<Country>
2135
*/
@@ -55,15 +69,15 @@ public function findByCountryName(string $countryName): ?Country
5569
}
5670

5771
/**
58-
* {@inheritdoc}
72+
* @inheritDoc
5973
*/
6074
public function count(): int
6175
{
6276
return count($this->byCountryCode);
6377
}
6478

6579
/**
66-
* {@inheritdoc}
80+
* @inheritDoc
6781
*
6882
* @return object[]
6983
*/
@@ -73,15 +87,15 @@ public function jsonSerialize(): array
7387
}
7488

7589
/**
76-
* {@inheritdoc}
90+
* @inheritDoc
7791
*/
7892
public function rewind(): void
7993
{
8094
reset($this->byCountryCode);
8195
}
8296

8397
/**
84-
* {@inheritdoc}
98+
* @inheritDoc
8599
*/
86100
public function current(): Country
87101
{
@@ -95,23 +109,23 @@ public function current(): Country
95109
}
96110

97111
/**
98-
* {@inheritdoc}
112+
* @inheritDoc
99113
*/
100114
public function key(): int | string | null
101115
{
102116
return key($this->byCountryCode);
103117
}
104118

105119
/**
106-
* {@inheritdoc}
120+
* @inheritDoc
107121
*/
108122
public function next(): void
109123
{
110124
next($this->byCountryCode);
111125
}
112126

113127
/**
114-
* {@inheritdoc}
128+
* @inheritDoc
115129
*/
116130
public function valid(): bool
117131
{

src/Country/Country.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Numverify API Client for PHP.
7+
*
8+
* (c) 2024 Eric Sizemore <admin@secondversion.com>
9+
* (c) 2018-2021 Mark Rogoyski
10+
*
11+
* @license The MIT License
12+
*
13+
* For the full copyright and license information, please view the LICENSE.md
14+
* file that was distributed with this source code.
15+
*/
16+
317
namespace Numverify\Country;
418

519
use JsonSerializable;
@@ -9,41 +23,41 @@
923

1024
/**
1125
* Country
12-
* Role: Value object that represents a callable country
26+
* Role: Value object that represents a callable country.
1327
*/
1428
readonly class Country implements Stringable, JsonSerializable
1529
{
1630
/**
17-
* Country constructor
31+
* Country constructor.
1832
*/
1933
public function __construct(private string $countryCode, private string $countryName, private string $dialingCode) {}
2034

2135
/**
22-
* Get country code
36+
* Get country code.
2337
*/
2438
public function getCountryCode(): string
2539
{
2640
return $this->countryCode;
2741
}
2842

2943
/**
30-
* Get country name
44+
* Get country name.
3145
*/
3246
public function getCountryName(): string
3347
{
3448
return $this->countryName;
3549
}
3650

3751
/**
38-
* Get dialing code
52+
* Get dialing code.
3953
*/
4054
public function getDialingCode(): string
4155
{
4256
return $this->dialingCode;
4357
}
4458

4559
/**
46-
* {@inheritdoc}
60+
* {@inheritDoc}
4761
*
4862
* CountryCode: CountryName (DialingCode)
4963
*/
@@ -53,7 +67,7 @@ public function __toString(): string
5367
}
5468

5569
/**
56-
* {@inheritdoc}
70+
* @inheritDoc
5771
*
5872
* @return string[]
5973
*/

src/Exception/NumverifyApiFailureException.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Numverify API Client for PHP.
7+
*
8+
* (c) 2024 Eric Sizemore <admin@secondversion.com>
9+
* (c) 2018-2021 Mark Rogoyski
10+
*
11+
* @license The MIT License
12+
*
13+
* For the full copyright and license information, please view the LICENSE.md
14+
* file that was distributed with this source code.
15+
*/
16+
317
namespace Numverify\Exception;
418

519
use RuntimeException;

0 commit comments

Comments
 (0)