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

Contact::linkSelf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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
}