1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Streak\Endpoint; |
4
|
|
|
|
5
|
|
|
class Pipeline extends AbstractEndpoint |
6
|
|
|
{ |
7
|
|
|
const ENDPOINT = 'pipelines'; |
8
|
|
|
|
9
|
|
View Code Duplication |
public function all($sortBy = null) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$options = []; |
12
|
|
|
|
13
|
|
|
if (null !== $sortBy) { |
14
|
|
|
if (!in_array($sortBy, ['creationTimestamp', 'lastUpdatedTimestamp'])) { |
15
|
|
|
throw new \InvalidArgumentException('Invalid sort field.'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$options['query'] = ['sortBy' => $sortBy]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
return $this->client->get(self::ENDPOINT, $options); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function find($pipelineKey) |
25
|
|
|
{ |
26
|
|
|
return $this->client->get(sprintf('%s/%s', self::ENDPOINT, $pipelineKey)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function create(array $pipeline) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
if (!isset($pipeline['name']) || !isset($pipeline['description'])) { |
32
|
|
|
throw new \InvalidArgumentException('Missing required fields.'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $this->client->put(self::ENDPOINT, [ |
36
|
|
|
'form_params' => $pipeline, |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function delete($pipelineKey) |
41
|
|
|
{ |
42
|
|
|
return $this->client->delete(sprintf('%s/%s', self::ENDPOINT, $pipelineKey)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function edit($pipelineKey, array $pipeline) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
foreach ($pipeline as $field => $value) { |
48
|
|
|
if (!in_array($field, ['name', 'description', 'stageOrder', 'orgWide', 'aclEntries'])) { |
49
|
|
|
throw new \InvalidArgumentException('Not allowed field.'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->client->post(sprintf('%s/%s', self::ENDPOINT, $pipelineKey), [ |
54
|
|
|
'json' => $pipeline, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.