Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DocumentTemplateData
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fromRow
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Document\Data;
6
7use App\Support\Row;
8
9/**
10 * A registered PandaDoc template the platform sends during registration.
11 *
12 * The {@see $templateId} is the PandaDoc UUID; {@see $active} controls whether
13 * the template is included in the bundle so a template can be retired without
14 * losing its ID.
15 */
16final readonly class DocumentTemplateData
17{
18    public function __construct(
19        public string $templateId,
20        public string $name,
21        public ?string $description,
22        public bool $active,
23        public int $displayOrder,
24        public string $recipientRole,
25        public string $createdAt,
26        public string $updatedAt,
27    ) {}
28
29    /**
30     * @param array<mixed> $row Repository row with camelCase aliases
31     */
32    public static function fromRow(array $row): self
33    {
34        return new self(
35            templateId: Row::string($row, 'templateId'),
36            name: Row::string($row, 'name'),
37            description: Row::nullableString($row, 'description'),
38            active: (bool)$row['active'],
39            displayOrder: Row::int($row, 'displayOrder'),
40            recipientRole: Row::string($row, 'recipientRole'),
41            createdAt: Row::string($row, 'createdAt'),
42            updatedAt: Row::string($row, 'updatedAt'),
43        );
44    }
45
46    /**
47     * @return array<string, mixed>
48     */
49    public function toArray(): array
50    {
51        return [
52            'templateId' => $this->templateId,
53            'name' => $this->name,
54            'description' => $this->description,
55            'active' => $this->active,
56            'displayOrder' => $this->displayOrder,
57            'recipientRole' => $this->recipientRole,
58            'createdAt' => $this->createdAt,
59            'updatedAt' => $this->updatedAt,
60        ];
61    }
62}