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

Webhooks   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

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

3 Methods

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