Passed
Push — 1.x ( 6f2535...3f3ba5 )
by Pavel
02:37 queued 44s
created

EnvelopeDocumentsEndpoint::download()   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 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\DigiSign\Endpoint;
6
7
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait;
8
use DigitalCz\DigiSign\Resource\Envelope;
9
use DigitalCz\DigiSign\Resource\EnvelopeDocument;
10
use DigitalCz\DigiSign\Resource\EnvelopeTag;
11
use DigitalCz\DigiSign\Resource\ListResource;
12
use DigitalCz\DigiSign\Stream\FileResponse;
13
14
/**
15
 * @extends ResourceEndpoint<EnvelopeDocument>
16
 * @method EnvelopeDocument get(string $id)
17
 * @method EnvelopeDocument create(array $body)
18
 * @method EnvelopeDocument update(string $id, array $body)
19
 */
20
final class EnvelopeDocumentsEndpoint extends ResourceEndpoint
21
{
22
    /** @use CRUDEndpointTrait<EnvelopeDocument> */
23
    use CRUDEndpointTrait;
24
25
    /**
26
     * @param Envelope|string $envelope
27
     */
28
    public function __construct(EnvelopesEndpoint $parent, $envelope)
29
    {
30
        parent::__construct($parent, '/{envelope}/documents', EnvelopeDocument::class, ['envelope' => $envelope]);
31
    }
32
33
    /**
34
     * @param mixed[] $body
35
     */
36
    public function positions(array $body): void
37
    {
38
        $this->putRequest('/positions', ['json' => $body]);
39
    }
40
41
    public function merge(): EnvelopeDocument
42
    {
43
        $response = $this->postRequest("/merge");
44
45
        return $this->makeResource($response);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResource($response) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\EnvelopeDocument.
Loading history...
46
    }
47
48
    /**
49
     * @param mixed[] $query
50
     */
51
    public function download(string $id, array $query = []): FileResponse
52
    {
53
        return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]);
54
    }
55
56
    /**
57
     * @param mixed[] $query
58
     * @return ListResource<EnvelopeTag>
59
     */
60
    public function tags(string $id, array $query = []): ListResource
61
    {
62
        return $this->createListResource(
63
            $this->getRequest('/{id}/tags', ['id' => $id, 'query' => $query]),
64
            EnvelopeTag::class
65
        );
66
    }
67
68
    /**
69
     * @param EnvelopeDocument|string $document
70
     * @param mixed[] $body
71
     */
72
    public function replaceFile($document, array $body): EnvelopeDocument
73
    {
74
        return $this->makeResource(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...ent, 'json' => $body))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\EnvelopeDocument.
Loading history...
75
            $this->postRequest('/{document}/replace-file', ['document' => $document, 'json' => $body])
76
        );
77
    }
78
}
79