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

CompanyService::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\Company;
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 CompanyService
13
 * @package linkprofit\AmoCRM\services
14
 */
15
class CompanyService extends BaseService
16
{
17
    use IdentifiableList,
18
        TermList,
19
        PaginableList;
20
21
    /**
22
     * @var Company[]
23
     */
24
    protected $entities = [];
25
26
    /**
27
     * @param Company $company
28
     */
29 4
    public function add(EntityInterface $company)
30
    {
31 4
        if ($company instanceof Company) {
32 4
            $this->entities[] = $company;
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 Company
55
     */
56 4
    public function parseArrayToEntity($array)
57
    {
58 4
        $company = new Company();
59 4
        $company->set($array);
60
61 4
        return $company;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 4
    protected function getLink()
68
    {
69 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/companies';
70
    }
71
}