Calculator::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Actions;
6
7
use CdekSDK2\BaseTypes\Tariff;
8
use CdekSDK2\BaseTypes\Tarifflist;
9
use CdekSDK2\Exceptions\RequestException;
10
use CdekSDK2\Http\ApiResponse;
11
12
/**
13
 * Class Calculator
14
 * @package CdekSDK2\Actions
15
 */
16
class Calculator extends Action
17
{
18
    /**
19
     * URL для запросов к API
20
     * @var string
21
     */
22
    public const URL = '/calculator';
23
24
    /**
25
     * @var Tarifflist|Tariff
26
     */
27
    private $lastAction;
28
29
    /**
30
     * Создание запроса на расчёт стоимости
31
     * @param Tarifflist|Tariff $tarifflist
32
     * @return ApiResponse
33
     * @throws RequestException
34
     */
35
    public function add($tarifflist): ApiResponse
36
    {
37
        $this->lastAction = $tarifflist;
38
        $params = $this->serializer->toArray($tarifflist);
39
        return $this->preparedAdd($params);
40
    }
41
42
    protected function slug(string $uuid = null): string
43
    {
44
        if ($this->lastAction instanceof Tariff) {
45
            return static::URL . '/tariff';
46
        }
47
48
        return static::URL . '/tarifflist';
49
    }
50
}
51