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

LeadService::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\EntityInterface;
6
use linkprofit\AmoCRM\entities\Lead;
7
use linkprofit\AmoCRM\RequestHandler;
8
use linkprofit\AmoCRM\traits\IdentifiableList;
9
use linkprofit\AmoCRM\traits\PaginableList;
10
use linkprofit\AmoCRM\traits\TermList;
11
12
/**
13
 * Class LeadService
14
 * @package linkprofit\AmoCRM\services
15
 */
16
class LeadService extends BaseService
17
{
18
    use IdentifiableList,
19
        TermList,
20
        PaginableList;
21
22
    /**
23
     * @var Lead[]
24
     */
25
    protected $entities = [];
26
27
    /**
28
     * @param Lead $lead
29
     */
30 4
    public function add(EntityInterface $lead)
31
    {
32 4
        if ($lead instanceof Lead) {
33 4
            $this->entities[] = $lead;
34
        }
35 4
    }
36
37
    /**
38
     * @param $link
39
     *
40
     * @return string
41
     */
42
    protected function composeListLink($link)
43
    {
44
        $query = $this->addTermToQuery();
45
        $query = $this->addIdToQuery($query);
46
        $query = $this->addPaginationToQuery($query);
47
48
        $link .= '?' . http_build_query($query);
49
50
        return $link;
51
    }
52
53
    /**
54
     * @param $array
55
     * @return Lead
56
     */
57 4
    public function parseArrayToEntity($array)
58
    {
59 4
        $lead = new Lead();
60 4
        $lead->set($array);
61
62 4
        return $lead;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 4
    protected function getLink()
69
    {
70 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/leads';
71
    }
72
73
}