Webhooks   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 3 1
A parse() 0 8 2
A add() 0 4 1
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