We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | try { |
| 76 | 76 | $entryValue = json_decode($entryValue, true); |
| 77 | 77 | } catch (\Exception) { |
| 78 | - return $entry; |
|
| 78 | + return $entry; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | try { |
| 325 | 325 | $files = json_decode($files, true); |
| 326 | 326 | } catch (\Exception) { |
| 327 | - Log::error('Could not parse files for deletion pivot entry with key: '. $entry->getKey() . ' and uploader: ' . $this->getName()); |
|
| 328 | - return; |
|
| 327 | + Log::error('Could not parse files for deletion pivot entry with key: '. $entry->getKey() . ' and uploader: ' . $this->getName()); |
|
| 328 | + return; |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
@@ -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 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | private function processRelationshipRepeatableUploaders(Model $entry) |
| 62 | 62 | { |
| 63 | - foreach(app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $uploader) { |
|
| 63 | + foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $uploader) { |
|
| 64 | 64 | $entry = $uploader->uploadRelationshipFiles($entry); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $entryValue = $this->getFilesFromEntry($entry); |
| 73 | 73 | |
| 74 | - if($this->handleMultipleFiles && is_string($entryValue)) { |
|
| 74 | + if ($this->handleMultipleFiles && is_string($entryValue)) { |
|
| 75 | 75 | try { |
| 76 | 76 | $entryValue = json_decode($entryValue, true); |
| 77 | 77 | } catch (\Exception) { |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | $this->updatedPreviousFiles = $this->getEntryAttributeValue($entry); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if($this->shouldKeepPreviousValueUnchanged($entry, $entryValue)) { |
|
| 87 | + if ($this->shouldKeepPreviousValueUnchanged($entry, $entryValue)) { |
|
| 88 | 88 | $entry->{$this->getAttributeName()} = $this->updatedPreviousFiles ?? $this->getEntryOriginalValue($entry); |
| 89 | 89 | return $entry; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if($this->shouldUploadFiles($entryValue)) { |
|
| 92 | + if ($this->shouldUploadFiles($entryValue)) { |
|
| 93 | 93 | $entry->{$this->getAttributeName()} = $this->uploadFiles($entry, $entryValue); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $uploader) { |
| 132 | 132 | $uploadedValues = $uploader->uploadRepeatableFiles($values->pluck($uploader->getAttributeName())->toArray(), $this->getPreviousRepeatableValues($entry, $uploader)); |
| 133 | 133 | |
| 134 | - $values = $values->map(function ($item, $key) use ($uploadedValues, $uploader) { |
|
| 134 | + $values = $values->map(function($item, $key) use ($uploadedValues, $uploader) { |
|
| 135 | 135 | $item[$uploader->getAttributeName()] = $uploadedValues[$key] ?? null; |
| 136 | 136 | |
| 137 | 137 | return $item; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | $values = $entry->{$this->getRepeatableContainerName()}; |
| 153 | 153 | $values = is_string($values) ? json_decode($values, true) : $values; |
| 154 | - $values = array_map(function ($item) use ($repeatableUploaders) { |
|
| 154 | + $values = array_map(function($item) use ($repeatableUploaders) { |
|
| 155 | 155 | foreach ($repeatableUploaders as $upload) { |
| 156 | 156 | $item[$upload->getAttributeName()] = $this->getValuesWithPathStripped($item, $upload); |
| 157 | 157 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | private function retrieveRepeatableRelationFiles(Model $entry) |
| 168 | 168 | { |
| 169 | - switch($this->getRepeatableRelationType()) { |
|
| 169 | + switch ($this->getRepeatableRelationType()) { |
|
| 170 | 170 | case 'BelongsToMany': |
| 171 | 171 | case 'MorphToMany': |
| 172 | 172 | $pivotClass = app('crud')->getModel()->{$this->getUploaderSubfield()['baseEntity']}()->getPivotClass(); |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $repeatableValues = collect($entry->{$this->getName()}); |
| 214 | 214 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $upload) { |
| 215 | - if (! $upload->shouldDeleteFiles()) { |
|
| 215 | + if (!$upload->shouldDeleteFiles()) { |
|
| 216 | 216 | continue; |
| 217 | 217 | } |
| 218 | 218 | $values = $repeatableValues->pluck($upload->getName())->toArray(); |
| 219 | 219 | foreach ($values as $value) { |
| 220 | - if (! $value) { |
|
| 220 | + if (!$value) { |
|
| 221 | 221 | continue; |
| 222 | 222 | } |
| 223 | 223 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | /** |
| 241 | 241 | * Given two multidimensional arrays/collections, merge them recursively. |
| 242 | 242 | */ |
| 243 | - protected function mergeValuesRecursive(array|Collection $array1, array|Collection $array2): array|Collection |
|
| 243 | + protected function mergeValuesRecursive(array | Collection $array1, array | Collection $array2): array | Collection |
|
| 244 | 244 | { |
| 245 | 245 | $merged = $array1; |
| 246 | 246 | foreach ($array2 as $key => &$value) { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | { |
| 263 | 263 | $items = CRUD::getRequest()->input('_order_'.$this->getRepeatableContainerName()) ?? []; |
| 264 | 264 | |
| 265 | - array_walk($items, function (&$key, $value) { |
|
| 265 | + array_walk($items, function(&$key, $value) { |
|
| 266 | 266 | $requestValue = $key[$this->getName()] ?? null; |
| 267 | 267 | $key = $this->handleMultipleFiles ? (is_string($requestValue) ? explode(',', $requestValue) : $requestValue) : $requestValue; |
| 268 | 268 | }); |
@@ -274,18 +274,18 @@ discard block |
||
| 274 | 274 | { |
| 275 | 275 | $previousValues = json_decode($entry->getOriginal($uploader->getRepeatableContainerName()), true); |
| 276 | 276 | |
| 277 | - if (! empty($previousValues)) { |
|
| 277 | + if (!empty($previousValues)) { |
|
| 278 | 278 | $previousValues = array_column($previousValues, $uploader->getName()); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | return $previousValues ?? []; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - private function getValuesWithPathStripped(array|string|null $item, UploaderInterface $upload) |
|
| 284 | + private function getValuesWithPathStripped(array | string | null $item, UploaderInterface $upload) |
|
| 285 | 285 | { |
| 286 | 286 | $uploadedValues = $item[$upload->getName()] ?? null; |
| 287 | 287 | if (is_array($uploadedValues)) { |
| 288 | - return array_map(function ($value) use ($upload) { |
|
| 288 | + return array_map(function($value) use ($upload) { |
|
| 289 | 289 | return Str::after($value, $upload->getPath()); |
| 290 | 290 | }, $uploadedValues); |
| 291 | 291 | } |
@@ -304,27 +304,27 @@ discard block |
||
| 304 | 304 | { |
| 305 | 305 | if (in_array($this->getRepeatableRelationType(), ['BelongsToMany', 'MorphToMany'])) { |
| 306 | 306 | $pivotAttributes = $entry->getAttributes(); |
| 307 | - $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function ($item) use ($pivotAttributes) { |
|
| 307 | + $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function($item) use ($pivotAttributes) { |
|
| 308 | 308 | $itemPivotAttributes = $item->pivot->only(array_keys($pivotAttributes)); |
| 309 | 309 | |
| 310 | 310 | return $itemPivotAttributes === $pivotAttributes; |
| 311 | 311 | })->first(); |
| 312 | 312 | |
| 313 | - if (! $connectedPivot) { |
|
| 313 | + if (!$connectedPivot) { |
|
| 314 | 314 | return; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $files = $connectedPivot->getOriginal()['pivot_'.$this->getAttributeName()]; |
| 318 | 318 | |
| 319 | - if (! $files) { |
|
| 319 | + if (!$files) { |
|
| 320 | 320 | return; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if($this->handleMultipleFiles && is_string($files)) { |
|
| 323 | + if ($this->handleMultipleFiles && is_string($files)) { |
|
| 324 | 324 | try { |
| 325 | 325 | $files = json_decode($files, true); |
| 326 | 326 | } catch (\Exception) { |
| 327 | - Log::error('Could not parse files for deletion pivot entry with key: '. $entry->getKey() . ' and uploader: ' . $this->getName()); |
|
| 327 | + Log::error('Could not parse files for deletion pivot entry with key: '.$entry->getKey().' and uploader: '.$this->getName()); |
|
| 328 | 328 | return; |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | $value = $value ?? CrudPanelFacade::getRequest()->file($this->getName()); |
| 14 | 14 | $previousFile = $this->getPreviousFiles($entry); |
| 15 | 15 | |
| 16 | - if($value === false && $previousFile) { |
|
| 16 | + if ($value === false && $previousFile) { |
|
| 17 | 17 | Storage::disk($this->getDisk())->delete($previousFile); |
| 18 | 18 | return null; |
| 19 | 19 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | return $this->getPath().$fileName; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if (! $value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) { |
|
| 31 | + if (!$value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) { |
|
| 32 | 32 | Storage::disk($this->getDisk())->delete($previousFile); |
| 33 | 33 | |
| 34 | 34 | return null; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | foreach ($previousRepeatableValues as $row => $file) { |
| 54 | - if ($file && ! isset($orderedFiles[$row])) { |
|
| 54 | + if ($file && !isset($orderedFiles[$row])) { |
|
| 55 | 55 | $orderedFiles[$row] = null; |
| 56 | 56 | Storage::disk($this->getDisk())->delete($file); |
| 57 | 57 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | private bool $deleteWhenEntryIsDeleted = true; |
| 27 | 27 | |
| 28 | - private bool|string $attachedToFakeField = false; |
|
| 28 | + private bool | string $attachedToFakeField = false; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Cloud disks have the ability to generate temporary URLs to files, should we do it? |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | /******************************* |
| 63 | 63 | * Static methods |
| 64 | 64 | *******************************/ |
| 65 | - public static function for(array $crudObject, array $definition): UploaderInterface |
|
| 65 | + public static function for (array $crudObject, array $definition): UploaderInterface |
|
| 66 | 66 | { |
| 67 | 67 | return new static($crudObject, $definition); |
| 68 | 68 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | public function deleteUploadedFiles(Model $entry): void |
| 104 | 104 | { |
| 105 | 105 | if ($this->deleteWhenEntryIsDeleted) { |
| 106 | - if (! in_array(SoftDeletes::class, class_uses_recursive($entry), true)) { |
|
| 106 | + if (!in_array(SoftDeletes::class, class_uses_recursive($entry), true)) { |
|
| 107 | 107 | $this->performFileDeletion($entry); |
| 108 | 108 | |
| 109 | 109 | return; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | public function getPreviousFiles(Model $entry): mixed |
| 181 | 181 | { |
| 182 | - if (! $this->attachedToFakeField) { |
|
| 182 | + if (!$this->attachedToFakeField) { |
|
| 183 | 183 | return $this->getOriginalValue($entry); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $value = $entry->{$this->getAttributeName()}; |
| 219 | 219 | |
| 220 | 220 | if ($this->handleMultipleFiles) { |
| 221 | - if (! isset($entry->getCasts()[$this->getName()]) && is_string($value)) { |
|
| 221 | + if (!isset($entry->getCasts()[$this->getName()]) && is_string($value)) { |
|
| 222 | 222 | $entry->{$this->getAttributeName()} = json_decode($value, true); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $values = $entry->{$this->getAttributeName()}; |
| 246 | 246 | |
| 247 | - if($values === null) { |
|
| 247 | + if ($values === null) { |
|
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ($this->handleMultipleFiles) { |
| 252 | 252 | // ensure we have an array of values when field is not casted in model. |
| 253 | - if (! isset($entry->getCasts()[$this->name]) && is_string($values)) { |
|
| 253 | + if (!isset($entry->getCasts()[$this->name]) && is_string($values)) { |
|
| 254 | 254 | $values = json_decode($values, true); |
| 255 | 255 | } |
| 256 | 256 | foreach ($values ?? [] as $value) { |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | private function performFileDeletion(Model $entry) |
| 269 | 269 | { |
| 270 | - if (! $this->handleRepeatableFiles) { |
|
| 270 | + if (!$this->handleRepeatableFiles) { |
|
| 271 | 271 | $this->deleteFiles($entry); |
| 272 | 272 | |
| 273 | 273 | return; |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | private function getOriginalValue(Model $entry, $field = null) |
| 290 | 290 | { |
| 291 | - if($this->updatedPreviousFiles !== null) { |
|
| 291 | + if ($this->updatedPreviousFiles !== null) { |
|
| 292 | 292 | return $this->updatedPreviousFiles; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $previousValue = $entry->getOriginal($field ?? $this->getAttributeName()); |
| 296 | 296 | |
| 297 | - if (! $previousValue) { |
|
| 297 | + if (!$previousValue) { |
|
| 298 | 298 | return $previousValue; |
| 299 | 299 | } |
| 300 | 300 | |