FulFillmentEndpoint   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 83
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A complete() 0 4 1
A cancel() 0 4 1
A create() 0 5 1
A countByOrder() 0 5 1
A update() 0 5 1
A findOne() 0 6 2
A findByOrder() 0 5 1
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
7
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
8
9
class FulFillmentEndpoint extends AbstractEndpoint
10
{
11
    /**
12
     * @param int $orderId
13
     * @param array $query
14
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
15
     */
16
    public function findByOrder($orderId, array $query = array())
17
    {
18
        $request = new GetJson('/admin/orders/' . $orderId . '/fulfillments.json', $query);
19
        $response = $this->sendPaged($request, 'fulfillments');
20
        return $this->createCollection($response);
21
    }
22
23
    /**
24
     * @param int $orderId
25
     * @param array $query
26
     * @return int
27
     */
28
    public function countByOrder($orderId, array $query = array())
29
    {
30
        $request = new GetJson('/admin/orders/' . $orderId . '/fulfillments/count.json', $query);
31
        $response = $this->send($request);
32
        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...
33
    }
34
35
    /**
36
     * @param int $orderId
37
     * @param int $fulfillmentId
38
     * @param array $fields
39
     * @return GenericResource
40
     */
41
    public function findOne($orderId, $fulfillmentId, array $fields = array())
42
    {
43
        $params = $fields ? array('fields' => $fields) : array();
44
        $request = new GetJson('/admin/orders/' . $orderId . '/fulfillments/' . $fulfillmentId . '.json', $params);
45
        $response = $this->send($request);
46
        return $this->createEntity($response->get('fulfillment'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('fulfillment') 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

46
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('fulfillment'));
Loading history...
47
    }
48
49
    /**
50
     * @param int $orderId
51
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $fulfillment
52
     * @return GenericResource
53
     */
54
    public function create($orderId, GenericResource $fulfillment)
55
    {
56
        $request = new PostJson('/admin/orders/' . $orderId . '/fulfillments.json', array('fulfillment' => $fulfillment->toArray()));
57
        $response = $this->send($request);
58
        return $this->createEntity($response->get('fulfillment'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('fulfillment') 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

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

71
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('fulfillment'));
Loading history...
72
    }
73
74
    /**
75
     * @param int $orderId
76
     * @param int $fulfillmentId
77
     */
78
    public function complete($orderId, $fulfillmentId)
79
    {
80
        $request = new PostJson('/admin/orders/' . $orderId . '/fulfillments/' . $fulfillmentId . '/complete.json');
81
        $this->send($request);
82
    }
83
84
    /**
85
     * @param int $orderId
86
     * @param int $fulfillmentId
87
     */
88
    public function cancel($orderId, $fulfillmentId)
89
    {
90
        $request = new PostJson('/admin/orders/' . $orderId . '/fulfillments/' . $fulfillmentId . '/cancel.json');
91
        $this->send($request);
92
    }
93
}
94