CustomCollectionEndpoint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 65
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A findOne() 0 5 1
A countAll() 0 5 1
A update() 0 5 1
A delete() 0 4 1
A findAll() 0 5 1
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 CustomCollectionEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param array $query
14
     * @return array|GenericResource[]
15
     */
16
    public function findAll(array $query = array())
17
    {
18
        $request = new GetJson('/admin/custom_collections.json', $query);
19
        $response = $this->sendPaged($request, 'custom_collections');
20
        return $this->createCollection($response);
21
    }
22
23
    /**
24
     * @param array $query
25
     * @return int
26
     */
27
    public function countAll(array $query = array())
28
    {
29
        $request = new GetJson('/admin/custom_collections/count.json', $query);
30
        $response = $this->send($request);
31
        return $response->get('count');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->get('count') also could return the type string which is incompatible with the documented return type integer.
Loading history...
32
    }
33
34
    /**
35
     * @param int $customCollectionId
36
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
37
     */
38
    public function findOne($customCollectionId)
39
    {
40
        $request = new GetJson('/admin/custom_collections/' . $customCollectionId . '.json');
41
        $response = $this->send($request);
42
        return $this->createEntity($response->get('custom_collection'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('custom_collection') 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

42
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('custom_collection'));
Loading history...
43
    }
44
45
    /**
46
     * @param GenericResource $customCollection
47
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
48
     */
49
    public function create(GenericResource $customCollection)
50
    {
51
        $request = new PostJson('/admin/custom_collections.json', array('custom_collection' => $customCollection->toArray()));
52
        $response = $this->send($request);
53
        return $this->createEntity($response->get('custom_collection'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('custom_collection') 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

53
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('custom_collection'));
Loading history...
54
    }
55
56
    /**
57
     * @param int $customCollectionId
58
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $customCollection
59
     * @return GenericResource
60
     */
61
    public function update($customCollectionId, GenericResource $customCollection)
62
    {
63
        $request = new PutJson('/admin/custom_collections/' . $customCollectionId . '.json', array('custom_collection' => $customCollection->toArray()));
64
        $response = $this->send($request);
65
        return $this->createEntity($response->get('custom_collection'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('custom_collection') 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

65
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('custom_collection'));
Loading history...
66
    }
67
68
    /**
69
     * @param int $customCollectionId
70
     */
71
    public function delete($customCollectionId)
72
    {
73
        $request = new DeleteParams('/admin/custom_collections/' . $customCollectionId . '.json');
74
        $this->send($request);
75
    }
76
}
77