Passed
Pull Request — 1.x (#100)
by
unknown
02:18
created

EnvelopeDocumentsEndpoint::assignments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
    public function assignments(): EnvelopeDocumentAssignmentsEndpoint
34
    {
35
        return new EnvelopeDocumentAssignmentsEndpoint($this);
36
    }
37
38
    /**
39
     * @param mixed[] $body
40
     */
41
    public function positions(array $body): void
42
    {
43
        $this->putRequest('/positions', ['json' => $body]);
44
    }
45
46
    public function merge(): EnvelopeDocument
47
    {
48
        $response = $this->postRequest("/merge");
49
50
        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...
51
    }
52
53
    /**
54
     * @param mixed[] $query
55
     */
56
    public function download(string $id, array $query = []): FileResponse
57
    {
58
        return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]);
59
    }
60
61
    /**
62
     * @param mixed[] $query
63
     * @return ListResource<EnvelopeTag>
64
     */
65
    public function tags(string $id, array $query = []): ListResource
66
    {
67
        return $this->createListResource(
68
            $this->getRequest('/{id}/tags', ['id' => $id, 'query' => $query]),
69
            EnvelopeTag::class
70
        );
71
    }
72
73
    /**
74
     * @param EnvelopeDocument|string $document
75
     * @param mixed[] $body
76
     */
77
    public function replaceFile($document, array $body): EnvelopeDocument
78
    {
79
        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...
80
            $this->postRequest('/{document}/replace-file', ['document' => $document, 'json' => $body])
81
        );
82
    }
83
}
84