Action   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 63
ccs 0
cts 11
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A slug() 0 6 2
A preparedAdd() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Actions;
6
7
use CdekSDK2\Exceptions\RequestException;
8
use CdekSDK2\Http\Api;
9
use CdekSDK2\Http\ApiResponse;
10
use JMS\Serializer\Serializer;
11
12
/**
13
 * Class Action
14
 * @package CdekSDK2\Actions
15
 */
16
class Action
17
{
18
    /**
19
     * URL для запросов к API
20
     * @var string
21
     */
22
    public const URL = '';
23
24
    /**
25
     * Объект для взаимодействия с API СДЭК
26
     * @var Api
27
     */
28
    protected $http_client;
29
30
    /**
31
     * @var Serializer
32
     */
33
    protected $serializer;
34
35
    /**
36
     * Action constructor.
37
     * @param Api $request
38
     * @param Serializer $serializer
39
     */
40
    public function __construct(Api $request, Serializer $serializer)
41
    {
42
        $this->http_client = $request;
43
        $this->serializer = $serializer;
44
    }
45
46
    /**
47
     * Получить данные по uuid
48
     * @param string $uuid
49
     * @return ApiResponse
50
     * @throws RequestException
51
     */
52
    public function get(string $uuid): ApiResponse
53
    {
54
        return $this->http_client->get($this->slug($uuid));
55
    }
56
57
    /**
58
     * Отправка запрос на добавление элемента
59
     * @param array $params
60
     * @return ApiResponse
61
     * @throws RequestException
62
     */
63
    protected function preparedAdd(array $params = []): ApiResponse
64
    {
65
        return $this->http_client->post($this->slug(), $params);
66
    }
67
68
    /**
69
     * Форматирование url для запросов
70
     * @param string|null $uuid
71
     * @return string
72
     */
73
    protected function slug(string $uuid = null): string
74
    {
75
        if (empty($uuid)) {
76
            return static::URL;
77
        }
78
        return static::URL . '/' . $uuid;
79
    }
80
}
81