1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Webhook; |
4
|
|
|
|
5
|
|
|
use JiraRestApi\JiraClient; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class WebhookService |
10
|
|
|
* @package JiraRestApi\Webhook |
11
|
|
|
*/ |
12
|
|
|
class WebhookService extends JiraClient |
13
|
|
|
{ |
14
|
|
|
protected $api_uri = '/rest/webhooks/1.0'; |
15
|
|
|
private $uri = '/webhook'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* get all project list. |
19
|
|
|
* @return bool|mixed |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function getAllWebhooks() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$result = $this->exec($this->uri); |
24
|
|
|
|
25
|
|
|
return $this->extractErrors($result, [200], function () use ($result) { |
26
|
|
|
return $this->json_mapper->mapArray( |
27
|
|
|
$result->getRawData(), new \ArrayObject(), '\JiraRestApi\Webhook\Webhook' |
28
|
|
|
); |
29
|
|
|
}); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $webhookId |
34
|
|
|
* |
35
|
|
|
* @return bool|object |
36
|
|
|
* @throws \JsonMapper_Exception |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function get($webhookId) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$result = $this->exec($this->uri . '/' . $webhookId); |
41
|
|
|
|
42
|
|
|
return $this->extractErrors($result, [200], function () use ($result) { |
43
|
|
|
return $this->json_mapper->map( |
44
|
|
|
$result->getRawData(), new Webhook() |
45
|
|
|
); |
46
|
|
|
}); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Webhook $webhook |
51
|
|
|
* |
52
|
|
|
* @return mixed |
53
|
|
|
*/ |
54
|
|
|
public function create(Webhook $webhook) |
55
|
|
|
{ |
56
|
|
|
$data = $this->filterNullVariable($webhook); |
57
|
|
|
|
58
|
|
|
$result = $this->exec($this->uri, $data, Request::METHOD_POST); |
59
|
|
|
|
60
|
|
|
return $this->extractErrors($result, [201], function () use ($result) { |
61
|
|
|
return $this->json_mapper->map( |
62
|
|
|
$result->getRawData(), new Webhook() |
63
|
|
|
); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $webhookId |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function delete($webhookId) |
73
|
|
|
{ |
74
|
|
|
$result = $this->exec($this->uri . '/' . $webhookId, null, Request::METHOD_DELETE); |
75
|
|
|
|
76
|
|
|
return $this->extractErrors($result, [204], function () use ($result) { |
77
|
|
|
return $result; |
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.