Webhooks::list()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Actions;
6
7
use CdekSDK2\BaseTypes\WebHook;
8
use CdekSDK2\Dto\InputHook;
9
use CdekSDK2\Http\ApiResponse;
10
11
/**
12
 * Class Webhooks
13
 * @package CdekSDK2\Actions
14
 */
15
class Webhooks extends ActionsWithDelete
16
{
17
    /**
18
     * URL для запросов к API
19
     * @var string
20
     */
21
    public const URL = '/webhooks';
22
23
    /**
24
     * Добавление нового слушателя вебхуков
25
     * @param WebHook $webHook
26
     * @return ApiResponse
27
     * @throws \CdekSDK2\Exceptions\RequestException
28
     */
29
    public function add(WebHook $webHook): ApiResponse
30
    {
31
        $params = $this->serializer->toArray($webHook);
32
        return $this->preparedAdd($params);
33
    }
34
35
    /**
36
     * Получение списка вебхуков
37
     * @return ApiResponse
38
     * @throws \CdekSDK2\Exceptions\RequestException
39
     */
40
    public function list(): ApiResponse
41
    {
42
        return $this->get('');
43
    }
44
45
    /**
46
     * Парсер входящих хуков
47
     * @param string $string
48
     * @return InputHook
49
     */
50
    public function parse(string $string): InputHook
51
    {
52
        try {
53
            $result = $this->serializer->deserialize($string, InputHook::class, 'json');
54
        } catch (\Exception $e) {
55
            $result = new InputHook();
56
        }
57
        return $result;
58
    }
59
}
60