ThemeEndpoint   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 4 1
A create() 0 5 1
A findOne() 0 6 2
A update() 0 5 1
A findAll() 0 6 2
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson;
7
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
8
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
9
10
class ThemeEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param array $fields
14
     * @return array|GenericResource[]
15
     */
16
    public function findAll(array $fields = array())
17
    {
18
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
19
        $request = new GetJson('/admin/themes.json', $params);
20
        $response = $this->send($request);
21
        return $this->createCollection($response->get('themes'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('themes') can also be of type string; however, parameter $items of CodeCloud\Bundle\Shopify...int::createCollection() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
        return $this->createCollection(/** @scrutinizer ignore-type */ $response->get('themes'));
Loading history...
22
    }
23
24
    /**
25
     * @param int $themeId
26
     * @param array $fields
27
     * @return GenericResource
28
     */
29
    public function findOne($themeId, array $fields = array())
30
    {
31
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
32
        $request = new GetJson('/admin/themes/' . $themeId . '.json', $params);
33
        $response = $this->send($request);
34
        return $this->createEntity($response->get('theme'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('theme') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('theme'));
Loading history...
35
    }
36
37
    /**
38
     * @param GenericResource $theme
39
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
40
     */
41
    public function create(GenericResource $theme)
42
    {
43
        $request = new PostJson('/admin/themes.json', array('theme' => $theme->toArray()));
44
        $response = $this->send($request);
45
        return $this->create($response->get('theme'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('theme') can also be of type null and string; however, parameter $theme of CodeCloud\Bundle\Shopify...ThemeEndpoint::create() does only seem to accept CodeCloud\Bundle\ShopifyBundle\Api\GenericResource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        return $this->create(/** @scrutinizer ignore-type */ $response->get('theme'));
Loading history...
46
    }
47
48
    /**
49
     * @param int $themeId
50
     * @param GenericResource $theme
51
     * @return GenericResource
52
     */
53
    public function update($themeId, $theme)
54
    {
55
        $request = new PutJson('/admin/themes/' . $themeId . '.json', array('theme' => $theme->toArray()));
56
        $response = $this->send($request);
57
        return $this->create($response->get('theme'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('theme') can also be of type null and string; however, parameter $theme of CodeCloud\Bundle\Shopify...ThemeEndpoint::create() does only seem to accept CodeCloud\Bundle\ShopifyBundle\Api\GenericResource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        return $this->create(/** @scrutinizer ignore-type */ $response->get('theme'));
Loading history...
58
    }
59
60
    /**
61
     * @param int $themeId
62
     */
63
    public function delete($themeId)
64
    {
65
        $request = new DeleteParams('/admin/themes/' . $themeId . '.json');
66
        $this->send($request);
67
    }
68
}
69