Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PandaDocTemplateDetailsData | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fromPandaDocResponse | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Document\Data; |
| 6 | |
| 7 | use App\Support\Row; |
| 8 | |
| 9 | /** |
| 10 | * Inspection result for a PandaDoc template: the field placeholders and |
| 11 | * token names defined in the template editor, plus the recipient roles. |
| 12 | * |
| 13 | * Used to discover what tokens/fields a template expects before wiring |
| 14 | * up automated fill-in. |
| 15 | */ |
| 16 | final readonly class PandaDocTemplateDetailsData |
| 17 | { |
| 18 | /** |
| 19 | * @param list<PandaDocTemplateFieldData> $fields |
| 20 | * @param list<PandaDocTemplateTokenData> $tokens |
| 21 | * @param list<string> $roles |
| 22 | * @param string $id |
| 23 | * @param string $name |
| 24 | */ |
| 25 | public function __construct( |
| 26 | public string $id, |
| 27 | public string $name, |
| 28 | public array $fields = [], |
| 29 | public array $tokens = [], |
| 30 | public array $roles = [], |
| 31 | ) {} |
| 32 | |
| 33 | /** |
| 34 | * @param array<mixed> $template |
| 35 | */ |
| 36 | public static function fromPandaDocResponse(array $template): self |
| 37 | { |
| 38 | $fields = []; |
| 39 | $rawFields = Row::nullableArray($template, 'fields') ?? []; |
| 40 | foreach ($rawFields as $field) { |
| 41 | if (is_array($field)) { |
| 42 | $fields[] = PandaDocTemplateFieldData::fromPandaDocResponse($field); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | $tokens = []; |
| 47 | $rawTokens = Row::nullableArray($template, 'tokens') ?? []; |
| 48 | foreach ($rawTokens as $token) { |
| 49 | if (is_array($token)) { |
| 50 | $tokens[] = PandaDocTemplateTokenData::fromPandaDocResponse($token); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | $roles = []; |
| 55 | $rawRoles = Row::nullableArray($template, 'roles') ?? []; |
| 56 | foreach ($rawRoles as $role) { |
| 57 | if (is_array($role)) { |
| 58 | $name = Row::nullableString($role, 'name'); |
| 59 | if ($name !== null && $name !== '') { |
| 60 | $roles[] = $name; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return new self( |
| 66 | id: Row::nullableString($template, 'id') ?? '', |
| 67 | name: Row::nullableString($template, 'name') ?? '', |
| 68 | fields: $fields, |
| 69 | tokens: $tokens, |
| 70 | roles: $roles, |
| 71 | ); |
| 72 | } |
| 73 | } |