Skip to content

Commit 9922c85

Browse files
cl77claude
andcommitted
refactor: improve null safety in lookup resources
- Make country, networkCode, countryCode properties nullable in Carrier - Make countryCode property nullable in LookupHlr - Better handle API responses with missing data 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1800ec9 commit 9922c85

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Resource/Lookup/Carrier.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
namespace Seven\Api\Resource\Lookup;
44

55
class Carrier {
6-
protected string $country;
6+
protected ?string $country;
77
protected ?string $name;
8-
protected string $networkCode;
8+
protected ?string $networkCode;
99
protected ?string $networkType;
1010

1111
public function __construct(object $data) {
12-
$this->country = $data->country;
12+
$this->country = $data->country ?: null;
1313
$this->name = $data->name;
14-
$this->networkCode = $data->network_code;
14+
$this->networkCode = $data->network_code ?: null;
1515
$this->networkType = $data->network_type;
1616
}
1717

18-
public function getCountry(): string {
18+
public function getCountry(): ?string {
1919
return $this->country;
2020
}
2121

2222
public function getName(): ?string {
2323
return $this->name;
2424
}
2525

26-
public function getNetworkCode(): string {
26+
public function getNetworkCode(): ?string {
2727
return $this->networkCode;
2828
}
2929

src/Resource/Lookup/LookupHlr.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Seven\Api\Resource\Lookup;
44

55
class LookupHlr {
6-
protected string $countryCode;
6+
protected ?string $countryCode;
77
protected ?string $countryName;
88
protected string|false $countryPrefix;
99
protected Carrier $currentCarrier;
@@ -23,7 +23,7 @@ class LookupHlr {
2323
protected string $validNumber;
2424

2525
public function __construct(object $data) {
26-
$this->countryCode = $data->country_code;
26+
$this->countryCode = $data->country_code ?: null;
2727
$this->countryName = $data->country_name;
2828
$this->countryPrefix = $data->country_prefix;
2929
$this->currentCarrier = new Carrier($data->current_carrier);
@@ -43,7 +43,7 @@ public function __construct(object $data) {
4343
$this->validNumber = $data->valid_number;
4444
}
4545

46-
public function getCountryCode(): string {
46+
public function getCountryCode(): ?string {
4747
return $this->countryCode;
4848
}
4949

0 commit comments

Comments
 (0)