Passed
Push — master ( 049c4c...7327a7 )
by Artem
01:51
created

Tax   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A payments() 0 12 2
A history() 0 7 1
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