Completed
Pull Request — dev (#10)
by Konstantin
04:59
created

CatalogService::getList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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
     * @return array|bool
36
     */
37 2
    public function getList()
38
    {
39 2
        $link = $this->getLink() . '?';
40
41 2
        $link = $this->addIdToLink($link);
42 2
        $link = $this->addPaginationToLink($link);
43
44 2
        $this->request->performRequest($link, [], 'application/json', 'GET');
45 2
        $this->response = $this->request->getResponse();
46
47 2
        return $this->parseResponseToEntities();
48
    }
49
50
    /**
51
     * @deprecated
52
     *
53
     * @param int|null
54
     *
55
     * @return array|bool
56
     */
57 1
    public function lists($id = null)
58
    {
59 1
        if ($id !== null) {
60
            $this->setId($id);
61
        }
62
63 1
        return $this->getList();
64
    }
65
66
    /**
67
     * @param $array
68
     *
69
     * @return Catalog
70
     */
71 5
    public function parseArrayToEntity($array)
72
    {
73 5
        $catalog = new Catalog();
74 5
        $catalog->set($array);
75
76 5
        return $catalog;
77
    }
78
79
    /**
80
     * @return string
81
     */
82 5
    protected function getLink()
83
    {
84 5
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/catalogs';
85
    }
86
87
}