OrderEndpoint::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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 OrderEndpoint 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/orders.json', $query);
19
        $response = $this->sendPaged($request, 'orders');
20
        return $this->createCollection($response);
21
    }
22
23
    /**
24
     * @param int $orderId
25
     * @param array $fields
26
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
27
     */
28
    public function findOne($orderId, array $fields = array())
29
    {
30
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
31
        $request = new GetJson('/admin/orders/' . $orderId . '.json', $params);
32
        $response = $this->send($request);
33
        return $this->createEntity($response->get('order'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('order') 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

33
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('order'));
Loading history...
34
    }
35
36
    /**
37
     * @param array $query
38
     * @return int
39
     */
40
    public function countAll(array $query = array())
41
    {
42
        $request = new GetJson('/admin/orders/count.json', $query);
43
        $response = $this->send($request);
44
        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...
45
    }
46
47
    /**
48
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $order
49
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
50
     */
51
    public function create(GenericResource $order)
52
    {
53
        $request = new PostJson('/admin/orders.json', array('order' => $order->toArray()));
54
        $response = $this->send($request);
55
        return $this->createEntity($response->get('order'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('order') 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

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

67
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('order'));
Loading history...
68
    }
69
70
    /**
71
     * @param int $orderId
72
     */
73
    public function delete($orderId)
74
    {
75
        $request = new DeleteParams('/admin/orders/' . $orderId . '.json');
76
        $this->send($request);
77
    }
78
79
    /**
80
     * @param int $orderId
81
     */
82
    public function close($orderId)
83
    {
84
        $request = new PostJson('/admin/orders/' . $orderId . '/close.json');
85
        $this->send($request);
86
    }
87
88
    /**
89
     * @param int $orderId
90
     */
91
    public function open($orderId)
92
    {
93
        $request = new PostJson('/admin/orders/' . $orderId . '/open.json');
94
        $this->send($request);
95
    }
96
97
    /**
98
     * @param int $orderId
99
     * @param array $options
100
     */
101
    public function cancel($orderId, array $options = array())
102
    {
103
        $request = new PostJson('/admin/orders/' . $orderId . '/cancel.json', $options);
104
        $this->send($request);
105
    }
106
}
107