Passed
Pull Request — master (#19)
by Thijs
11:57
created

ManagesWebhooks::deleteWebhook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace TestMonitor\DevOps\Actions;
4
5
use TestMonitor\DevOps\Resources\Webhook;
6
use TestMonitor\DevOps\Transforms\TransformsWebhooks;
7
8
trait ManagesWebhooks
9
{
10
    use TransformsWebhooks;
11
12
    /**
13
     * Get a list of webhooks.
14
     *
15
     * @param string $eventType
16
     *
17
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
18
     *
19
     * @return \TestMonitor\DevOps\Resources\Webhook[]
20
     */
21
    public function webhooks($eventType = '')
22
    {
23
        $response = $this->get("_apis/hooks/subscriptions", [
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        /** @scrutinizer ignore-call */ 
24
        $response = $this->get("_apis/hooks/subscriptions", [
Loading history...
24
            'query' => array_filter([
25
                'eventType' => $eventType,
26
                'consumerId' => 'webHooks',
27
            ]),
28
        ]);
29
30
        return $this->fromDevOpsWebhooks($response['value']);
31
    }
32
33
    /**
34
     * Create a new webhook.
35
     *
36
     * @param \TestMonitor\DevOps\Resources\Webhook $webhook
37
     *
38
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
39
     *
40
     * @return \TestMonitor\DevOps\Resources\Webhook
41
     */
42
    public function createWebhook(Webhook $webhook): Webhook
43
    {
44
        $response = $this->post('_apis/hooks/subscriptions',
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        /** @scrutinizer ignore-call */ 
45
        $response = $this->post('_apis/hooks/subscriptions',
Loading history...
45
            [
46
                'json' => $this->toDevOpsWebhook($webhook),
47
            ]
48
        );
49
50
        return $this->fromDevOpsWebhook($response);
51
    }
52
53
    /**
54
     * Deletes a webhook.
55
     *
56
     * @param int $id
57
     *
58
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
59
     *
60
     * @return bool
61
     */
62
    public function deleteWebhook($id): bool
63
    {
64
        $response = $this->delete("_apis/hooks/subscriptions/{$id}");
0 ignored issues
show
Bug introduced by
The method delete() does not exist on TestMonitor\DevOps\Actions\ManagesWebhooks. Did you maybe mean deleteWebhook()? ( Ignorable by Annotation )

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

64
        /** @scrutinizer ignore-call */ 
65
        $response = $this->delete("_apis/hooks/subscriptions/{$id}");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
66
        return empty($response);
67
    }
68
}
69