Completed
Pull Request — dev (#13)
by Konstantin
02:01
created

Lead   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 75
loc 75
c 5
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 6 6 2
A linkSelf() 7 7 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\entities;
4
5
use linkprofit\AmoCRM\traits\CompanyLinkable;
6
use linkprofit\AmoCRM\traits\ContactsLinkable;
7
8
/**
9
 * Class Lead
10
 * @package linkprofit\AmoCRM\entities
11
 */
12 View Code Duplication
class Lead extends CustomizableEntity implements LinkableElement
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...
13
{
14
    /**
15
     * Сделка
16
     */
17
    const ELEMENT_TYPE = 2;
18
19
    /**
20
     * @var string Название сделки
21
     */
22
    public $name;
23
24
    /**
25
     * @var integer Статус сделки (id этапа продаж см. Воронки и этапы продаж) Чтобы перенести сделку в другую воронку, необходимо установить ей статус из нужной воронки
26
     */
27
    public $status_id;
28
29
    /**
30
     * @var integer ID воронки. Указывается в том случае, если выбраны статусы id 142 или 143, т.к. эти статусы не уникальны и обязательны для всех цифровых воронок.
31
     */
32
    public $pipeline_id;
33
34
    /**
35
     * @var integer Бюджет сделки
36
     */
37
    public $sale;
38
39
    /**
40
     * @var string Если вы хотите задать новые теги, перечислите их внутри строковой переменной через запятую
41
     */
42
    public $tags;
43
44
    /**
45
     * @var int Id пользователя изменившего сущность, если 0, то робот
46
     */
47
    public $modified_user_id;
48
49
    /**
50
     * @var array
51
     */
52
    protected $fieldList = [
53
        'id', 'name', 'created_at', 'updated_at',
54
        'status_id', 'pipeline_id', 'responsible_user_id',
55
        'sale', 'tags', 'contacts_id', 'company_id',
56
        'modified_user_id'
57
    ];
58
59
    use CompanyLinkable,
60
        ContactsLinkable;
61
62
    /**
63
     * @param $entityClass
64
     *
65
     * @return bool
66
     */
67 4
    public function supports($entityClass)
68
    {
69 4
        $supportedClasses = [Task::class, Note::class];
70
71 4
        return in_array($entityClass, $supportedClasses, 1) && !empty($this->id);
72
    }
73
74
    /**
75
     * @param LinkElementCapableEntity $entity
76
     *
77
     * @return LinkElementCapableEntity
78
     */
79 2
    public function linkSelf(LinkElementCapableEntity $entity)
80
    {
81 2
        $entity->element_type = self::ELEMENT_TYPE;
82 2
        $entity->element_id = $this->id;
83
84 2
        return $entity;
85
    }
86
}