Completed
Pull Request — dev (#3)
by
unknown
01:49
created

CatalogService::lists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\Catalog;
6
use linkprofit\AmoCRM\entities\EntityInterface;
7
8
/**
9
 * Class CatalogService
10
 *
11
 * @package linkprofit\AmoCRM\services
12
 */
13
class CatalogService extends BaseService
14
{
15
    /**
16
     * @var \linkprofit\AmoCRM\entities\Catalog[]
17
     */
18
    protected $entities = [];
19
20
    /**
21
     * @param \linkprofit\AmoCRM\entities\EntityInterface|Catalog $catalog
22
     */
23 4
    public function add(EntityInterface $catalog)
24
    {
25 4
        if ($catalog instanceof Catalog) {
26 4
            $this->entities[] = $catalog;
27
        }
28 4
    }
29
30 1
    public function lists($id = null)
31
    {
32 1
        $link = $id ? $this->getLink().'?id='.$id : $this->getLink();
33 1
        $this->request->performRequest($link, [], 'application/json', 'GET');
34 1
        $this->response = $this->request->getResponse();
35
36 1
        return $this->parseResponseToEntities();
37
    }
38
39
    /**
40
     * @param $array
41
     * 
42
     * @return Catalog
43
     */
44 4
    public function parseArrayToEntity($array)
45
    {
46 4
        $catalog = new Catalog();
47 4
        $catalog->set($array);
48
49 4
        return $catalog;
50
    }
51
52
    /**
53
     * @return string
54
     */
55 4
    protected function getLink()
56
    {
57 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/catalogs';
58
    }
59
60
}