We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | return $this->getPath().$fileName; |
24 | 24 | } |
25 | 25 | |
26 | - if (! $value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) { |
|
26 | + if (!$value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) { |
|
27 | 27 | Storage::disk($this->getDisk())->delete($previousFile); |
28 | 28 | |
29 | 29 | return null; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | foreach ($previousRepeatableValues as $row => $file) { |
50 | - if ($file && ! isset($orderedFiles[$row])) { |
|
50 | + if ($file && !isset($orderedFiles[$row])) { |
|
51 | 51 | $orderedFiles[$row] = null; |
52 | 52 | Storage::disk($this->getDisk())->delete($file); |
53 | 53 | } |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | private string $crudObjectType; |
15 | 15 | |
16 | 16 | public function __construct( |
17 | - private readonly CrudField|CrudColumn $crudObject, |
|
17 | + private readonly CrudField | CrudColumn $crudObject, |
|
18 | 18 | private readonly array $uploaderConfiguration, |
19 | 19 | private readonly string $macro |
20 | 20 | ) { |
21 | 21 | $this->crudObjectType = is_a($crudObject, CrudField::class) ? 'field' : (is_a($crudObject, CrudColumn::class) ? 'column' : null); |
22 | 22 | |
23 | - if (! $this->crudObjectType) { |
|
23 | + if (!$this->crudObjectType) { |
|
24 | 24 | abort(500, 'Upload handlers only work for CrudField and CrudColumn classes.'); |
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
28 | - public static function handle(CrudField|CrudColumn $crudObject, array $uploaderConfiguration, string $macro, ?array $subfield = null, ?bool $registerModelEvents = true): void |
|
28 | + public static function handle(CrudField | CrudColumn $crudObject, array $uploaderConfiguration, string $macro, ?array $subfield = null, ?bool $registerModelEvents = true): void |
|
29 | 29 | { |
30 | 30 | $instance = new self($crudObject, $uploaderConfiguration, $macro); |
31 | 31 | |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | /******************************* |
36 | 36 | * Private methods - implementation |
37 | 37 | *******************************/ |
38 | - private function registerEvents(array|null $subfield = [], ?bool $registerModelEvents = true): void |
|
38 | + private function registerEvents(array | null $subfield = [], ?bool $registerModelEvents = true): void |
|
39 | 39 | { |
40 | - if (! empty($subfield)) { |
|
40 | + if (!empty($subfield)) { |
|
41 | 41 | $this->registerSubfieldEvent($subfield, $registerModelEvents); |
42 | 42 | |
43 | 43 | return; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | $subfields = collect($this->crudObject->getAttributes()['subfields']); |
84 | - $subfields = $subfields->map(function ($item) use ($subfield, $uploader) { |
|
84 | + $subfields = $subfields->map(function($item) use ($subfield, $uploader) { |
|
85 | 85 | if ($item['name'] === $subfield['name']) { |
86 | 86 | $item['upload'] = true; |
87 | 87 | $item['disk'] = $uploader->getDisk(); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | |
113 | 113 | if ($this->crudObjectType === 'field') { |
114 | - $model::saving(function ($entry) use ($uploader) { |
|
114 | + $model::saving(function($entry) use ($uploader) { |
|
115 | 115 | $entry = $uploader->storeUploadedFiles($entry); |
116 | 116 | }); |
117 | 117 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // is not called in pivot models when loading the relations. |
125 | 125 | $retrieveModel = $this->getModelForRetrieveEvent($model, $uploader); |
126 | 126 | |
127 | - $retrieveModel::retrieved(function ($entry) use ($uploader) { |
|
127 | + $retrieveModel::retrieved(function($entry) use ($uploader) { |
|
128 | 128 | if ($entry->translationEnabled()) { |
129 | 129 | $locale = request('_locale', app()->getLocale()); |
130 | 130 | if (in_array($locale, array_keys($entry->getAvailableLocales()))) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | }); |
136 | 136 | } |
137 | 137 | |
138 | - $model::deleting(function ($entry) use ($uploader) { |
|
138 | + $model::deleting(function($entry) use ($uploader) { |
|
139 | 139 | $uploader->deleteUploadedFiles($entry); |
140 | 140 | }); |
141 | 141 | |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | $customUploader = isset($uploaderConfiguration['uploader']) && class_exists($uploaderConfiguration['uploader']); |
158 | 158 | |
159 | 159 | if ($customUploader) { |
160 | - return $uploaderConfiguration['uploader']::for($crudObject, $uploaderConfiguration); |
|
160 | + return $uploaderConfiguration['uploader']::for ($crudObject, $uploaderConfiguration); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $uploader = app('UploadersRepository')->hasUploadFor($crudObject['type'], $this->macro); |
164 | 164 | |
165 | 165 | if ($uploader) { |
166 | - return app('UploadersRepository')->getUploadFor($crudObject['type'], $this->macro)::for($crudObject, $uploaderConfiguration); |
|
166 | + return app('UploadersRepository')->getUploadFor($crudObject['type'], $this->macro)::for ($crudObject, $uploaderConfiguration); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | throw new Exception('Undefined upload type for '.$this->crudObjectType.' type: '.$crudObject['type']); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | private function getSubfieldModel(array $subfield, UploaderInterface $uploader) |
181 | 181 | { |
182 | - if (! $uploader->isRelationship()) { |
|
182 | + if (!$uploader->isRelationship()) { |
|
183 | 183 | return $subfield['baseModel'] ?? get_class(app('crud')->getModel()); |
184 | 184 | } |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | private function getModelForRetrieveEvent(string $model, UploaderInterface $uploader) |
194 | 194 | { |
195 | - if (! $uploader->isRelationship()) { |
|
195 | + if (!$uploader->isRelationship()) { |
|
196 | 196 | return $model; |
197 | 197 | } |
198 | 198 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $value = $value ?? CRUD::getRequest()->get($this->getName()); |
15 | 15 | $previousImage = $this->getPreviousFiles($entry); |
16 | 16 | |
17 | - if (! $value && $previousImage) { |
|
17 | + if (!$value && $previousImage) { |
|
18 | 18 | Storage::disk($this->getDisk())->delete($previousImage); |
19 | 19 | |
20 | 20 | return null; |
@@ -67,6 +67,6 @@ discard block |
||
67 | 67 | |
68 | 68 | protected function shouldKeepPreviousValueUnchanged(Model $entry, $entryValue): bool |
69 | 69 | { |
70 | - return $entry->exists && is_string($entryValue) && ! Str::startsWith($entryValue, 'data:image'); |
|
70 | + return $entry->exists && is_string($entryValue) && !Str::startsWith($entryValue, 'data:image'); |
|
71 | 71 | } |
72 | 72 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | class MultipleFiles extends Uploader |
12 | 12 | { |
13 | - public static function for(array $field, $configuration): UploaderInterface |
|
13 | + public static function for (array $field, $configuration): UploaderInterface |
|
14 | 14 | { |
15 | 15 | return (new self($field, $configuration))->multiple(); |
16 | 16 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $previousFiles = []; |
30 | 30 | } |
31 | 31 | |
32 | - if (! is_array($previousFiles) && is_string($previousFiles)) { |
|
32 | + if (!is_array($previousFiles) && is_string($previousFiles)) { |
|
33 | 33 | $previousFiles = json_decode($previousFiles, true); |
34 | 34 | } |
35 | 35 | |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | if (in_array($previousFile, $filesToDelete)) { |
39 | 39 | Storage::disk($this->getDisk())->delete($previousFile); |
40 | 40 | |
41 | - $previousFiles = Arr::where($previousFiles, function ($value, $key) use ($previousFile) { |
|
41 | + $previousFiles = Arr::where($previousFiles, function($value, $key) use ($previousFile) { |
|
42 | 42 | return $value != $previousFile; |
43 | 43 | }); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - if (! is_array($value)) { |
|
48 | + if (!is_array($value)) { |
|
49 | 49 | $value = []; |
50 | 50 | } |
51 | 51 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | { |
15 | 15 | public bool $handleRepeatableFiles = false; |
16 | 16 | |
17 | - public null|string $repeatableContainerName = null; |
|
17 | + public null | string $repeatableContainerName = null; |
|
18 | 18 | |
19 | 19 | /******************************* |
20 | 20 | * Setters - fluently configure the uploader |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /******************************* |
32 | 32 | * Getters |
33 | 33 | *******************************/ |
34 | - public function getRepeatableContainerName(): null|string |
|
34 | + public function getRepeatableContainerName(): null | string |
|
35 | 35 | { |
36 | 36 | return $this->repeatableContainerName; |
37 | 37 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | return $entry; |
57 | 57 | } |
58 | 58 | |
59 | - public static function collecFilesAndValuesFromRequest(string $attribute): array|Collection |
|
59 | + public static function collecFilesAndValuesFromRequest(string $attribute): array | Collection |
|
60 | 60 | { |
61 | 61 | $values = collect(CRUD::getRequest()->get($attribute)); |
62 | 62 | $files = collect(CRUD::getRequest()->file($attribute)); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $uploader) { |
138 | 138 | $uploadedValues = $uploader->uploadRepeatableFiles($values->pluck($uploader->getAttributeName())->toArray(), $this->getPreviousRepeatableValues($entry, $uploader)); |
139 | 139 | |
140 | - $values = $values->map(function ($item, $key) use ($uploadedValues, $uploader) { |
|
140 | + $values = $values->map(function($item, $key) use ($uploadedValues, $uploader) { |
|
141 | 141 | $item[$uploader->getAttributeName()] = $uploadedValues[$key] ?? null; |
142 | 142 | |
143 | 143 | return $item; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | $values = $entry->{$this->getRepeatableContainerName()}; |
159 | 159 | $values = is_string($values) ? json_decode($values, true) : $values; |
160 | - $values = array_map(function ($item) use ($repeatableUploaders) { |
|
160 | + $values = array_map(function($item) use ($repeatableUploaders) { |
|
161 | 161 | foreach ($repeatableUploaders as $upload) { |
162 | 162 | $item[$upload->getAttributeName()] = $this->getValuesWithPathStripped($item, $upload); |
163 | 163 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | private function retrieveRepeatableRelationFiles(Model $entry) |
174 | 174 | { |
175 | - switch($this->getRepeatableRelationType()) { |
|
175 | + switch ($this->getRepeatableRelationType()) { |
|
176 | 176 | case 'BelongsToMany': |
177 | 177 | case 'MorphToMany': |
178 | 178 | $pivotClass = app('crud')->getModel()->{$this->getUploaderSubfield()['baseEntity']}()->getPivotClass(); |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | |
219 | 219 | $repeatableValues = collect($entry->{$this->getName()}); |
220 | 220 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $upload) { |
221 | - if (! $upload->shouldDeleteFiles()) { |
|
221 | + if (!$upload->shouldDeleteFiles()) { |
|
222 | 222 | continue; |
223 | 223 | } |
224 | 224 | $values = $repeatableValues->pluck($upload->getName())->toArray(); |
225 | 225 | foreach ($values as $value) { |
226 | - if (! $value) { |
|
226 | + if (!$value) { |
|
227 | 227 | continue; |
228 | 228 | } |
229 | 229 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | { |
251 | 251 | $items = CRUD::getRequest()->input('_order_'.$this->getRepeatableContainerName()) ?? []; |
252 | 252 | |
253 | - array_walk($items, function (&$key, $value) { |
|
253 | + array_walk($items, function(&$key, $value) { |
|
254 | 254 | $requestValue = $key[$this->getName()] ?? null; |
255 | 255 | $key = $this->handleMultipleFiles ? (is_string($requestValue) ? explode(',', $requestValue) : $requestValue) : $requestValue; |
256 | 256 | }); |
@@ -262,18 +262,18 @@ discard block |
||
262 | 262 | { |
263 | 263 | $previousValues = json_decode($entry->getOriginal($uploader->getRepeatableContainerName()), true); |
264 | 264 | |
265 | - if (! empty($previousValues)) { |
|
265 | + if (!empty($previousValues)) { |
|
266 | 266 | $previousValues = array_column($previousValues, $uploader->getName()); |
267 | 267 | } |
268 | 268 | |
269 | 269 | return $previousValues ?? []; |
270 | 270 | } |
271 | 271 | |
272 | - private function getValuesWithPathStripped(array|string|null $item, UploaderInterface $upload) |
|
272 | + private function getValuesWithPathStripped(array | string | null $item, UploaderInterface $upload) |
|
273 | 273 | { |
274 | 274 | $uploadedValues = $item[$upload->getName()] ?? null; |
275 | 275 | if (is_array($uploadedValues)) { |
276 | - return array_map(function ($value) use ($upload) { |
|
276 | + return array_map(function($value) use ($upload) { |
|
277 | 277 | return Str::after($value, $upload->getPath()); |
278 | 278 | }, $uploadedValues); |
279 | 279 | } |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | { |
293 | 293 | if (in_array($this->getRepeatableRelationType(), ['BelongsToMany', 'MorphToMany'])) { |
294 | 294 | $pivotAttributes = $entry->getAttributes(); |
295 | - $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function ($item) use ($pivotAttributes) { |
|
295 | + $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function($item) use ($pivotAttributes) { |
|
296 | 296 | $itemPivotAttributes = $item->pivot->only(array_keys($pivotAttributes)); |
297 | 297 | |
298 | 298 | return $itemPivotAttributes === $pivotAttributes; |
299 | 299 | })->first(); |
300 | 300 | |
301 | - if (! $connectedPivot) { |
|
301 | + if (!$connectedPivot) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | 305 | $files = $connectedPivot->getOriginal()['pivot_'.$this->getAttributeName()]; |
306 | 306 | |
307 | - if (! $files) { |
|
307 | + if (!$files) { |
|
308 | 308 | return; |
309 | 309 | } |
310 | 310 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | private bool $deleteWhenEntryIsDeleted = true; |
28 | 28 | |
29 | - private bool|string $attachedToFakeField = false; |
|
29 | + private bool | string $attachedToFakeField = false; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Cloud disks have the ability to generate temporary URLs to files, should we do it? |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /******************************* |
64 | 64 | * Static methods |
65 | 65 | *******************************/ |
66 | - public static function for(array $crudObject, array $definition): UploaderInterface |
|
66 | + public static function for (array $crudObject, array $definition): UploaderInterface |
|
67 | 67 | { |
68 | 68 | return new static($crudObject, $definition); |
69 | 69 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function deleteUploadedFiles(Model $entry): void |
105 | 105 | { |
106 | 106 | if ($this->deleteWhenEntryIsDeleted) { |
107 | - if (! in_array(SoftDeletes::class, class_uses_recursive($entry), true)) { |
|
107 | + if (!in_array(SoftDeletes::class, class_uses_recursive($entry), true)) { |
|
108 | 108 | $this->performFileDeletion($entry); |
109 | 109 | |
110 | 110 | return; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | public function getPreviousFiles(Model $entry): mixed |
182 | 182 | { |
183 | - if (! $this->attachedToFakeField) { |
|
183 | + if (!$this->attachedToFakeField) { |
|
184 | 184 | return $this->getOriginalValue($entry); |
185 | 185 | } |
186 | 186 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $value = $entry->{$this->getAttributeName()}; |
220 | 220 | |
221 | 221 | if ($this->handleMultipleFiles) { |
222 | - if (! isset($entry->getCasts()[$this->getName()]) && is_string($value)) { |
|
222 | + if (!isset($entry->getCasts()[$this->getName()]) && is_string($value)) { |
|
223 | 223 | $entry->{$this->getAttributeName()} = json_decode($value, true); |
224 | 224 | } |
225 | 225 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | |
252 | 252 | if ($this->handleMultipleFiles) { |
253 | 253 | // ensure we have an array of values when field is not casted in model. |
254 | - if (! isset($entry->getCasts()[$this->name]) && is_string($values)) { |
|
254 | + if (!isset($entry->getCasts()[$this->name]) && is_string($values)) { |
|
255 | 255 | $values = json_decode($values, true); |
256 | 256 | } |
257 | 257 | foreach ($values ?? [] as $value) { |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | |
269 | 269 | private function performFileDeletion(Model $entry) |
270 | 270 | { |
271 | - if (! $this->handleRepeatableFiles) { |
|
271 | + if (!$this->handleRepeatableFiles) { |
|
272 | 272 | $this->deleteFiles($entry); |
273 | 273 | |
274 | 274 | return; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | $previousValue = $entry->getOriginal($field ?? $this->getAttributeName()); |
297 | 297 | |
298 | - if (! $previousValue) { |
|
298 | + if (!$previousValue) { |
|
299 | 299 | return $previousValue; |
300 | 300 | } |
301 | 301 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | /** |
314 | 314 | * Given two multidimensional arrays/collections, merge them recursively. |
315 | 315 | */ |
316 | - public static function mergeFilesAndValuesRecursive(array|Collection $array1, array|Collection $array2): array|Collection |
|
316 | + public static function mergeFilesAndValuesRecursive(array | Collection $array1, array | Collection $array2): array | Collection |
|
317 | 317 | { |
318 | 318 | $merged = $array1; |
319 | 319 | foreach ($array2 as $key => &$value) { |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | - if (! array_key_exists($attribute, $this->data) && $entry) { |
|
36 | + if (!array_key_exists($attribute, $this->data) && $entry) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $this->createValidator($attribute, $this->getFieldRules(), $value, $fail); |
41 | 41 | |
42 | - if (! empty($value) && ! empty($this->getFileRules())) { |
|
42 | + if (!empty($value) && !empty($this->getFileRules())) { |
|
43 | 43 | $this->createValidator($attribute, $this->getFileRules(), $value, $fail); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - public static function field(string|array|ValidationRule|Rule $rules = []): self |
|
47 | + public static function field(string | array | ValidationRule | Rule $rules = []): self |
|
48 | 48 | { |
49 | 49 | return parent::field($rules); |
50 | 50 | } |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | |
58 | 58 | $values[$mainField] = Uploader::mergeFilesAndValuesRecursive($this->data[$mainField], $this->data['_order_'.$mainField] ?? []); |
59 | 59 | |
60 | - if (! array_key_exists($subfield, $values[$mainField][$row]) && $entry) { |
|
60 | + if (!array_key_exists($subfield, $values[$mainField][$row]) && $entry) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $this->createValidator($subfield, $this->getFieldRules(), $values[$mainField][$row][$subfield] ?? null, $fail); |
65 | 65 | |
66 | - if (! empty($value) && ! empty($this->getFileRules())) { |
|
66 | + if (!empty($value) && !empty($this->getFileRules())) { |
|
67 | 67 | $this->createValidator($subfield, $this->getFileRules(), $values[$mainField][$row][$subfield] ?? null, $fail); |
68 | 68 | } |
69 | 69 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | return; |
29 | 29 | } |
30 | 30 | |
31 | - if (! $value = self::ensureValidValue($value)) { |
|
31 | + if (!$value = self::ensureValidValue($value)) { |
|
32 | 32 | $fail('Unable to determine the value type.'); |
33 | 33 | |
34 | 34 | return; |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | |
79 | 79 | $values[$mainField] = Uploader::mergeFilesAndValuesRecursive($this->data[$mainField], $this->data['_order_'.$mainField] ?? []); |
80 | 80 | |
81 | - if (! array_key_exists($subfield, $values[$mainField][$row]) && $entry) { |
|
81 | + if (!array_key_exists($subfield, $values[$mainField][$row]) && $entry) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | $this->createValidator($subfield, $this->getFieldRules(), $values[$mainField][$row][$subfield] ?? null, $fail); |
86 | 86 | |
87 | - if (! empty($value) && ! empty($this->getFileRules())) { |
|
87 | + if (!empty($value) && !empty($this->getFileRules())) { |
|
88 | 88 | $this->createValidator($subfield, $this->getFileRules(), $values[$mainField][$row][$subfield] ?? null, $fail); |
89 | 89 | } |
90 | 90 | } |