Passed
Pull Request — master (#4)
by
unknown
07:28
created

Webhooks::list()   A

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
/**
4
 * Copyright (c) 2019. CDEK-IT. All rights reserved.
5
 * See LICENSE.md for license details.
6
 *
7
 * @author Chizhekov Viktor
8
 */
9
10
namespace CdekSDK2\Actions;
11
12
use CdekSDK2\BaseTypes\InputHook;
13
use CdekSDK2\BaseTypes\WebHook;
14
use CdekSDK2\Http\ApiResponse;
15
16
/**
17
 * Class Webhooks
18
 * @package CdekSDK2\Actions
19
 */
20
class Webhooks extends ActionsWithDelete
21
{
22
    /**
23
     * URL для запросов к API
24
     * @var string
25
     */
26
    public const URL = '/webhooks';
27
28
    /**
29
     * Добавление нового слушателя вебхуков
30
     * @param WebHook $webHook
31
     * @return ApiResponse
32
     * @throws \CdekSDK2\Exceptions\RequestException
33
     */
34 1
    public function add(WebHook $webHook): ApiResponse
35
    {
36 1
        $params = $this->serializer->toArray($webHook);
37 1
        return $this->preparedAdd($params);
0 ignored issues
show
Bug introduced by
$params of type PhpOption\T is incompatible with the type array expected by parameter $params of CdekSDK2\Actions\Action::preparedAdd(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return $this->preparedAdd(/** @scrutinizer ignore-type */ $params);
Loading history...
38
    }
39
40
    /**
41
     * Получение списка вебхуков
42
     * @return ApiResponse
43
     * @throws \CdekSDK2\Exceptions\RequestException
44
     */
45
    public function list(): ApiResponse
46
    {
47
        return $this->get('');
48
    }
49
50
    /**
51
     * Парсер входящих хуков
52
     * @param string $string
53
     * @return InputHook
54
     */
55 2
    public function parse(string $string): InputHook
56
    {
57
        try {
58 2
            $result = $this->serializer->deserialize($string, InputHook::class, 'json');
59 1
        } catch (\Exception $e) {
60 1
            $result = new InputHook();
61
        }
62 2
        return $result;
63
    }
64
}
65