Notification Setup Error

We have detected an error in your notification set-up (Event-ID dab39dc24f564ec7bd4628d1305fd03c). Currently, we cannot inform you about inspection progress. Please check that the user 557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or update the API account.

Hooks::update()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 9.52
c 0
b 0
f 0
cc 4
nc 3
nop 4
crap 4
1
<?php
2
3
/**
4
 * This file is part of the bitbucket-api package.
5
 *
6
 * (c) Alexandru Guzinschi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bitbucket\API\Repositories;
13
14
use Bitbucket\API;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @author Alexandru Guzinschi <[email protected]>
19
 */
20
class Hooks extends API\Api
21
{
22
    /**
23
     * @access public
24
     * @param  string           $account The team or individual account owning the repository.
25
     * @param  string           $repo    The repository identifier.
26
     * @param  array            $params  Additional service parameters
27
     * @return ResponseInterface
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31 8
    public function create($account, $repo, array $params = array())
32
    {
33
        $mandatory = array(
34 8
            'description'   => 'My webhook',
35
            'url'           => '',
36
            'active'        => true,
37
            'events'        => array()
38
        );
39
40 8
        $diff = array_diff(array_keys($mandatory), array_keys($params));
41
42 8
        if (count($diff) > 0) {
43 4
            throw new \InvalidArgumentException('Missing parameters for creating a new webhook.');
44
        }
45
46 4
        if (false === array_key_exists('events', $params) || 0 === count($params['events'])) {
47 1
            throw new \InvalidArgumentException('Missing events for creating a new webhook.');
48
        }
49
50 3
        return $this->getClient()->setApiVersion('2.0')->post(
51 3
            sprintf('/repositories/%s/%s/hooks', $account, $repo),
52 3
            json_encode($params),
53 3
            array('Content-Type' => 'application/json')
54
        );
55
    }
56
57
    /**
58
     * @access public
59
     * @param  string           $account The team or individual account owning the repository.
60
     * @param  string           $repo    The repository identifier.
61
     * @param  string           $uuid    The universally unique identifier of the webhook.
62
     * @param  array            $params  Additional service parameters
63
     * @return ResponseInterface
64
     *
65
     * @throws \InvalidArgumentException
66
     */
67 6
    public function update($account, $repo, $uuid, array $params = array())
68
    {
69
        $mandatory = array(
70 6
            'description'   => 'My webhook',
71
            'url'           => '',
72
            'active'        => true,
73
            'events'        => array()
74
        );
75
76 6
        $diff = array_diff(array_keys($mandatory), array_keys($params));
77
78 6
        if (count($diff) > 0) {
79 4
            throw new \InvalidArgumentException('Missing parameters for updating a webhook.');
80
        }
81
82 2
        if (false === array_key_exists('events', $params) || 0 === count($params['events'])) {
83 1
            throw new \InvalidArgumentException('Missing events for updating a new webhook.');
84
        }
85
86 1
        return $this->getClient()->setApiVersion('2.0')->put(
87 1
            sprintf('/repositories/%s/%s/hooks/%s', $account, $repo, $uuid),
88 1
            json_encode($params),
89 1
            array('Content-Type' => 'application/json')
90
        );
91
    }
92
93
    /**
94
     * @access public
95
     * @param  string           $account The team or individual account owning the repository.
96
     * @param  string           $repo    The repository identifier.
97
     * @return ResponseInterface
98
     */
99 1
    public function all($account, $repo)
100
    {
101 1
        return $this->getClient()->setApiVersion('2.0')->get(
102 1
            sprintf('/repositories/%s/%s/hooks', $account, $repo)
103
        );
104
    }
105
106
    /**
107
     * @access public
108
     * @param  string           $account The team or individual account owning the repository.
109
     * @param  string           $repo    The repository identifier.
110
     * @param  string           $uuid    The universally unique identifier of the webhook.
111
     * @return ResponseInterface
112
     */
113 1
    public function get($account, $repo, $uuid)
114
    {
115 1
        return $this->getClient()->setApiVersion('2.0')->get(
116 1
            sprintf('/repositories/%s/%s/hooks/%s', $account, $repo, $uuid)
117
        );
118
    }
119
120
    /**
121
     * @access public
122
     * @param  string           $account The team or individual account owning the repository.
123
     * @param  string           $repo    The repository identifier.
124
     * @param  string           $uuid    The universally unique identifier of the webhook.
125
     * @return ResponseInterface
126
     */
127 1
    public function delete($account, $repo, $uuid)
128
    {
129 1
        return $this->getClient()->setApiVersion('2.0')->delete(
130 1
            sprintf('/repositories/%s/%s/hooks/%s', $account, $repo, $uuid)
131
        );
132
    }
133
}
134