Passed
Push — master ( ae5df4...18b32f )
by Jens
18:19 queued 10:07
created

ShippingMethodRequestBuilder::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Builder\Request;
7
8
use Commercetools\Core\Model\ShippingMethod\ShippingMethod;
9
use Commercetools\Core\Model\ShippingMethod\ShippingMethodDraft;
10
use Commercetools\Core\Model\Zone\Location;
11
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByCartIdGetRequest;
12
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByIdGetRequest;
13
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByKeyGetRequest;
14
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByLocationGetRequest;
15
use Commercetools\Core\Request\ShippingMethods\ShippingMethodCreateRequest;
16
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteByKeyRequest;
17
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteRequest;
18
use Commercetools\Core\Request\ShippingMethods\ShippingMethodQueryRequest;
19
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateByKeyRequest;
20
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateRequest;
21
22
class ShippingMethodRequestBuilder
23
{
24
    /**
25
     * @return ShippingMethodQueryRequest
26
     */
27 1
    public function query()
28
    {
29 1
        return ShippingMethodQueryRequest::of();
30
    }
31
32
    /**
33
     * @param ShippingMethod $shippingMethod
34
     * @return ShippingMethodUpdateRequest
35
     */
36 1
    public function update(ShippingMethod $shippingMethod)
37
    {
38 1
        return ShippingMethodUpdateRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion());
39
    }
40
41
    /**
42
     * @param ShippingMethod $shippingMethod
43
     * @return ShippingMethodUpdateByKeyRequest
44
     */
45 1
    public function updateByKey(ShippingMethod $shippingMethod)
46
    {
47 1
        return ShippingMethodUpdateByKeyRequest::ofKeyAndVersion(
48 1
            $shippingMethod->getKey(),
49 1
            $shippingMethod->getVersion()
50
        );
51
    }
52
53
    /**
54
     * @param ShippingMethodDraft $shippingMethodDraft
55
     * @return ShippingMethodCreateRequest
56
     */
57 1
    public function create(ShippingMethodDraft $shippingMethodDraft)
58
    {
59 1
        return ShippingMethodCreateRequest::ofDraft($shippingMethodDraft);
60
    }
61
62
    /**
63
     * @param ShippingMethod $shippingMethod
64
     * @return ShippingMethodDeleteRequest
65
     */
66 1
    public function delete(ShippingMethod $shippingMethod)
67
    {
68 1
        return ShippingMethodDeleteRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion());
69
    }
70
71
    /**
72
     * @param ShippingMethod $shippingMethod
73
     * @return ShippingMethodDeleteByKeyRequest
74
     */
75 1
    public function deleteByKey(ShippingMethod $shippingMethod)
76
    {
77 1
        return ShippingMethodDeleteByKeyRequest::ofKeyAndVersion(
78 1
            $shippingMethod->getKey(),
79 1
            $shippingMethod->getVersion()
80
        );
81
    }
82
83
    /**
84
     * @param string $id
85
     * @return ShippingMethodByIdGetRequest
86
     */
87 1
    public function getById($id)
88
    {
89 1
        return ShippingMethodByIdGetRequest::ofId($id);
90
    }
91
92
    /**
93
     * @param string $key
94
     * @return ShippingMethodByKeyGetRequest
95
     */
96 1
    public function getByKey($key)
97
    {
98 1
        return ShippingMethodByKeyGetRequest::ofKey($key);
99
    }
100
101
    /**
102
     * @param string $cartId
103
     * @return ShippingMethodByCartIdGetRequest
104
     */
105
    public function getByCartId($cartId)
106
    {
107
        return ShippingMethodByCartIdGetRequest::ofCartId($cartId);
108
    }
109
110
    /**
111
     * @param Location $location
112
     * @param string $currency
113
     * @return ShippingMethodByLocationGetRequest
114
     */
115
    public function getByLocation(Location $location, $currency = null)
116
    {
117
        $request = ShippingMethodByLocationGetRequest::ofCountry($location->getCountry());
118
        if (!is_null($location->getState())) {
0 ignored issues
show
introduced by
The condition is_null($location->getState()) is always false.
Loading history...
119
            $request->withState($location->getState());
120
        }
121
        if (!is_null($currency)) {
122
            $request->withCurrency($currency);
123
        }
124
        return $request;
125
    }
126
}
127