@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param array $query |
32 | 32 | * @return null|static |
33 | 33 | */ |
34 | - public static function load ($caller, string $id, array $query = []) { |
|
34 | + public static function load($caller, string $id, array $query = []) { |
|
35 | 35 | return self::_getApi($caller)->load($caller, static::class, self::DIR . '/' . $id, $query); |
36 | 36 | } |
37 | 37 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param array $query |
42 | 42 | * @return static[] |
43 | 43 | */ |
44 | - public static function loadAll ($caller, string $path, array $query = []) { |
|
44 | + public static function loadAll($caller, string $path, array $query = []) { |
|
45 | 45 | return self::_getApi($caller)->loadAll($caller, static::class, $path, $query); |
46 | 46 | } |
47 | 47 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * @return bool |
51 | 51 | * @internal pool |
52 | 52 | */ |
53 | - final public function __merge (self $entity): bool { |
|
53 | + final public function __merge(self $entity): bool { |
|
54 | 54 | return false; // todo |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - public function __toString (): string { |
|
60 | + public function __toString(): string { |
|
61 | 61 | $path = static::DIR . '/' . $this->getId(); |
62 | 62 | if ($container = $this->_container()) { |
63 | 63 | return "{$container}/{$path}"; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return null|AbstractEntity |
72 | 72 | */ |
73 | - protected function _container () { |
|
73 | + protected function _container() { |
|
74 | 74 | return null; |
75 | 75 | } |
76 | 76 | |
@@ -80,25 +80,25 @@ discard block |
||
80 | 80 | * @param string $field |
81 | 81 | * @return mixed |
82 | 82 | */ |
83 | - protected function _get (string $field) { |
|
83 | + protected function _get(string $field) { |
|
84 | 84 | if (!array_key_exists($field, $this->data) and $this->hasId()) { |
85 | 85 | $this->_reload($field); |
86 | 86 | } |
87 | 87 | return parent::_get($field); |
88 | 88 | } |
89 | 89 | |
90 | - protected function _onDelete (): void { |
|
90 | + protected function _onDelete(): void { |
|
91 | 91 | $this->pool->remove(...$this->getPoolKeys()); |
92 | 92 | } |
93 | 93 | |
94 | - protected function _onSave (): void { |
|
94 | + protected function _onSave(): void { |
|
95 | 95 | $this->pool->add($this); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @param string $field |
100 | 100 | */ |
101 | - protected function _reload (string $field): void { |
|
101 | + protected function _reload(string $field): void { |
|
102 | 102 | assert($this->hasId()); |
103 | 103 | $remote = $this->api->get($this, ['fields' => $field]); |
104 | 104 | $this->_setField($field, $remote[static::TYPE][$field]); |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * @return null|string |
110 | 110 | */ |
111 | - final public function getId (): ?string { |
|
111 | + final public function getId(): ?string { |
|
112 | 112 | return $this->data['id'] ?? null; |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return string[] |
117 | 117 | */ |
118 | - public function getPoolKeys () { |
|
118 | + public function getPoolKeys() { |
|
119 | 119 | return [$this->getId(), (string)$this]; |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @return bool |
124 | 124 | */ |
125 | - final public function hasId (): bool { |
|
125 | + final public function hasId(): bool { |
|
126 | 126 | return isset($this->data['id']); |
127 | 127 | } |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return $this |
133 | 133 | */ |
134 | - public function reload () { |
|
134 | + public function reload() { |
|
135 | 135 | assert($this->hasId()); |
136 | 136 | $remote = $this->api->get($this); |
137 | 137 | if (!isset($remote[static::TYPE]['id'])) { // deleted? |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - protected function _metafieldType (): string { |
|
20 | + protected function _metafieldType(): string { |
|
21 | 21 | return static::TYPE; |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @return Metafield[] |
26 | 26 | */ |
27 | - public function getMetafields () { |
|
27 | + public function getMetafields() { |
|
28 | 28 | assert($this->hasId()); |
29 | 29 | // the endpoints are all over the place. |
30 | 30 | // querying the main directory works for all entities. |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return Metafield |
44 | 44 | */ |
45 | - public function newMetafield () { |
|
45 | + public function newMetafield() { |
|
46 | 46 | assert($this->hasId()); |
47 | 47 | /** @var AbstractEntity $that */ |
48 | 48 | $that = $this; |
@@ -9,7 +9,7 @@ |
||
9 | 9 | */ |
10 | 10 | trait DeleteTrait { |
11 | 11 | |
12 | - public function delete (): void { |
|
12 | + public function delete(): void { |
|
13 | 13 | assert($this->hasId()); |
14 | 14 | $this->api->delete($this); |
15 | 15 | $this->_onDelete(); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - protected function _dir (): string { |
|
17 | + protected function _dir(): string { |
|
18 | 18 | if ($container = $this->_container()) { |
19 | 19 | assert($container->hasId()); |
20 | 20 | return "{$container}/" . static::DIR; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return $this |
27 | 27 | */ |
28 | - public function create () { |
|
28 | + public function create() { |
|
29 | 29 | assert(!$this->hasId()); |
30 | 30 | $remote = $this->api->post($this->_dir(), [static::TYPE => $this->toArray()]); |
31 | 31 | $this->_setData($remote[static::TYPE]); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | /** |
13 | 13 | * @return $this |
14 | 14 | */ |
15 | - public function update () { |
|
15 | + public function update() { |
|
16 | 16 | assert($this->hasId()); |
17 | 17 | if ($this->isDiff()) { |
18 | 18 | $remote = $this->api->put($this, [static::TYPE => $this->toDiff()]); |
@@ -61,33 +61,33 @@ discard block |
||
61 | 61 | */ |
62 | 62 | protected $order; |
63 | 63 | |
64 | - public function __construct (Order $order, array $data = []) { |
|
64 | + public function __construct(Order $order, array $data = []) { |
|
65 | 65 | $this->order = $order; |
66 | 66 | parent::__construct($order, $data); |
67 | 67 | } |
68 | 68 | |
69 | - protected function _container () { |
|
69 | + protected function _container() { |
|
70 | 70 | return $this->order; |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @return Order |
75 | 75 | */ |
76 | - public function getOrder () { |
|
76 | + public function getOrder() { |
|
77 | 77 | return Order::load($this, $this->order->getId()); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @return RefundItem |
82 | 82 | */ |
83 | - public function newItem () { |
|
83 | + public function newItem() { |
|
84 | 84 | return $this->api->factory($this, RefundItem::class); |
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | 88 | * @return Transaction |
89 | 89 | */ |
90 | - public function newTransaction () { |
|
90 | + public function newTransaction() { |
|
91 | 91 | return $this->api->factory($this, Transaction::class, [ |
92 | 92 | 'kind' => Transaction::KIND_REFUND |
93 | 93 | ]); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @depends create-only |
98 | 98 | * @return $this |
99 | 99 | */ |
100 | - public function setFullShipping () { |
|
100 | + public function setFullShipping() { |
|
101 | 101 | return $this->_set('shipping', ['full_refund' => true]); |
102 | 102 | } |
103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param string $amount |
107 | 107 | * @return $this |
108 | 108 | */ |
109 | - public function setShippingAmount (string $amount) { |
|
109 | + public function setShippingAmount(string $amount) { |
|
110 | 110 | return $this->_set('shipping', ['amount' => $amount]); |
111 | 111 | } |
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | const SHIPMENT_COMPLETE = 'delivered'; |
62 | 62 | const SHIPMENT_FAILURE = 'failure'; |
63 | 63 | |
64 | - protected function _container () { |
|
64 | + protected function _container() { |
|
65 | 65 | return $this->getOrder(); |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return $this |
70 | 70 | */ |
71 | - public function cancel () { |
|
71 | + public function cancel() { |
|
72 | 72 | assert($this->hasId()); |
73 | 73 | $remote = $this->api->post("{$this}/cancel", []); |
74 | 74 | return $this->_setData($remote[self::TYPE]); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @return $this |
79 | 79 | */ |
80 | - public function complete () { |
|
80 | + public function complete() { |
|
81 | 81 | assert($this->hasId()); |
82 | 82 | $remote = $this->api->post("{$this}/complete", []); |
83 | 83 | return $this->_setData($remote[self::TYPE]); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @return Order |
88 | 88 | */ |
89 | - public function getOrder () { |
|
89 | + public function getOrder() { |
|
90 | 90 | return Order::load($this, $this->getOrderId()); |
91 | 91 | } |
92 | 92 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param string $orderItemId |
95 | 95 | * @return OrderItem |
96 | 96 | */ |
97 | - public function newItem (string $orderItemId) { |
|
97 | + public function newItem(string $orderItemId) { |
|
98 | 98 | return $this->api->factory($this, OrderItem::class, [ |
99 | 99 | 'id' => $orderItemId |
100 | 100 | ]); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @return $this |
105 | 105 | */ |
106 | - public function open () { |
|
106 | + public function open() { |
|
107 | 107 | assert($this->hasId()); |
108 | 108 | $remote = $this->api->post("{$this}/open", []); |
109 | 109 | return $this->_setData($remote[self::TYPE]); |
@@ -58,11 +58,11 @@ |
||
58 | 58 | const KIND_SALE = 'sale'; |
59 | 59 | const KIND_VOID = 'void'; |
60 | 60 | |
61 | - protected function _container () { |
|
61 | + protected function _container() { |
|
62 | 62 | return $this->getOrder(); |
63 | 63 | } |
64 | 64 | |
65 | - public function getOrder () { |
|
65 | + public function getOrder() { |
|
66 | 66 | return Order::load($this, $this->getOrderId()); |
67 | 67 | } |
68 | 68 | } |
69 | 69 | \ No newline at end of file |
@@ -60,21 +60,21 @@ |
||
60 | 60 | /** |
61 | 61 | * @return Customer |
62 | 62 | */ |
63 | - public function getCustomer () { |
|
63 | + public function getCustomer() { |
|
64 | 64 | return Customer::load($this, $this->getCustomerId()); |
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @return Order |
69 | 69 | */ |
70 | - public function getOrder () { |
|
70 | + public function getOrder() { |
|
71 | 71 | return Order::load($this, $this->getOrderId()); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @return User |
76 | 76 | */ |
77 | - public function getUser () { |
|
77 | + public function getUser() { |
|
78 | 78 | return User::load($this, $this->getUserId()); |
79 | 79 | } |
80 | 80 |