Passed
Push — develop ( a27dd2...8f2abb )
by Edwin
03:09
created

Fulfillment::open()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace ShopifyClient\Resource;
4
5
class Fulfillment extends AbstractNestedCountableCrudResource
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $resourceParentEndpointPleural = 'orders';
11
12
    /**
13
     * @var string
14
     */
15
    protected $resourceChildEndpointPleural = 'fulfillments';
16
17
    /**
18
     * @var string
19
     */
20
    protected $resourceChildKeySingular = 'fulfillment';
21
22
    /**
23
     * @var string
24
     */
25
    protected $resourceChildKeyPleural = 'fulfillments';
26
27
    /**
28
     * @param float $parentId
29
     * @param float $id
30
     * @return array
31
     */
32 1
    public function complete(float $parentId, float $id): array
33
    {
34 1
        return $this->changeStatus('complete', $parentId, $id);
35
    }
36
37
    /**
38
     * @param float $parentId
39
     * @param float $id
40
     * @return array
41
     */
42 1
    public function open(float $parentId, float $id): array
43
    {
44 1
        return $this->changeStatus('open', $parentId, $id);
45
    }
46
47
    /**
48
     * @param float $parentId
49
     * @param float $id
50
     * @return array
51
     */
52 1
    public function cancel(float $parentId, float $id): array
53
    {
54 1
        return $this->changeStatus('cancel', $parentId, $id);
55
    }
56
57
    /**
58
     * @param string $status
59
     * @param float $parentId
60
     * @param float $id
61
     * @return array
62
     */
63 3
    private function changeStatus(string $status, float $parentId, float $id): array
64
    {
65 3
        $response = $this->request('POST', sprintf(
66 3
            '/admin/%s/%s/%s/%s/%s.json',
67 3
            $this->resourceParentEndpointPleural,
68 3
            $parentId,
69 3
            $this->resourceChildEndpointPleural,
70 3
            $id,
71 3
            $status
72
        ));
73
74 1
        return $response[$this->resourceChildKeySingular];
75
    }
76
}
77