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

TaskService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 5
dl 55
loc 55
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\Task;
7
use linkprofit\AmoCRM\traits\IdentifiableList;
8
use linkprofit\AmoCRM\traits\PaginableList;
9
10
/**
11
 * Class TaskService
12
 * @package linkprofit\AmoCRM\services
13
 */
14 View Code Duplication
class TaskService 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
        PaginableList;
18
19
    /**
20
     * @var Task[]
21
     */
22
    protected $entities = [];
23
24
    /**
25
     * @param Task $task
26
     */
27 3
    public function add(EntityInterface $task)
28
    {
29 3
        if ($task instanceof Task) {
30 3
            $this->entities[] = $task;
31
        }
32 3
    }
33
34
    /**
35
     * @param $link
36
     *
37
     * @return string
38
     */
39
    protected function composeListLink($link)
40
    {
41
        $query = $this->addIdToQuery();
42
43
        $link .= '?' . http_build_query($query);
44
45
        return $link;
46
    }
47
48
    /**
49
     * @param $array
50
     * @return Task
51
     */
52 3
    public function parseArrayToEntity($array)
53
    {
54 3
        $task = new Task();
55 3
        $task->set($array);
56
57 3
        return $task;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 3
    protected function getLink()
64
    {
65 3
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/tasks';
66
    }
67
68
}