Pipeline::find()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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