Test Failed
Pull Request — master (#46)
by Yuji
04:29
created

UpdateOrderStatusRequest::setOrderStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use FluidXml\FluidXml;
6
use LogicException;
7
use Shippinno\YahooShoppingJp\Api\UpdateOrderStatusApi;
8
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException;
9
use Shippinno\YahooShoppingJp\Enum\OrderStatus;
10
use Shippinno\YahooShoppingJp\Enum\CancelReason;
11
use Shippinno\YahooShoppingJp\Response\UpdateOrderStatusResponse;
12
13
class UpdateOrderStatusRequest extends AbstractRequest
14
{
15
16
    /**
17
     * @return UpdateOrderStatusApi
18
     */
19
    public function api()
20
    {
21
        return new UpdateOrderStatusApi;
22
    }
23
24
    /**
25
     * @return UpdateOrderStatusResponse
26
     */
27
    public function response()
28
    {
29
        return new UpdateOrderStatusResponse;
30
    }
31
32
    /**
33
     * @return void
34
     */
35
    protected function validateParams(): void
36
    {
37
        if (!isset($this->params['SellerId'])) {
38
            throw new InvalidRequestException;
39
        }
40
        if (!isset($this->params['Target']['OrderId'])) {
41
            throw new InvalidRequestException;
42
        }
43
        if (!isset($this->params['Target']['IsPointFix'])) {
44
            throw new InvalidRequestException;
45
        }
46
        if (!isset($this->params['Order']['OrderStatus'])) {
47
            throw new InvalidRequestException;
48
        }
49
        // ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
50
        if ($this->params['Order']['OrderStatus'] === OrderStatus::PROCESSED()->getValue() && $this->params['Target']['IsPointFix'] === 'false') {
51
            throw new InvalidRequestException;
52
        }
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getParams()
59
    {
60
        $this->validateParams();
61
62
        $fluidXml = new FluidXml('Req');
63
        $fluidXml->add($this->params);
64
65
        return $fluidXml->xml();
66
    }
67
68
    /**
69
     * 【必須】ストアアカウント
70
     *
71
     * @param string $sellerId
72
     * @return self
73
     */
74 View Code Duplication
    public function setSellerId(string $sellerId): self
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        if (isset($this->params['SellerId'])) {
77
            throw new LogicException('SellerId is already set.');
78
        }
79
80
        $this->params['SellerId'] = $sellerId;
81
82
        return $this;
83
    }
84
85
    /**
86
     * 【必須】注文ID
87
     *
88
     * @param string $orderId
89
     * @return self
90
     */
91
    public function setOrderId(string $orderId): self
92
    {
93
        if (isset($this->params['Target']['OrderId'])) {
94
            throw new LogicException('OrderId is already set.');
95
        }
96
97
        $this->params['Target']['OrderId'] = $orderId;
98
99
        return $this;
100
    }
101
102
    /**
103
     * 【必須】ポイント確定要否
104
     * true : ポイント確定します。
105
     * false : ポイント確定しません。
106
     * ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
107
     *
108
     * @param bool $isPointFix
109
     * @return self
110
     */
111
    public function setIsPointFix(bool $isPointFix): self
112
    {
113
        if (isset($this->params['Target']['IsPointFix'])) {
114
            throw new LogicException('IsPointFix is already set.');
115
        }
116
117
        $this->params['Target']['IsPointFix'] = ($isPointFix ? 'true' : 'false');
118
119
        return $this;
120
    }
121
122
    /**
123
     * 【必須】注文ステータス
124
     *
125
     * @param OrderStatus $orderStatus
126
     * @return self
127
     */
128
    public function setOrderStatus(OrderStatus $orderStatus): self
129
    {
130
        if (isset($this->params['Order']['OrderStatus'])) {
131
            throw new LogicException('OrderStatus is already set.');
132
        }
133
        $this->params['Order']['OrderStatus'] = $orderStatus->getValue();
134
135
        return $this;
136
    }
137
138
    /**
139
     * 更新者名(ビジネスID登録氏名)
140
     *
141
     * @param string $operationUser
142
     * @return self
143
     */
144
    public function setOperationUser(string $operationUser): self
145
    {
146
        if (isset($this->params['Target']['OperationUser'])) {
147
            throw new LogicException('OperationUser is already set.');
148
        }
149
150
        $this->params['Target']['OperationUser'] = $operationUser;
151
152
        return $this;
153
    }
154
155
    /**
156
     * キャンセル理由
157
     *
158
     * @param CancelReason $cancelReason
159
     * @return self
160
     */
161
    public function setCancelReason(CancelReason $cancelReason): self
162
    {
163
        if (isset($this->params['Order']['CancelReason'])) {
164
            throw new LogicException('CancelReason is already set.');
165
        }
166
167
        $this->params['Order']['CancelReason'] = $cancelReason->getValue();
168
169
        return $this;
170
    }
171
172
}
173