Skip to content

Commit 231e5a7

Browse files
malukenhoScullWM
authored andcommitted
Promote properties
Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
1 parent 0ff5ce2 commit 231e5a7

File tree

4 files changed

+27
-64
lines changed

4 files changed

+27
-64
lines changed

src/ApiThrottling.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
namespace Scullwm\DbIpClient;
66

7-
class ApiThrottling
7+
final class ApiThrottling
88
{
9-
private string $apiKey;
10-
private int $queriesPerDay;
11-
private int $queriesLeft;
12-
private string $status;
13-
14-
public function __construct(string $apiKey, int $queriesPerDay, int $queriesLeft, string $status)
15-
{
16-
$this->apiKey = $apiKey;
17-
$this->queriesPerDay = $queriesPerDay;
18-
$this->queriesLeft = $queriesLeft;
19-
$this->status = $status;
9+
private const UNKNOWN = 'unknown';
10+
11+
public function __construct(
12+
private string $apiKey,
13+
private int $queriesPerDay,
14+
private int $queriesLeft,
15+
private string $status
16+
) {
2017
}
2118

2219
/**
@@ -29,7 +26,7 @@ public static function new(array $data, string $defaultApiToken = ''): self
2926
$data['apiKey'] ?? $defaultApiToken,
3027
$data['queriesPerDay'] ?? 0,
3128
$data['queriesLeft'] ?? 0,
32-
$data['status'] ?? 'unknown'
29+
$data['status'] ?? self::UNKNOWN
3330
);
3431
}
3532

src/Client.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,19 @@
2121

2222
use const JSON_THROW_ON_ERROR;
2323

24-
class Client
24+
final class Client
2525
{
2626
private ClientInterface $client;
27-
2827
private RequestFactoryInterface $messageFactory;
2928

30-
private string $token;
31-
3229
private const API_ENDPOINT_V2_IP_DETAILS = 'https://api.db-ip.com/v2/%s/%s';
3330
private const API_ENDPOINT_V2_API_STATUS = 'https://api.db-ip.com/v2/%s';
3431

3532
public function __construct(
36-
string $token,
33+
private string $token,
3734
?ClientInterface $client = null,
3835
?RequestFactoryInterface $factory = null
3936
) {
40-
$this->token = $token;
4137
$this->client = $client ?: Psr18ClientDiscovery::find();
4238
$this->messageFactory = $factory ?: Psr17FactoryDiscovery::findRequestFactory();
4339
}
@@ -60,8 +56,6 @@ public function getApiStatus(): ApiThrottling
6056
* @psalm-return array<string, string>
6157
*
6258
* @throws ClientExceptionInterface
63-
*
64-
* @todo can we get the right array shape here?
6559
*/
6660
protected function getParsedResponse(RequestInterface $request): array
6761
{

src/IpDetails.php

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,20 @@
44

55
namespace Scullwm\DbIpClient;
66

7-
class IpDetails
7+
final class IpDetails
88
{
9-
private string $ipAddress;
10-
11-
private string $continentCode;
12-
13-
private string $continentName;
14-
15-
private string $countryCode;
16-
17-
private string $countryName;
18-
19-
private bool $isEuMember;
20-
21-
private string $stateProv;
22-
23-
private string $city;
24-
25-
private string $threatLevel;
26-
27-
private string $isp;
28-
299
private function __construct(
30-
string $ipAddress,
31-
string $continentCode,
32-
string $continentName,
33-
string $countryCode,
34-
string $countryName,
35-
bool $isEuMember,
36-
string $stateProv,
37-
string $city,
38-
string $threatLevel,
39-
string $isp
10+
private string $ipAddress,
11+
private string $continentCode,
12+
private string $continentName,
13+
private string $countryCode,
14+
private string $countryName,
15+
private bool $isEuMember,
16+
private string $stateProv,
17+
private string $city,
18+
private string $threatLevel,
19+
private string $isp
4020
) {
41-
$this->ipAddress = $ipAddress;
42-
$this->continentCode = $continentCode;
43-
$this->continentName = $continentName;
44-
$this->countryCode = $countryCode;
45-
$this->countryName = $countryName;
46-
$this->stateProv = $stateProv;
47-
$this->isEuMember = $isEuMember;
48-
$this->city = $city;
49-
$this->threatLevel = $threatLevel;
50-
$this->isp = $isp;
5121
}
5222

5323
/**

tests/DbIpClientTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ public function testApiStatus(): void
6767

6868
$response = $this->getResponse(file_get_contents(__DIR__ . '/Fixtures/status.json'));
6969
$client->setDefaultResponse($response);
70-
$dbipClient = new TestedClient('d74be40a1acd2b5b356f67a0f6a5e1be', $client);
70+
$hash = 'd74be40a1acd2b5b356f67a0f6a5e1be';
71+
72+
$dbipClient = new TestedClient($hash, $client);
7173

7274
$apiStatus = $dbipClient->getApiStatus();
7375

74-
self::assertEquals('d74be40a1acd2b5b356f67a0f6a5e1be', $apiStatus->getApiKey());
76+
self::assertEquals($hash, $apiStatus->getApiKey());
7577
self::assertEquals(10000, $apiStatus->getQueriesPerDay());
7678
self::assertEquals(9986, $apiStatus->getQueriesLeft());
7779
self::assertEquals('active', $apiStatus->getStatus());

0 commit comments

Comments
 (0)