Test Failed
Pull Request — feature/families (#15)
by
unknown
02:37
created

UpdateOrderStatusRequest::setOrderId()   A

Complexity

Conditions 2
Paths 2

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