Completed
Push — dev ( 4a164e...157791 )
by Konstantin
02:03
created

PipelineService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 4
dl 53
loc 53
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 6 6 2
A composeListLink() 8 8 1
A parseArrayToEntity() 7 7 1
A getLink() 4 4 1

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 linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\EntityInterface;
6
use linkprofit\AmoCRM\entities\Pipeline;
7
use linkprofit\AmoCRM\RequestHandler;
8
use linkprofit\AmoCRM\traits\IdentifiableList;
9
10
/**
11
 * Class PipelineService
12
 * @package linkprofit\AmoCRM\services
13
 */
14 View Code Duplication
class PipelineService extends BaseService
0 ignored issues
show
Duplication introduced by
This class 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...
15
{
16
    use IdentifiableList;
17
18
    /**
19
     * @var Pipeline[]
20
     */
21
    protected $entities = [];
22
23
    /**
24
     * @param Pipeline $pipeline
25
     */
26 4
    public function add(EntityInterface $pipeline)
27
    {
28 4
        if ($pipeline instanceof Pipeline) {
29 4
            $this->entities[] = $pipeline;
30
        }
31 4
    }
32
33
    /**
34
     * @param $link
35
     *
36
     * @return string
37
     */
38
    protected function composeListLink($link)
39
    {
40
        $query = $this->addIdToQuery();
41
42
        $link .= '?' . http_build_query($query);
43
44
        return $link;
45
    }
46
47
    /**
48
     * @param $array
49
     * @return Pipeline
50
     */
51 4
    public function parseArrayToEntity($array)
52
    {
53 4
        $pipeline = new Pipeline();
54 4
        $pipeline->set($array);
55
56 4
        return $pipeline;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 4
    protected function getLink()
63
    {
64 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/private/api/v2/json/pipelines/set';
65
    }
66
}