Passed
Push — master ( e06835...9e4381 )
by Andrey
03:50
created

InternetDocument::getDocumentDeliveryDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 4
dl 0
loc 19
rs 10
1
<?php
2
3
namespace Daaner\NovaPoshta\Models;
4
5
use Daaner\NovaPoshta\NovaPoshta;
6
use Daaner\NovaPoshta\Traits\DateTimes;
7
use Daaner\NovaPoshta\Traits\DocumentList;
8
use Daaner\NovaPoshta\Traits\InternetDocumentProperty;
9
use Daaner\NovaPoshta\Traits\Limit;
10
use Daaner\NovaPoshta\Traits\OptionsSeatProperty;
11
use Daaner\NovaPoshta\Traits\RecipientProperty;
12
use Daaner\NovaPoshta\Traits\SenderProperty;
13
14
class InternetDocument extends NovaPoshta
15
{
16
    /**
17
     * getDocumentList
18
     * getMoneyTransferDocuments.
19
     */
20
    use Limit, DateTimes;
21
22
    /**
23
     * getDocumentList.
24
     */
25
    use DocumentList;
26
27
    /**
28
     * save.
29
     */
30
    use InternetDocumentProperty, SenderProperty, OptionsSeatProperty, RecipientProperty;
31
32
    protected $model = 'InternetDocument';
33
    protected $calledMethod;
34
    protected $methodProperties = [];
35
36
    /**
37
     * Получить список ЭН.
38
     *
39
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9d22b34-8512-11ec-8ced-005056b2dbe1
40
     *
41
     * @return array
42
     */
43
    public function getDocumentList(): array
44
    {
45
        $this->calledMethod = 'getDocumentList';
46
47
        $this->getPage();
48
        $this->addLimit();
49
50
        //DateTime
51
        $this->getDateTime();
52
        $this->getDateTimeFromTo();
53
54
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
55
    }
56
57
    /**
58
     * Создать экспресс-накладную.
59
     *
60
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1
61
     *
62
     * @param  string|null  $description
63
     * @return array
64
     */
65
    public function save(string $description = null): array
66
    {
67
        $this->calledMethod = 'save';
68
69
        $this->getPayerType();
70
        $this->getServiceType();
71
        $this->getPaymentMethod();
72
        $this->getCargoType();
73
74
        $this->getDateTime();
75
        $this->setDescription($description);
76
        $this->getSeatsAmount();
77
        $this->getCost();
78
        $this->getOptionsSeat();
79
80
        //Отправитель и другое
81
        $this->getSender();
82
        $this->getRecipientType();
83
        $this->getBackwardDeliveryData();
84
        $this->getNote();
85
        $this->getAdditionalInformation();
86
87
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
88
    }
89
90
    /**
91
     * Удаление экспресс-накладной.
92
     *
93
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9f43ff1-8512-11ec-8ced-005056b2dbe1
94
     *
95
     * @param  string|array  $DocumentRefs
96
     * @return array
97
     */
98
    public function delete($DocumentRefs): array
99
    {
100
        $this->calledMethod = 'delete';
101
102
        if (is_array($DocumentRefs) === false) {
103
            $DocumentRefs = explode(', ', /** @scrutinizer ignore-type */ $DocumentRefs);
104
        }
105
106
        $this->methodProperties['DocumentRefs'] = array_values(/** @scrutinizer ignore-type */ $DocumentRefs);
107
108
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
109
    }
110
111
    /**
112
     * Получить данные о платежах за определенный период.
113
     *
114
     * @param  null  $dateFrom
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dateFrom is correct as it would always require null to be passed?
Loading history...
115
     * @param  null  $dateTo
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dateTo is correct as it would always require null to be passed?
Loading history...
116
     * @return array
117
     */
118
    public function getMoneyTransferDocuments($dateFrom = null, $dateTo = null)
119
    {
120
        $this->calledMethod = 'getMoneyTransferDocuments';
121
122
        $this->addLimit();
123
        $this->getPage();
124
        $this->getDateFromTo($dateFrom, $dateTo);
125
126
        // dd($this->methodProperties);
127
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
128
    }
129
130
    /**
131
     * Редактирование экспресс-накладной.
132
     *
133
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a98a4354-8512-11ec-8ced-005056b2dbe1
134
     * @author https://github.com/seriklav/NovaPoshta
135
     *
136
     * TODO need tested
137
     * @deprecated NOT FULLY TESTED
138
     *
139
     * @param null $description
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $description is correct as it would always require null to be passed?
Loading history...
140
     * @return array
141
     */
142
    public function edit($description = null): array
143
    {
144
        $this->calledMethod = 'update';
145
146
        $this->getRef();
147
148
        $this->getPayerType();
149
        $this->getServiceType();
150
        $this->getPaymentMethod();
151
        $this->getCargoType();
152
153
        $this->getDateTime();
154
        $this->setDescription($description);
155
        $this->getSeatsAmount();
156
        $this->getCost();
157
        $this->getWeight();
158
//        $this->getOptionsSeat();
159
160
        //Отправитель и другое
161
        $this->getSender();
162
        $this->getRecipientType();
163
        $this->getBackwardDeliveryData();
164
        $this->getNote();
165
        $this->getAdditionalInformation();
166
167
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
168
    }
169
170
171
    /**
172
     * Прогноз даты доставки груза
173
     *
174
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a941c714-8512-11ec-8ced-005056b2dbe1
175
     * @author https://github.com/seriklav/NovaPoshta
176
     *
177
     * @param string $CitySender
178
     * @param string $CityRecipient
179
     * @param string|null $DateTime
180
     * @param string|null $ServiceType
181
     *
182
     * @return array
183
     */
184
    public function getDocumentDeliveryDate(
185
        string $CitySender,
186
        string $CityRecipient,
187
        ?string $DateTime = null,
188
        ?string $ServiceType = null
189
    ): array
190
    {
191
192
        $this->calledMethod = 'getDocumentDeliveryDate';
193
194
        $methodProperties['ServiceType'] = $ServiceType ?? config('novaposhta.service_type');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$methodProperties was never initialized. Although not strictly required by PHP, it is generally a good practice to add $methodProperties = array(); before regardless.
Loading history...
195
        $methodProperties['CitySender'] = $CitySender;
196
        $methodProperties['CityRecipient'] = $CityRecipient;
197
198
        if ($DateTime) {
199
            $methodProperties['DateTime'] = $this->checkDate($DateTime, 'd.m.Y');
200
        }
201
202
        return $this->getResponse($this->model, $this->calledMethod, $methodProperties, false);
203
    }
204
205
}
206