Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
5 / 10
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PandaDocSigningSessionData
50.00% covered (danger)
50.00%
5 / 10
66.67% covered (warning)
66.67%
2 / 3
6.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromPandaDocResponse
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 toArray
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Document\Data;
6
7use App\Support\Row;
8
9/**
10 * The result of creating an embedded-signing session for a PandaDoc document.
11 *
12 * `sessionUrl` is the browser-facing URL the frontend opens (PandaDoc's API
13 * returns only a session id; the URL is constructed in
14 * {@see \App\Domain\Document\Service\PandaDocService::createSigningSession}).
15 */
16final readonly class PandaDocSigningSessionData
17{
18    public function __construct(
19        public string $sessionUrl = '',
20        public string $expiresAt = '',
21    ) {}
22
23    /**
24     * Build from a PandaDoc session-create API response. Constructs the
25     * browser-facing URL from the returned session id.
26     *
27     * @param array<mixed> $response
28     */
29    public static function fromPandaDocResponse(array $response): self
30    {
31        $sessionId = Row::nullableString($response, 'id') ?? '';
32
33        return new self(
34            sessionUrl: $sessionId === '' ? '' : 'https://app.pandadoc.com/s/' . $sessionId,
35            expiresAt: Row::nullableString($response, 'expires_at') ?? '',
36        );
37    }
38
39    /**
40     * @return array<string, mixed>
41     */
42    public function toArray(): array
43    {
44        return [
45            'sessionUrl' => $this->sessionUrl,
46            'expiresAt' => $this->expiresAt,
47        ];
48    }
49}