Pipeline   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 67.92 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 2
dl 36
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 14 14 3
A find() 0 4 1
A create() 10 10 3
A delete() 0 4 1
A edit() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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