Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
53.33% |
8 / 15 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PandaDocRecipientData | |
53.33% |
8 / 15 |
|
66.67% |
2 / 3 |
3.91 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromPandaDocResponse | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Document\Data; |
| 6 | |
| 7 | use App\Support\Row; |
| 8 | |
| 9 | /** |
| 10 | * A single recipient on a PandaDoc document. |
| 11 | * |
| 12 | * Constructed exclusively from PandaDoc API responses by |
| 13 | * {@see \App\Domain\Document\Service\PandaDocService}; consumers never see |
| 14 | * the raw wire format. |
| 15 | */ |
| 16 | final readonly class PandaDocRecipientData |
| 17 | { |
| 18 | public function __construct( |
| 19 | public string $email = '', |
| 20 | public string $firstName = '', |
| 21 | public string $lastName = '', |
| 22 | public string $role = '', |
| 23 | public ?int $signingOrder = null, |
| 24 | ) {} |
| 25 | |
| 26 | /** |
| 27 | * Build from a PandaDoc API recipient object. |
| 28 | * |
| 29 | * @param array<mixed> $recipient |
| 30 | */ |
| 31 | public static function fromPandaDocResponse(array $recipient): self |
| 32 | { |
| 33 | return new self( |
| 34 | email: Row::nullableString($recipient, 'email') ?? '', |
| 35 | firstName: Row::nullableString($recipient, 'first_name') ?? '', |
| 36 | lastName: Row::nullableString($recipient, 'last_name') ?? '', |
| 37 | role: Row::nullableString($recipient, 'role') ?? '', |
| 38 | signingOrder: Row::nullableInt($recipient, 'signing_order'), |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @return array<string, mixed> |
| 44 | */ |
| 45 | public function toArray(): array |
| 46 | { |
| 47 | return [ |
| 48 | 'email' => $this->email, |
| 49 | 'firstName' => $this->firstName, |
| 50 | 'lastName' => $this->lastName, |
| 51 | 'role' => $this->role, |
| 52 | 'signingOrder' => $this->signingOrder, |
| 53 | ]; |
| 54 | } |
| 55 | } |