Passed
Pull Request — master (#32)
by Artem
01:42
created

Tax::history()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoman4eg\Nalog\Api;
5
6
use Psr\Http\Client\ClientExceptionInterface;
7
use Shoman4eg\Nalog\ErrorHandler;
8
use Shoman4eg\Nalog\Exception\DomainException;
9
use Shoman4eg\Nalog\Model\Tax\HistoryRecords;
10
use Shoman4eg\Nalog\Model\Tax\PaymentRecords;
11
use Shoman4eg\Nalog\Model\Tax\Tax as TaxModel;
12
13
/**
14
 * @author Artem Dubinin <[email protected]>
15
 */
16
final class Tax extends BaseHttpApi
17
{
18
    /**
19
     * @throws ClientExceptionInterface
20
     */
21
    public function get(): TaxModel
22
    {
23
        $response = $this->httpGet('/taxes');
24
25
        return $this->hydrator->hydrate($response, TaxModel::class);
26
    }
27
28
    /**
29
     * @throws \JsonException
30
     * @throws ClientExceptionInterface
31
     */
32
    public function history(?string $oktmo = null): HistoryRecords
33
    {
34
        $response = $this->httpPost('/taxes/history', [
35
            'oktmo' => $oktmo,
36
        ]);
37
38
        return $this->hydrator->hydrate($response, HistoryRecords::class);
39
    }
40
41
    /**
42
     * @throws \JsonException
43
     * @throws ClientExceptionInterface
44
     * @throws DomainException
45
     */
46
    public function payments(?string $oktmo = null, bool $onlyPaid = false): PaymentRecords
47
    {
48
        $response = $this->httpPost('/taxes/payments', [
49
            'oktmo' => $oktmo,
50
            'onlyPaid' => $onlyPaid,
51
        ]);
52
53
        if ($response->getStatusCode() >= 400) {
54
            (new ErrorHandler())->handleResponse($response);
55
        }
56
57
        return $this->hydrator->hydrate($response, PaymentRecords::class);
58
    }
59
}
60