Test Failed
Pull Request — develop (#32)
by Yuji
11:42
created

UpdateOrderStatusRequest::setIsPointFix()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use LogicException;
6
use Shippinno\YahooShoppingJp\Api\AbstractApi;
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 FluidXml\FluidXml;
12
use Shippinno\YahooShoppingJp\Response\AbstractResponse;
13
use Shippinno\YahooShoppingJp\Response\UpdateOrderStatusResponse;
14
15
class UpdateOrderStatusRequest extends AbstractRequest
16
{
17
    /**
18
     * @var array
19
     */
20
    private $params = [];
21
22
    /**
23
     * @return AbstractApi
24
     */
25
    public function api()
26
    {
27
        return new UpdateOrderStatusApi;
28
    }
29
30
    /**
31
     * @return AbstractResponse
32
     */
33
    public function response()
34
    {
35
        new UpdateOrderStatusResponse;
36
    }
37
38
    /**
39
     * 【必須】ストアアカウント
40
     *
41
     * @param string $sellerId
42
     * @return self
43
     */
44 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...
45
    {
46
        if (isset($this->params['SellerId'])) {
47
            throw new LogicException('SellerId is already set.');
48
        }
49
50
        $this->params['SellerId'] = $sellerId;
51
52
        return $this;
53
    }
54
55
    /**
56
     * 【必須】注文ID
57
     *
58
     * @param string $orderId
59
     * @return self
60
     */
61 View Code Duplication
    public function setOrderId(string $orderId): 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...
62
    {
63
        if (isset($this->params['Target']['OrderId'])) {
64
            throw new LogicException('OrderId is already set.');
65
        }
66
67
        $this->params['Target']['OrderId'] = $orderId;
68
69
        return $this;
70
    }
71
72
    /**
73
     * 【必須】ポイント確定要否
74
     * true : ポイント確定します。
75
     * false : ポイント確定しません。
76
     * ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
77
     *
78
     * @param bool $isPointFix
79
     * @return self
80
     */
81 View Code Duplication
    public function setIsPointFix(bool $isPointFix): 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...
82
    {
83
        if (isset($this->params['Target']['IsPointFix'])) {
84
            throw new LogicException('IsPointFix is already set.');
85
        }
86
87
        $this->params['Target']['IsPointFix'] = ($isPointFix ? 'true' : 'false');
88
89
        return $this;
90
    }
91
92
    /**
93
     * 【必須】注文ステータス
94
     *
95
     * @param OrderStatus $orderStatus
96
     * @return self
97
     */
98 View Code Duplication
    public function setOrderStatus(OrderStatus $orderStatus): 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...
99
    {
100
        if (isset($this->params['Order']['OrderStatus'])) {
101
            throw new LogicException('OrderStatus is already set.');
102
        }
103
        $this->params['Order']['OrderStatus'] = $orderStatus->getValue();
104
105
        return $this;
106
    }
107
108
    /**
109
     * 更新者名(ビジネスID登録氏名)
110
     *
111
     * @param string $operationUser
112
     * @return self
113
     */
114 View Code Duplication
    public function setOperationUser(string $operationUser): 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...
115
    {
116
        if (isset($this->params['Target']['OperationUser'])) {
117
            throw new LogicException('OperationUser is already set.');
118
        }
119
120
        $this->params['Target']['OperationUser'] = $operationUser;
121
122
        return $this;
123
    }
124
125
    /**
126
     * キャンセル理由
127
     *
128
     * @param CancelReason $cancelReason
129
     * @return self
130
     */
131 View Code Duplication
    public function setCancelReason(CancelReason $cancelReason): 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...
132
    {
133
        if (isset($this->params['Order']['CancelReason'])) {
134
            throw new LogicException('CancelReason is already set.');
135
        }
136
137
        $this->params['Order']['CancelReason'] = $cancelReason->getValue();
138
139
        return $this;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getParams()
146
    {
147
        $this->validateRequest();
148
149
        $fluidXml = new FluidXml('Req');
150
        $fluidXml->add($this->params);
151
152
        return $fluidXml->xml();
153
    }
154
155
    /**
156
     * @throws InvalidRequestException
157
     */
158
    private function validateRequest(): void
159
    {
160
        if (!isset($this->params['SellerId'])) {
161
            throw new InvalidRequestException;
162
        }
163
        if (!isset($this->params['Target']['OrderId'])) {
164
            throw new InvalidRequestException;
165
        }
166
        if (!isset($this->params['Target']['IsPointFix'])) {
167
            throw new InvalidRequestException;
168
        }
169
        if (!isset($this->params['Order']['OrderStatus'])) {
170
            throw new InvalidRequestException;
171
        }
172
        // ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
173
        if ($this->params['Order']['OrderStatus'] === OrderStatus::PROCESSED()->getValue() && $this->params['Target']['IsPointFix'] === 'false') {
174
            throw new InvalidRequestException;
175
        }
176
    }
177
178
179
180
    /**
181
     * @return void
182
     */
183
    protected function validateParams()
184
    {
185
    }
186
}
187