CustomerSavedSearchEndpoint::countAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 CustomerSavedSearchEndpoint 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/customer_saved_searches.json', $query);
19
        $response = $this->sendPaged($request, 'customer_saved_searches');
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/customer_saved_searches/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 $savedSearchId
36
     * @param array $fields
37
     * @return GenericResource
38
     */
39
    public function findOne($savedSearchId, array $fields = array())
40
    {
41
        $params = $fields ? array('fields' => $fields) : array();
42
        $request = new GetJson('/admin/customer_saved_searches/' . $savedSearchId . '.json', $params);
43
        $response = $this->send($request);
44
        return $this->createEntity($response->get('customer_saved_search'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_saved_search') 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

44
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_saved_search'));
Loading history...
45
    }
46
47
    /**
48
     * @param int $savedSearchId
49
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
50
     */
51
    public function findCustomersForSavedSearch($savedSearchId, array $query = array())
52
    {
53
        $request = new GetJson('/admin/customer_saved_searches/' . $savedSearchId . '/customers.json', $query);
54
        $response = $this->sendPaged($request, 'customers');
55
        return $this->createCollection($response);
56
    }
57
58
    /**
59
     * @param GenericResource $savedSearch
60
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
61
     */
62
    public function create(GenericResource $savedSearch)
63
    {
64
        $request = new PostJson('/admin/customer_saved_searches.json', array('customer_saved_search' => $savedSearch->toArray()));
65
        $response = $this->send($request);
66
        return $this->createEntity($response->get('customer_saved_search'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_saved_search') 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

66
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_saved_search'));
Loading history...
67
    }
68
69
    /**
70
     * @param int $savedSearchId
71
     * @param GenericResource $savedSearch
72
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
73
     */
74
    public function update($savedSearchId, GenericResource $savedSearch)
75
    {
76
        $request = new PutJson('/admin/customer_saved_searches/' . $savedSearchId . '.json', array('customer_saved_search' => $savedSearch->toArray()));
77
        $response = $this->send($request);
78
        return $this->createEntity($response->get('customer_saved_search'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_saved_search') 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

78
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_saved_search'));
Loading history...
79
    }
80
81
    /**
82
     * @param int $savedSearchId
83
     */
84
    public function delete($savedSearchId)
85
    {
86
        $request = new DeleteParams('/admin/customer_saved_searches/' . $savedSearchId . '.json');
87
        $this->send($request);
88
    }
89
}
90