1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Streak\Endpoint; |
4
|
|
|
|
5
|
|
|
use Streak\Paginator; |
6
|
|
|
|
7
|
|
|
class Box extends AbstractEndpoint |
8
|
|
|
{ |
9
|
|
|
const ENDPOINT = 'boxes'; |
10
|
|
|
|
11
|
|
|
public function all() |
12
|
|
|
{ |
13
|
|
|
return $this->client->get(self::ENDPOINT); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function findAll($pipelineKey, $sortBy = null, Paginator $paginator = null) |
17
|
|
|
{ |
18
|
|
|
$options = ['query' => []]; |
19
|
|
|
|
20
|
|
|
if (null !== $sortBy) { |
21
|
|
|
if (!in_array($sortBy, ['creationTimestamp', 'lastUpdatedTimestamp'])) { |
22
|
|
|
throw new \InvalidArgumentException('Invalid sort field.'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$options['query']['sortBy'] = $sortBy; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (null === $paginator) { |
29
|
|
|
$paginator = new Paginator(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
while ($paginator->nextPage()) { |
33
|
|
|
$options['query']['page'] = $paginator->getPage(); |
34
|
|
|
$options['query']['limit'] = $paginator->getLimit(); |
35
|
|
|
|
36
|
|
|
$results = $this->client->get(sprintf('pipelines/%s/%s', $pipelineKey, self::ENDPOINT), $options); |
37
|
|
|
|
38
|
|
|
$paginator->addResults($results); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $paginator->getResults(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function create($pipelineKey, array $box) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
if (!isset($box['name'])) { |
47
|
|
|
throw new \InvalidArgumentException('Missing required fields.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->client->put(sprintf('pipelines/%s/%s', $pipelineKey, self::ENDPOINT), [ |
51
|
|
|
'form_params' => $box, |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function delete($boxKey) |
56
|
|
|
{ |
57
|
|
|
return $this->client->delete(sprintf('%s/%s', self::ENDPOINT, $boxKey)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function edit($boxKey, array $box) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
foreach ($box as $field => $value) { |
63
|
|
|
if (!in_array($field, ['name', 'notes', 'stageKey', 'followerKeys', 'fields'])) { |
64
|
|
|
throw new \InvalidArgumentException('Not allowed field.'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->client->post(sprintf('%s/%s', self::ENDPOINT, $boxKey), [ |
69
|
|
|
'json' => $box, |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function find($boxKey) |
74
|
|
|
{ |
75
|
|
|
return $this->client->get(sprintf('%s/%s', self::ENDPOINT, $boxKey)); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.