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

ContactService::composeListLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\Contact;
6
use linkprofit\AmoCRM\entities\EntityInterface;
7
use linkprofit\AmoCRM\traits\IdentifiableList;
8
use linkprofit\AmoCRM\traits\PaginableList;
9
use linkprofit\AmoCRM\traits\TermList;
10
11
/**
12
 * Class ContactService
13
 * @package linkprofit\AmoCRM\services
14
 */
15
class ContactService extends BaseService
16
{
17
    use IdentifiableList,
18
        TermList,
19
        PaginableList;
20
21
    /**
22
     * @var Contact[]
23
     */
24
    protected $entities = [];
25
26
    /**
27
     * @param Contact $contact
28
     */
29 4
    public function add(EntityInterface $contact)
30
    {
31 4
        if ($contact instanceof Contact) {
32 4
            $this->entities[] = $contact;
33
        }
34 4
    }
35
36
    /**
37
     * @param $link
38
     *
39
     * @return string
40
     */
41
    protected function composeListLink($link)
42
    {
43
        $query = $this->addTermToQuery();
44
        $query = $this->addIdToQuery($query);
45
        $query = $this->addPaginationToQuery($query);
46
47
        $link .= '?' . http_build_query($query);
48
49
        return $link;
50
    }
51
52
    /**
53
     * @param $array
54
     * @return Contact
55
     */
56 4
    public function parseArrayToEntity($array)
57
    {
58 4
        $contact = new Contact();
59 4
        $contact->set($array);
60
61 4
        return $contact;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 4
    protected function getLink()
68
    {
69 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/contacts';
70
    }
71
}