1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shippinno\YahooShoppingJp\Request; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use LogicException; |
7
|
|
|
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException; |
8
|
|
|
|
9
|
|
|
class GetItemStockInfoRequest extends AbstractRequest |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $params = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param string $sellerId |
18
|
|
|
* @return self |
19
|
|
|
*/ |
20
|
|
|
public function setSellerId(string $sellerId): self |
21
|
|
|
{ |
22
|
|
|
if (isset($this->params['seller_id'])) { |
23
|
|
|
throw new LogicException('seller_id is already set.'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$this->params['seller_id'] = $sellerId; |
27
|
|
|
|
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $itemCode |
33
|
|
|
* @return self |
34
|
|
|
*/ |
35
|
|
|
public function addItemCode(string $itemCode): self |
36
|
|
|
{ |
37
|
|
|
if (strlen($itemCode) === 0) { |
38
|
|
|
throw new InvalidArgumentException('The item_code cannot be empty.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (strlen($itemCode) > 99) { |
42
|
|
|
throw new InvalidArgumentException('The item_code must be less than 99 characters.'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->params['itemCodeList'][] = $itemCode; |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function getParams(): array |
54
|
|
|
{ |
55
|
|
|
$this->validateRequest(); |
56
|
|
|
|
57
|
|
|
$this->params['item_code'] = implode(',', $this->params['itemCodeList']); |
58
|
|
|
|
59
|
|
|
return $this->params; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @throws InvalidRequestException |
64
|
|
|
*/ |
65
|
|
|
private function validateRequest(): void |
66
|
|
|
{ |
67
|
|
|
if (! isset($this->params['seller_id'])) { |
68
|
|
|
throw new InvalidRequestException; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (count(array_unique($this->params['itemCodeList'])) < count($this->params['itemCodeList'])) { |
72
|
|
|
throw new LogicException('Some of item_code are duplicated.'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (count($this->params['itemCodeList']) >= 1000) { |
76
|
|
|
throw new LogicException('The number of the item_code must be less than 1000.'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|