@@ -23,12 +23,12 @@ |
||
23 | 23 | */ |
24 | 24 | protected $customer; |
25 | 25 | |
26 | - public function __construct (Customer $customer) { |
|
26 | + public function __construct(Customer $customer) { |
|
27 | 27 | $this->customer = $customer; |
28 | 28 | parent::__construct($customer); |
29 | 29 | } |
30 | 30 | |
31 | - public function send (): void { |
|
31 | + public function send(): void { |
|
32 | 32 | $this->api->post("{$this->customer}/send_invite", ['customer_invite' => $this->getData()]); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | protected $assets; |
36 | 36 | |
37 | - final protected static function getType (): string { |
|
37 | + final protected static function getType(): string { |
|
38 | 38 | return 'theme'; |
39 | 39 | } |
40 | 40 | |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | * @param Api $api |
43 | 43 | * @return Theme[] |
44 | 44 | */ |
45 | - public static function loadAll (Api $api) { |
|
45 | + public static function loadAll(Api $api) { |
|
46 | 46 | return static::toList(new static($api), $api->get('themes')['themes']); |
47 | 47 | } |
48 | 48 | |
49 | - final public function __toString (): string { |
|
49 | + final public function __toString(): string { |
|
50 | 50 | return "themes/{$this->getId()}"; |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return Asset[] |
55 | 55 | */ |
56 | - public function getAssets () { |
|
56 | + public function getAssets() { |
|
57 | 57 | if (!isset($this->assets)) { |
58 | 58 | /** |
59 | 59 | * Asset values are not returned by Shopify for this query. |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | return $this->assets->getItems(); |
70 | 70 | } |
71 | 71 | |
72 | - final protected function getDir (): string { |
|
72 | + final protected function getDir(): string { |
|
73 | 73 | return 'themes'; |
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @return Asset |
78 | 78 | */ |
79 | - public function newAsset () { |
|
79 | + public function newAsset() { |
|
80 | 80 | $this->getAssets(); |
81 | 81 | return $this->assets->add(Asset::toData($this, ['theme_id' => $this->getId()])); |
82 | 82 | } |
@@ -61,34 +61,34 @@ discard block |
||
61 | 61 | 'variants' => [Variant::class, 'toDataSet'] |
62 | 62 | ]; |
63 | 63 | |
64 | - final protected static function getMetafieldType (): string { |
|
64 | + final protected static function getMetafieldType(): string { |
|
65 | 65 | return 'product'; |
66 | 66 | } |
67 | 67 | |
68 | - final protected static function getSearchPath (): string { |
|
68 | + final protected static function getSearchPath(): string { |
|
69 | 69 | return 'products'; |
70 | 70 | } |
71 | 71 | |
72 | - final protected static function getSearchType (): string { |
|
72 | + final protected static function getSearchType(): string { |
|
73 | 73 | return 'products'; |
74 | 74 | } |
75 | 75 | |
76 | - final protected static function getType (): string { |
|
76 | + final protected static function getType(): string { |
|
77 | 77 | return 'product'; |
78 | 78 | } |
79 | 79 | |
80 | - final public function __toString (): string { |
|
80 | + final public function __toString(): string { |
|
81 | 81 | return "products/{$this->getId()}"; |
82 | 82 | } |
83 | 83 | |
84 | - final protected function getDir (): string { |
|
84 | + final protected function getDir(): string { |
|
85 | 85 | return 'products'; |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return Image |
90 | 90 | */ |
91 | - public function newImage () { |
|
91 | + public function newImage() { |
|
92 | 92 | return $this->data['images']->add(Image::toData($this, ['product_id' => $this->getId()])); |
93 | 93 | } |
94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string[] $values |
98 | 98 | * @return Option |
99 | 99 | */ |
100 | - public function newOption (string $name, array $values) { |
|
100 | + public function newOption(string $name, array $values) { |
|
101 | 101 | $option = Option::toData($this, ['product_id' => $this->getId()]); |
102 | 102 | $option->setName($name)->setValues($values); |
103 | 103 | return $this->data['options']->add($option); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * @return Variant |
108 | 108 | */ |
109 | - public function newVariant () { |
|
109 | + public function newVariant() { |
|
110 | 110 | return $this->data['variants']->add(Variant::toData($this, ['product_id' => $this->getId()])); |
111 | 111 | } |
112 | 112 |
@@ -21,23 +21,23 @@ |
||
21 | 21 | |
22 | 22 | use SearchTrait; |
23 | 23 | |
24 | - final protected static function getSearchPath (): string { |
|
24 | + final protected static function getSearchPath(): string { |
|
25 | 25 | return 'reports'; |
26 | 26 | } |
27 | 27 | |
28 | - final protected static function getSearchType (): string { |
|
28 | + final protected static function getSearchType(): string { |
|
29 | 29 | return 'reports'; |
30 | 30 | } |
31 | 31 | |
32 | - final protected static function getType (): string { |
|
32 | + final protected static function getType(): string { |
|
33 | 33 | return 'report'; |
34 | 34 | } |
35 | 35 | |
36 | - final public function __toString (): string { |
|
36 | + final public function __toString(): string { |
|
37 | 37 | return "reports/{$this->getId()}"; |
38 | 38 | } |
39 | 39 | |
40 | - final protected function getDir (): string { |
|
40 | + final protected function getDir(): string { |
|
41 | 41 | return 'reports'; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - abstract protected static function getType (): string; |
|
24 | + abstract protected static function getType(): string; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * The entity's unique path for GET/PUT/DELETE. |
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - abstract public function __toString (): string; |
|
31 | + abstract public function __toString(): string; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @var Api |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param mixed ...$extra Other arguments needed by the constructor. |
42 | 42 | * @return null|static |
43 | 43 | */ |
44 | - public static function load (Api $api, array $data, ...$extra) { |
|
44 | + public static function load(Api $api, array $data, ...$extra) { |
|
45 | 45 | $class = static::class; |
46 | 46 | /** @var Data $proto */ |
47 | 47 | $proto = new $class($api, $data, ...$extra); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | return null; |
54 | 54 | } |
55 | 55 | |
56 | - public function delete (): void { |
|
56 | + public function delete(): void { |
|
57 | 57 | /** @var Data $this */ |
58 | 58 | $this->api->delete($this); |
59 | 59 | $this->notify('delete'); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - abstract protected function getDir (): string; |
|
20 | + abstract protected function getDir(): string; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var bool |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return $this |
38 | 38 | */ |
39 | - public function save () { |
|
39 | + public function save() { |
|
40 | 40 | if ($this->isDiff()) { |
41 | 41 | $type = static::getType(); |
42 | 42 | if (!$this->hasId()) { |
@@ -41,8 +41,7 @@ |
||
41 | 41 | $type = static::getType(); |
42 | 42 | if (!$this->hasId()) { |
43 | 43 | $remote = $this->api->post($this->getDir(), [$type => $this->getPatch()]); |
44 | - } |
|
45 | - else { |
|
44 | + } else { |
|
46 | 45 | assert($this->canUpdate); |
47 | 46 | $remote = $this->api->put($this, [$type => $this->getPatch()]); |
48 | 47 | } |
@@ -13,21 +13,21 @@ |
||
13 | 13 | * @param array $query |
14 | 14 | * @return string |
15 | 15 | */ |
16 | - abstract protected static function getSearchPath (array $query): string; |
|
16 | + abstract protected static function getSearchPath(array $query): string; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The pluralized key that results are wrapped in. |
20 | 20 | * |
21 | 21 | * @return string |
22 | 22 | */ |
23 | - abstract protected static function getSearchType (): string; |
|
23 | + abstract protected static function getSearchType(): string; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @param Api $api |
27 | 27 | * @param array $query |
28 | 28 | * @return Traversable|static[] |
29 | 29 | */ |
30 | - public static function search (Api $api, array $query) { |
|
30 | + public static function search(Api $api, array $query) { |
|
31 | 31 | $continue = !isset($query['limit']); |
32 | 32 | $query += ['limit' => 250]; |
33 | 33 | $class = static::class; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @param Data[] $items |
33 | 33 | */ |
34 | - public function __construct (array $items = []) { |
|
34 | + public function __construct(array $items = []) { |
|
35 | 35 | foreach ($items as $item) { |
36 | 36 | $this->add($item); |
37 | 37 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param Data $item |
45 | 45 | * @return Data|mixed |
46 | 46 | */ |
47 | - public function add (Data $item) { |
|
47 | + public function add(Data $item) { |
|
48 | 48 | $key = spl_object_hash($item); |
49 | 49 | $this->items[$key] = $item; |
50 | 50 | $this->diff[$key] = $item; |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return $this |
70 | 70 | */ |
71 | - public function clear () { |
|
71 | + public function clear() { |
|
72 | 72 | $this->items = []; |
73 | 73 | $this->diff = []; |
74 | 74 | return $this; |
75 | 75 | } |
76 | 76 | |
77 | - public function count () { |
|
77 | + public function count() { |
|
78 | 78 | return count($this->items); |
79 | 79 | } |
80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param Closure $keep |
85 | 85 | * @return $this |
86 | 86 | */ |
87 | - public function filter (Closure $keep) { |
|
87 | + public function filter(Closure $keep) { |
|
88 | 88 | $oldItems = $this->items; |
89 | 89 | $this->items = array_filter($this->items, $keep); |
90 | 90 | $this->diff += array_diff_key($oldItems, $this->items); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param Closure $selector |
96 | 96 | * @return null|Data |
97 | 97 | */ |
98 | - public function first (Closure $selector) { |
|
98 | + public function first(Closure $selector) { |
|
99 | 99 | foreach ($this->items as $item) { |
100 | 100 | if ($selector->__invoke($item)) { |
101 | 101 | return $item; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return null; |
105 | 105 | } |
106 | 106 | |
107 | - final public function getData (): array { |
|
107 | + final public function getData(): array { |
|
108 | 108 | return array_map(function(Data $item) { |
109 | 109 | return $item->getData(); |
110 | 110 | }, $this->getItems()); |
@@ -113,24 +113,24 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * @return Data[] |
115 | 115 | */ |
116 | - final public function getItems (): array { |
|
116 | + final public function getItems(): array { |
|
117 | 117 | return array_values($this->items); |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return Traversable|Data[] |
122 | 122 | */ |
123 | - final public function getIterator () { |
|
123 | + final public function getIterator() { |
|
124 | 124 | yield from $this->getItems(); |
125 | 125 | } |
126 | 126 | |
127 | - protected function getPatch (): array { |
|
127 | + protected function getPatch(): array { |
|
128 | 128 | return array_map(function(Data $item) { |
129 | 129 | return $item->getPatch(); |
130 | 130 | }, $this->getItems()); |
131 | 131 | } |
132 | 132 | |
133 | - protected function isDiff (): bool { |
|
133 | + protected function isDiff(): bool { |
|
134 | 134 | if ($this->diff) { |
135 | 135 | return true; |
136 | 136 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return $this |
149 | 149 | */ |
150 | - public function save () { |
|
150 | + public function save() { |
|
151 | 151 | foreach ($this->items as $item) { |
152 | 152 | assert($item instanceof EntityInterface); |
153 | 153 | $item->save(); // onSave() clears the diff for the item. |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param Closure $selector |
166 | 166 | * @return Data[] |
167 | 167 | */ |
168 | - public function select (Closure $selector) { |
|
168 | + public function select(Closure $selector) { |
|
169 | 169 | return array_filter($this->items, $selector); |
170 | 170 | } |
171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @param Closure $cmp |
174 | 174 | * @return $this |
175 | 175 | */ |
176 | - public function sort (Closure $cmp) { |
|
176 | + public function sort(Closure $cmp) { |
|
177 | 177 | $oldKeys = array_keys($this->items); |
178 | 178 | uasort($this->items, $cmp); |
179 | 179 | $newKeys = array_keys($this->items); |
@@ -128,8 +128,7 @@ |
||
128 | 128 | public function __construct ($caller, array $data = []) { |
129 | 129 | if ($caller instanceof Api) { |
130 | 130 | $this->api = $caller; |
131 | - } |
|
132 | - elseif ($caller instanceof Data) { |
|
131 | + } elseif ($caller instanceof Data) { |
|
133 | 132 | $this->api = $caller->api; |
134 | 133 | } |
135 | 134 | $this->import($data); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param null|array $data |
83 | 83 | * @return null|static|mixed |
84 | 84 | */ |
85 | - protected static function toData ($caller, ?array $data) { |
|
85 | + protected static function toData($caller, ?array $data) { |
|
86 | 86 | return isset($data) ? new static($caller, $data) : null; |
87 | 87 | } |
88 | 88 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param null|array $table |
94 | 94 | * @return DataSet |
95 | 95 | */ |
96 | - protected static function toDataSet ($caller, array $table = null) { |
|
96 | + protected static function toDataSet($caller, array $table = null) { |
|
97 | 97 | return new DataSet(static::toList($caller, $table)); |
98 | 98 | } |
99 | 99 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param null|array[] $table |
105 | 105 | * @return Hash |
106 | 106 | */ |
107 | - protected static function toHash ($caller, array $table = null) { |
|
107 | + protected static function toHash($caller, array $table = null) { |
|
108 | 108 | unset($caller); |
109 | 109 | return new Hash($table ?? []); |
110 | 110 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @param null|array[] $table |
117 | 117 | * @return array|static[] |
118 | 118 | */ |
119 | - protected static function toList ($caller, array $table = null) { |
|
119 | + protected static function toList($caller, array $table = null) { |
|
120 | 120 | return array_map(function(array $row) use ($caller) { |
121 | 121 | return static::toData($caller, $row); |
122 | 122 | }, $table ?? []); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param Api|Data $caller |
127 | 127 | * @param array $data |
128 | 128 | */ |
129 | - public function __construct ($caller, array $data = []) { |
|
129 | + public function __construct($caller, array $data = []) { |
|
130 | 130 | if ($caller instanceof Api) { |
131 | 131 | $this->api = $caller; |
132 | 132 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param array $args |
142 | 142 | * @return mixed |
143 | 143 | */ |
144 | - public function __call (string $method, array $args) { |
|
144 | + public function __call(string $method, array $args) { |
|
145 | 145 | static $cache = []; |
146 | - if (!$call =& $cache[$method]) { |
|
146 | + if (!$call = & $cache[$method]) { |
|
147 | 147 | preg_match('/^(filter|get|has|is|on|select|set|sort)(.+)$/', $method, $call); |
148 | 148 | $call[2] = preg_replace_callback('/[A-Z]/', function(array $match) { |
149 | 149 | return '_' . strtolower($match[0]); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param array $data |
157 | 157 | * @return $this |
158 | 158 | */ |
159 | - protected function apply (array $data) { |
|
159 | + protected function apply(array $data) { |
|
160 | 160 | $this->data = $data + $this->data; |
161 | 161 | $this->diff += array_fill_keys(array_keys($data), true); |
162 | 162 | return $this; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $key |
167 | 167 | * @return bool |
168 | 168 | */ |
169 | - final protected function exists (string $key): bool { |
|
169 | + final protected function exists(string $key): bool { |
|
170 | 170 | return array_key_exists($key, $this->data); |
171 | 171 | } |
172 | 172 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param callable $filter |
180 | 180 | * @return $this |
181 | 181 | */ |
182 | - protected function filter (string $key, callable $filter) { |
|
182 | + protected function filter(string $key, callable $filter) { |
|
183 | 183 | assert($this->data[$key] instanceof DataSet); |
184 | 184 | $this->data[$key]->filter($filter); |
185 | 185 | return $this; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param null $default |
196 | 196 | * @return mixed |
197 | 197 | */ |
198 | - protected function get (string $key, $default = null) { |
|
198 | + protected function get(string $key, $default = null) { |
|
199 | 199 | $value = $this->data[$key] ?? $default; |
200 | 200 | return $value instanceof DataSet ? $value->getItems() : $value; |
201 | 201 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | /** |
204 | 204 | * @return array |
205 | 205 | */ |
206 | - public function getData (): array { |
|
206 | + public function getData(): array { |
|
207 | 207 | $data = array_map(function($value) { |
208 | 208 | if ($value instanceof AbstractData) { |
209 | 209 | return $value->getData(); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * @return array |
219 | 219 | */ |
220 | - protected function getPatch (): array { |
|
220 | + protected function getPatch(): array { |
|
221 | 221 | $patch = []; |
222 | 222 | foreach ($this->data as $key => $value) { |
223 | 223 | // mapped structures |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param string $key |
248 | 248 | * @return bool |
249 | 249 | */ |
250 | - protected function has (string $key) { |
|
250 | + protected function has(string $key) { |
|
251 | 251 | $value = $this->data[$key] ?? null; |
252 | 252 | if (isset($value)) { |
253 | 253 | if (is_countable($value)) { |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param array $data |
265 | 265 | * @return $this |
266 | 266 | */ |
267 | - protected function import (array $data) { |
|
267 | + protected function import(array $data) { |
|
268 | 268 | foreach ($this->map as $key => $callable) { |
269 | 269 | $data[$key] = call_user_func($callable, $this, $data[$key] ?? null); |
270 | 270 | } |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | * @param string $key |
285 | 285 | * @return bool |
286 | 286 | */ |
287 | - protected function is (string $key): bool { |
|
287 | + protected function is(string $key): bool { |
|
288 | 288 | return !empty($this->data[$key]); |
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * @return bool |
293 | 293 | */ |
294 | - protected function isDiff (): bool { |
|
294 | + protected function isDiff(): bool { |
|
295 | 295 | if ($this->diff) { |
296 | 296 | return true; |
297 | 297 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param mixed ...$args |
318 | 318 | * @return $this |
319 | 319 | */ |
320 | - protected function notify (string $event, ...$args) { |
|
320 | + protected function notify(string $event, ...$args) { |
|
321 | 321 | $args[] = $this; |
322 | 322 | if (in_array($event, $this->_events)) { |
323 | 323 | throw new LogicException('Circular event: ' . implode(' -> ', $this->_events) . " -> **{$event}**"); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param Closure $observer |
346 | 346 | * @return $this |
347 | 347 | */ |
348 | - protected function on (string $event, Closure $observer) { |
|
348 | + protected function on(string $event, Closure $observer) { |
|
349 | 349 | $this->_observers[$event][] = $observer; |
350 | 350 | return $this; |
351 | 351 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @param Closure $selector |
360 | 360 | * @return Data[] |
361 | 361 | */ |
362 | - protected function select (string $key, Closure $selector) { |
|
362 | + protected function select(string $key, Closure $selector) { |
|
363 | 363 | assert($this->data[$key] instanceof DataSet); |
364 | 364 | return $this->data[$key]->select($selector); |
365 | 365 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @param mixed $value |
374 | 374 | * @return $this |
375 | 375 | */ |
376 | - protected function set (string $key, $value) { |
|
376 | + protected function set(string $key, $value) { |
|
377 | 377 | $this->data[$key] = is_array($value) ? array_values($value) : $value; |
378 | 378 | $this->diff[$key] = true; |
379 | 379 | return $this; |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * @param Closure $cmp |
389 | 389 | * @return $this |
390 | 390 | */ |
391 | - protected function sort (string $key, Closure $cmp) { |
|
391 | + protected function sort(string $key, Closure $cmp) { |
|
392 | 392 | $dataSet = $this->data[$key]; |
393 | 393 | assert($dataSet instanceof DataSet); |
394 | 394 | $dataSet->sort($cmp); |