CustomerEndpoint   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 4 1
A findAll() 0 5 1
A search() 0 5 1
A findOrdersForCustomer() 0 6 2
A findOne() 0 5 1
A update() 0 5 1
A create() 0 5 1
A countAll() 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\GenericResource;
8
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
9
10
class CustomerEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param array $query
14
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
15
     */
16
    public function findAll(array $query = array())
17
    {
18
        $request = new GetJson('/admin/customers.json', $query);
19
        $response = $this->sendPaged($request, 'customers');
20
        return $this->createCollection($response);
21
    }
22
23
    /**
24
     * @param int $customerId
25
     * @param array $fields
26
     * @return array|GenericResource[]
27
     */
28
    public function findOrdersForCustomer($customerId, array $fields = array())
29
    {
30
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
31
        $request = new GetJson('/admin/customers/' . $customerId . '.json', $params);
32
        $response = $this->sendPaged($request, 'customers');
33
        return $this->createCollection($response);
34
    }
35
36
    /**
37
     * @param array $query
38
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
39
     */
40
    public function search(array $query = array())
41
    {
42
        $request = new GetJson('/admin/customers/search.json', $query);
43
        $response = $this->sendPaged($request, 'customers');
44
        return $this->createCollection($response);
45
    }
46
47
    /**
48
     * @return int
49
     */
50
    public function countAll()
51
    {
52
        $request = new GetJson('/admin/customers/count.json');
53
        $response = $this->send($request);
54
        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...
55
    }
56
57
    /**
58
     * @param int $customerId
59
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
60
     */
61
    public function findOne($customerId)
62
    {
63
        $request = new GetJson('/admin/customers/' . $customerId . '.json');
64
        $response = $this->send($request);
65
        return $this->createEntity($response->get('customer'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer') 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('customer'));
Loading history...
66
    }
67
68
    /**
69
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $customer
70
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
71
     */
72
    public function create(GenericResource $customer)
73
    {
74
        $request = new PostJson('/admin/customers.json', array('customer' => $customer->toArray()));
75
        $response = $this->send($request);
76
        return $this->createEntity($response->get('customer'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer') 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

76
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer'));
Loading history...
77
    }
78
79
    /**
80
     * @param int $customerId
81
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $customer
82
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
83
     */
84
    public function update($customerId, GenericResource $customer)
85
    {
86
        $request = new PutJson('/admin/customers/' . $customerId . '.json', array('customer' => $customer->toArray()));
87
        $response = $this->send($request);
88
        return $this->createEntity($response->get('customer'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer') 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

88
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer'));
Loading history...
89
    }
90
91
    /**
92
     * @param int $customerId
93
     */
94
    public function delete($customerId)
95
    {
96
        $request = new DeleteParams('/admin/customers/' . $customerId . '.json');
97
        $this->send($request);
98
    }
99
}
100