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

Contact   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 69
loc 69
c 3
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\LeadsLinkable;
7
8
/**
9
 * Class Contact
10
 * @package linkprofit\AmoCRM\entities
11
 */
12 View Code Duplication
class Contact 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 = 1;
18
19
    /**
20
     * @var string Название контакта
21
     */
22
    public $name;
23
24
    /**
25
     * @var integer id пользователя создавшего контакт
26
     */
27
    public $created_by;
28
29
    /**
30
     * @var string Название новой компании. Параметр указывается для создания новой компании и привязке к ней контакта. Для привязки контакта к уже существующей компании, необходимо использовать параметр company_id
31
     */
32
    public $company_name;
33
34
    /**
35
     * @var string Теги, привязываемые к контакту. Задаются целостной строковой переменной, внутри строки перечисляются через запятую
36
     */
37
    public $tags;
38
39
    /**
40
     * @var string Покупатели, привязываемые к контакту. Перечисляются через запятую.
41
     */
42
    public $customers_id;
43
44
    /**
45
     * @var array
46
     */
47
    protected $fieldList = [
48
        'id', 'name', 'created_at', 'updated_at',
49
        'responsible_user_id', 'created_by', 'company_name',
50
        'tags', 'leads_id', 'customers_id', 'company_id',
51
    ];
52
53
    use CompanyLinkable,
54
        LeadsLinkable;
55
56
    /**
57
     * @param $entityClass
58
     *
59
     * @return bool
60
     */
61 4
    public function supports($entityClass)
62
    {
63 4
        $supportedClasses = [Task::class, Note::class];
64
65 4
        return in_array($entityClass, $supportedClasses, 1) && !empty($this->id);
66
    }
67
68
    /**
69
     * @param LinkElementCapableEntity $entity
70
     *
71
     * @return LinkElementCapableEntity
72
     */
73 2
    public function linkSelf(LinkElementCapableEntity $entity)
74
    {
75 2
        $entity->element_type = self::ELEMENT_TYPE;
76 2
        $entity->element_id = $this->id;
77
78 2
        return $entity;
79
    }
80
}