Passed
Pull Request — master (#19)
by Thijs
02:38 queued 46s
created

ManagesWebhooks   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 60
ccs 19
cts 19
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A webhooks() 0 10 1
A createWebhook() 0 10 1
A deleteWebhook() 0 5 1
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 5
    public function webhooks($eventType = '')
22
    {
23 5
        $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 5
            'query' => array_filter([
25 5
                'eventType' => $eventType,
26 5
                'consumerId' => 'webHooks',
27 5
            ]),
28 5
        ]);
29
30 1
        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 2
    public function createWebhook(Webhook $webhook): Webhook
43
    {
44 2
        $response = $this->post(
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(
Loading history...
45 2
            '_apis/hooks/subscriptions',
46 2
            [
47 2
                'json' => $this->toDevOpsWebhook($webhook),
48 2
            ]
49 2
        );
50
51 1
        return $this->fromDevOpsWebhook($response);
52
    }
53
54
    /**
55
     * Delete a webhook.
56
     *
57
     * @param int $id
58
     *
59
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
60
     *
61
     * @return bool
62
     */
63 2
    public function deleteWebhook($id): bool
64
    {
65 2
        $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

65
        /** @scrutinizer ignore-call */ 
66
        $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...
66
67 1
        return empty($response);
68
    }
69
}
70