Passed
Push — develop ( 793156...298c14 )
by Jens
09:21 queued 13s
created

Builder/Request/ShippingMethodRequestBuilder.php (1 issue)

Severity
1
<?php
2
// phpcs:disable Generic.Files.LineLength
3
namespace Commercetools\Core\Builder\Request;
4
5
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByCartIdGetRequest;
6
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByIdGetRequest;
7
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByKeyGetRequest;
8
use Commercetools\Core\Request\ShippingMethods\ShippingMethodByLocationGetRequest;
9
use Commercetools\Core\Model\Zone\Location;
10
use Commercetools\Core\Request\ShippingMethods\ShippingMethodCreateRequest;
11
use Commercetools\Core\Model\ShippingMethod\ShippingMethodDraft;
12
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteByKeyRequest;
13
use Commercetools\Core\Model\ShippingMethod\ShippingMethod;
14
use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteRequest;
15
use Commercetools\Core\Request\ShippingMethods\ShippingMethodQueryRequest;
16
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateByKeyRequest;
17
use Commercetools\Core\Request\ShippingMethods\ShippingMethodUpdateRequest;
18
19
class ShippingMethodRequestBuilder
20
{
21
22
    /**
23
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-a-cart
24
     * @param string $cartId
25
     * @return ShippingMethodByCartIdGetRequest
26
     */
27
    public function getByCartId($cartId)
28
    {
29
        $request = ShippingMethodByCartIdGetRequest::ofCartId($cartId);
30
        return $request;
31
    }
32
33
    /**
34
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethod-by-id
35
     * @param string $id
36
     * @return ShippingMethodByIdGetRequest
37
     */
38 1
    public function getById($id)
39
    {
40 1
        $request = ShippingMethodByIdGetRequest::ofId($id);
41 1
        return $request;
42
    }
43
44
    /**
45
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethod-by-key
46
     * @param string $key
47
     * @return ShippingMethodByKeyGetRequest
48
     */
49 1
    public function getByKey($key)
50
    {
51 1
        $request = ShippingMethodByKeyGetRequest::ofKey($key);
52 1
        return $request;
53
    }
54
55
    /**
56
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#get-shippingmethods-for-a-location
57
     * @param Location $location
58
     * @param string $currency
59
     * @return ShippingMethodByLocationGetRequest
60
     */
61
    public function getByLocation(Location $location, $currency = null)
62
    {
63
        $request = ShippingMethodByLocationGetRequest::ofCountry($location->getCountry());
64
        if (!is_null($location->getState())) {
0 ignored issues
show
The condition is_null($location->getState()) is always false.
Loading history...
65
            $request->withState($location->getState());
66
        }
67
        if (!is_null($currency)) {
68
            $request->withCurrency($currency);
69
        }
70
        return $request;
71
    }
72
73
    /**
74
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#create-shippingmethod
75
     * @param ShippingMethodDraft $shippingMethod
76
     * @return ShippingMethodCreateRequest
77
     */
78 1
    public function create(ShippingMethodDraft $shippingMethod)
79
    {
80 1
        $request = ShippingMethodCreateRequest::ofDraft($shippingMethod);
81 1
        return $request;
82
    }
83
84
    /**
85
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#delete-shippingmethod-by-key
86
     * @param ShippingMethod $shippingMethod
87
     * @return ShippingMethodDeleteByKeyRequest
88
     */
89 1
    public function deleteByKey(ShippingMethod $shippingMethod)
90
    {
91 1
        $request = ShippingMethodDeleteByKeyRequest::ofKeyAndVersion($shippingMethod->getKey(), $shippingMethod->getVersion());
92 1
        return $request;
93
    }
94
95
    /**
96
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#delete-shippingmethod
97
     * @param ShippingMethod $shippingMethod
98
     * @return ShippingMethodDeleteRequest
99
     */
100 1
    public function delete(ShippingMethod $shippingMethod)
101
    {
102 1
        $request = ShippingMethodDeleteRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion());
103 1
        return $request;
104
    }
105
106
    /**
107
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#query-shippingmethods
108
     *
109
     * @return ShippingMethodQueryRequest
110
     */
111 1
    public function query()
112
    {
113 1
        $request = ShippingMethodQueryRequest::of();
114 1
        return $request;
115
    }
116
117
    /**
118
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#update-shippingmethod-by-key
119
     * @param ShippingMethod $shippingMethod
120
     * @return ShippingMethodUpdateByKeyRequest
121
     */
122 1
    public function updateByKey(ShippingMethod $shippingMethod)
123
    {
124 1
        $request = ShippingMethodUpdateByKeyRequest::ofKeyAndVersion($shippingMethod->getKey(), $shippingMethod->getVersion());
125 1
        return $request;
126
    }
127
128
    /**
129
     * @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#update-shippingmethod
130
     * @param ShippingMethod $shippingMethod
131
     * @return ShippingMethodUpdateRequest
132
     */
133 1
    public function update(ShippingMethod $shippingMethod)
134
    {
135 1
        $request = ShippingMethodUpdateRequest::ofIdAndVersion($shippingMethod->getId(), $shippingMethod->getVersion());
136 1
        return $request;
137
    }
138
139
    /**
140
     * @return ShippingMethodRequestBuilder
141
     */
142
    public function of()
143
    {
144
        return new self();
145
    }
146
}
147