Passed
Push — 1.x ( d2e935...cf97bc )
by Pavel
01:52
created

EnvelopesEndpoint::cancel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\DigiSign\Endpoint;
6
7
use DigitalCz\DigiSign\DigiSign;
8
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait;
9
use DigitalCz\DigiSign\Resource\BaseResource;
10
use DigitalCz\DigiSign\Resource\Envelope;
11
use DigitalCz\DigiSign\Resource\EnvelopeTemplate;
12
use DigitalCz\DigiSign\Stream\FileResponse;
13
14
/**
15
 * @extends ResourceEndpoint<Envelope>
16
 * @method Envelope get(string $id)
17
 * @method Envelope create(array $body)
18
 * @method Envelope update(string $id, array $body)
19
 */
20
final class EnvelopesEndpoint extends ResourceEndpoint
21
{
22
    /** @use CRUDEndpointTrait<Envelope> */
23
    use CRUDEndpointTrait;
24
25
    public function __construct(DigiSign $parent)
26
    {
27
        parent::__construct($parent, '/api/envelopes', Envelope::class);
28
    }
29
30
    /**
31
     * @param Envelope|string $envelope
32
     */
33
    public function documents($envelope): EnvelopeDocumentsEndpoint
34
    {
35
        return new EnvelopeDocumentsEndpoint($this, $envelope);
36
    }
37
38
    /**
39
     * @param Envelope|string $envelope
40
     */
41
    public function recipients($envelope): EnvelopeRecipientsEndpoint
42
    {
43
        return new EnvelopeRecipientsEndpoint($this, $envelope);
44
    }
45
46
    /**
47
     * @param Envelope|string $envelope
48
     */
49
    public function tags($envelope): EnvelopeTagsEndpoint
50
    {
51
        return new EnvelopeTagsEndpoint($this, $envelope);
52
    }
53
54
    /**
55
     * @param Envelope|string $envelope
56
     */
57
    public function notifications($envelope): EnvelopeNotificationsEndpoint
58
    {
59
        return new EnvelopeNotificationsEndpoint($this, $envelope);
60
    }
61
62
    public function cancel(string $id): BaseResource
63
    {
64
        return $this->createResource($this->postRequest('/{id}/cancel', ['id' => $id]));
65
    }
66
67
    public function count(): BaseResource
68
    {
69
        return $this->createResource($this->getRequest('/count'));
70
    }
71
72
    /**
73
     * @param mixed[] $query
74
     */
75
    public function download(string $id, array $query = []): FileResponse
76
    {
77
        return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]);
78
    }
79
80
    public function embedEdit(string $id): BaseResource
81
    {
82
        return $this->createResource($this->postRequest('/{id}/embed/edit', ['id' => $id]));
83
    }
84
85
    /**
86
     * @param mixed[] $body
87
     */
88
    public function extend(string $id, array $body): Envelope
89
    {
90
        return $this->makeResource($this->putRequest('/{id}/extend', ['id' => $id, 'json' => $body]));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...$id, 'json' => $body))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\Envelope.
Loading history...
91
    }
92
93
    public function send(string $id): BaseResource
94
    {
95
        return $this->createResource($this->postRequest('/{id}/send', ['id' => $id]));
96
    }
97
98
    public function resend(string $id): BaseResource
99
    {
100
        return $this->createResource($this->postRequest('/{id}/resend', ['id' => $id]));
101
    }
102
103
    /**
104
     * @param Envelope|string $id
105
     */
106
    public function template($id): EnvelopeTemplate
107
    {
108
        return $this->createResource($this->getRequest('/{id}/template', ['id' => $id]), EnvelopeTemplate::class);
109
    }
110
}
111