Skip to content

Commit d5bdab2

Browse files
authored
Merge pull request #6 from codebar-ag/fix-null-carrier
Allow null Carrier
2 parents c44f9aa + 13efe8f commit d5bdab2

File tree

6 files changed

+45
-33
lines changed

6 files changed

+45
-33
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
},
2929
"require-dev": {
3030
"friendsofphp/php-cs-fixer": "^3.46",
31+
"laravel/pint": "^1.14",
3132
"nunomaduro/collision": "^7.10",
3233
"orchestra/testbench": "^8.20",
3334
"pestphp/pest": "^2.31",
3435
"phpunit/phpunit": "^10.5",
35-
"spatie/laravel-ray": "^1.33",
36+
"spatie/laravel-ray": "^1.35",
3637
"vimeo/psalm": "^5.19"
3738
},
3839
"autoload": {

src/DTO/Carrier.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
namespace CodebarAg\TwilioVerify\DTO;
44

5+
use Illuminate\Support\Arr;
6+
57
class Carrier
68
{
79
public static function fromJson(array $data): self
810
{
911
return new static(
10-
error_code: $data['error_code'],
11-
name: $data['name'],
12-
mobile_country_code: $data['mobile_country_code'],
13-
mobile_network_code: $data['mobile_network_code'],
14-
type: $data['type'],
12+
error_code: Arr::get($data, 'error_code'),
13+
name: Arr::get($data, 'name'),
14+
mobile_country_code: Arr::get($data, 'mobile_country_code'),
15+
mobile_network_code: Arr::get($data, 'mobile_network_code'),
16+
type: Arr::get($data, 'type'),
1517
);
1618
}
1719

src/DTO/Lookup.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
namespace CodebarAg\TwilioVerify\DTO;
44

5+
use Illuminate\Support\Arr;
6+
57
class Lookup
68
{
7-
public static function fromJson(array $lookup): self
9+
public static function fromJson(array $lookup): ?self
810
{
11+
if (Arr::get($lookup, 'carrier') === null) {
12+
return null;
13+
}
14+
915
return new static(
10-
carrier: Carrier::fromJson($lookup['carrier']),
16+
carrier: Carrier::fromJson(Arr::get($lookup, 'carrier')),
1117
);
1218
}
1319

src/DTO/SendCodeAttempt.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodebarAg\TwilioVerify\DTO;
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\Str;
89

@@ -12,9 +13,9 @@ public static function fromJson(array $attempts): Collection
1213
{
1314
return collect($attempts)->map(function (array $attempt) {
1415
return new static(
15-
time: Carbon::parse($attempt['time']),
16-
channel: $attempt['channel'],
17-
attempt_sid: $attempt['attempt_sid'],
16+
time: Carbon::parse(Arr::get($attempt, 'time')),
17+
channel: Arr::get($attempt, 'channel'),
18+
attempt_sid: Arr::get($attempt, 'attempt_sid'),
1819
);
1920
});
2021
}

src/DTO/VerificationCheck.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
namespace CodebarAg\TwilioVerify\DTO;
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Str;
78

89
class VerificationCheck
910
{
1011
public static function fromJson(array $data): self
1112
{
1213
return new static(
13-
sid: $data['sid'],
14-
service_sid: $data['service_sid'],
15-
account_sid: $data['account_sid'],
16-
to: $data['to'],
17-
channel: $data['channel'],
18-
status: $data['status'],
19-
valid: $data['valid'],
20-
created_at: Carbon::parse($data['date_created']),
21-
updated_at: Carbon::parse($data['date_updated']),
14+
sid: Arr::get($data, 'sid'),
15+
service_sid: Arr::get($data, 'service_sid'),
16+
account_sid: Arr::get($data, 'account_sid'),
17+
to: Arr::get($data, 'to'),
18+
channel: Arr::get($data, 'channel'),
19+
status: Arr::get($data, 'status'),
20+
valid: Arr::get($data, 'valid'),
21+
created_at: Carbon::parse(Arr::get($data, 'date_created')),
22+
updated_at: Carbon::parse(Arr::get($data, 'date_updated')),
2223
);
2324
}
2425

src/DTO/VerificationStart.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodebarAg\TwilioVerify\DTO;
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\Str;
89

@@ -14,18 +15,18 @@ class VerificationStart
1415
public static function fromJson(array $data): self
1516
{
1617
return new static(
17-
sid: $data['sid'],
18-
service_sid: $data['service_sid'],
19-
account_sid: $data['account_sid'],
20-
to: $data['to'],
21-
channel: $data['channel'],
22-
status: $data['status'],
23-
valid: $data['valid'],
24-
created_at: Carbon::parse($data['date_created']),
25-
updated_at: Carbon::parse($data['date_updated']),
26-
lookup: Lookup::fromJson($data['lookup']),
27-
send_code_attempts: SendCodeAttempt::fromJson($data['send_code_attempts']),
28-
url: $data['url'],
18+
sid: Arr::get($data, 'sid'),
19+
service_sid: Arr::get($data, 'service_sid'),
20+
account_sid: Arr::get($data, 'account_sid'),
21+
to: Arr::get($data, 'to'),
22+
channel: Arr::get($data, 'channel'),
23+
status: Arr::get($data, 'status'),
24+
valid: Arr::get($data, 'valid'),
25+
created_at: Carbon::parse(Arr::get($data, 'date_created')),
26+
updated_at: Carbon::parse(Arr::get($data, 'date_updated')),
27+
lookup: Lookup::fromJson(Arr::get($data, 'lookup')),
28+
send_code_attempts: SendCodeAttempt::fromJson(Arr::get($data, 'send_code_attempts')),
29+
url: Arr::get($data, 'url'),
2930
);
3031
}
3132

@@ -39,7 +40,7 @@ public function __construct(
3940
public bool $valid,
4041
public Carbon $created_at,
4142
public Carbon $updated_at,
42-
public Lookup $lookup,
43+
public ?Lookup $lookup,
4344
public Collection $send_code_attempts,
4445
public string $url,
4546
) {

0 commit comments

Comments
 (0)