Completed
Pull Request — master (#4)
by Konstantin
01:40
created

CatalogService::getLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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