1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fousky\Component\iDoklad\Functions\CashVoucher; |
4
|
|
|
|
5
|
|
|
use Fousky\Component\iDoklad\Functions\iDokladAbstractFunction; |
6
|
|
|
use Fousky\Component\iDoklad\LOV\InvoiceTypeEnum; |
7
|
|
|
use Fousky\Component\iDoklad\Model\CashVoucher\CashVoucherApiModelInsert; |
8
|
|
|
use Fousky\Component\iDoklad\Model\Void\VoidModel; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @see https://app.idoklad.cz/developer/Help/v2/cs/Api?apiId=POST-api-v2-CashVouchers-Pair-invoiceType-invoiceId |
12
|
|
|
* |
13
|
|
|
* @author Lukáš Brzák <[email protected]> |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class PairCashVoucher extends iDokladAbstractFunction |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** @var CashVoucherApiModelInsert $data */ |
18
|
|
|
protected $data; |
19
|
|
|
|
20
|
|
|
/** @var InvoiceTypeEnum $invoiceType */ |
21
|
|
|
protected $invoiceType; |
22
|
|
|
|
23
|
|
|
/** @var string $invoiceId */ |
24
|
|
|
protected $invoiceId; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param CashVoucherApiModelInsert $data Cash voucher identification (or create new) |
28
|
|
|
* @param int $invoiceType Pair with invoice type (object InvoiceTypeEnum constant) |
29
|
|
|
* @param string $invoiceId Pair with invoice ID of the $invoiceType |
30
|
|
|
*/ |
31
|
|
|
public function __construct(CashVoucherApiModelInsert $data, int $invoiceType, string $invoiceId) |
32
|
|
|
{ |
33
|
|
|
$this->data = $data; |
34
|
|
|
$this->invoiceType = new InvoiceTypeEnum($invoiceType); |
35
|
|
|
$this->invoiceId = $invoiceId; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get iDokladModelInterface class. |
40
|
|
|
* |
41
|
|
|
* @see iDokladModelInterface |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getModelClass(): string |
46
|
|
|
{ |
47
|
|
|
return VoidModel::class; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* GET|POST|PUT|DELETE e.g. |
52
|
|
|
* |
53
|
|
|
* @see iDoklad::request() |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getHttpMethod(): string |
58
|
|
|
{ |
59
|
|
|
return 'POST'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return base URI, e.g. /invoices; /invoice/1/edit and so on. |
64
|
|
|
* |
65
|
|
|
* @see iDoklad::call() |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getUri(): string |
70
|
|
|
{ |
71
|
|
|
return sprintf( |
72
|
|
|
'CashVouchers/Pair/%s/%s', |
73
|
|
|
(string) $this->invoiceType, |
74
|
|
|
$this->invoiceId |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Vrátí seznam parametrů, které se předají GuzzleHttp\Client. |
80
|
|
|
* |
81
|
|
|
* @see \GuzzleHttp\Client::request() |
82
|
|
|
* @see iDoklad::call() |
83
|
|
|
* |
84
|
|
|
* @throws \ReflectionException |
85
|
|
|
* @throws \InvalidArgumentException |
86
|
|
|
* |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
public function getGuzzleOptions(): array |
90
|
|
|
{ |
91
|
|
|
return [ |
92
|
|
|
'json' => $this->data->toArray(), |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.