CatalogService::composeListLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.9666
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\Catalog;
6
use linkprofit\AmoCRM\entities\EntityInterface;
7
use linkprofit\AmoCRM\traits\IdentifiableList;
8
use linkprofit\AmoCRM\traits\PaginableList;
9
10
/**
11
 * Class CatalogService
12
 *
13
 * @package linkprofit\AmoCRM\services
14
 */
15
class CatalogService extends BaseService implements ListableService
16
{
17
    use IdentifiableList, PaginableList;
18
19
    /**
20
     * @var Catalog[]
21
     */
22
    protected $entities = [];
23
24
    /**
25
     * @param Catalog $catalog
26
     */
27 5
    public function add(EntityInterface $catalog)
28
    {
29 5
        if ($catalog instanceof Catalog) {
30 5
            $this->entities[] = $catalog;
31 5
        }
32 5
    }
33
34
    /**
35
     * @param $link
36
     *
37
     * @return string
38
     */
39 2
    protected function composeListLink($link)
40
    {
41 2
        $query = $this->addIdToQuery();
42 2
        $query = $this->addPaginationToQuery($query);
43
44 2
        $link .= '?' . http_build_query($query);
45
46 2
        return $link;
47
    }
48
49
    /**
50
     * @deprecated
51
     *
52
     * @param int|null
53
     *
54
     * @return array|bool
55
     */
56 1
    public function lists($id = null)
57
    {
58 1
        if ($id !== null) {
59
            $this->setId($id);
60
        }
61
62 1
        return $this->getList();
63
    }
64
65
    /**
66
     * @param $array
67
     *
68
     * @return Catalog
69
     */
70 5
    public function parseArrayToEntity($array)
71
    {
72 5
        $catalog = new Catalog();
73 5
        $catalog->set($array);
74
75 5
        return $catalog;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 5
    protected function getLink()
82
    {
83 5
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/catalogs';
84
    }
85
86
}