We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -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 | $updatedCountKey = 'uploaded_'.($uploader->getRepeatableContainerName() ?? $uploader->getName()).'_count'; |
| 116 | 116 | |
| 117 | 117 | CRUD::set($updatedCountKey, CRUD::get($updatedCountKey) ?? 0); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | // is not called in pivot models when eager loading the relations. |
| 131 | 131 | $retrieveModel = $this->getRetrieveModel($model, $uploader); |
| 132 | 132 | |
| 133 | - $retrieveModel::retrieved(function ($entry) use ($uploader) { |
|
| 133 | + $retrieveModel::retrieved(function($entry) use ($uploader) { |
|
| 134 | 134 | if ($entry->translationEnabled()) { |
| 135 | 135 | $locale = request('_locale', \App::getLocale()); |
| 136 | 136 | if (in_array($locale, array_keys($entry->getAvailableLocales()))) { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | }); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $model::deleting(function ($entry) use ($uploader) { |
|
| 144 | + $model::deleting(function($entry) use ($uploader) { |
|
| 145 | 145 | $uploader->deleteUploadedFiles($entry); |
| 146 | 146 | }); |
| 147 | 147 | |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | $customUploader = isset($uploaderConfiguration['uploader']) && class_exists($uploaderConfiguration['uploader']); |
| 164 | 164 | |
| 165 | 165 | if ($customUploader) { |
| 166 | - return $uploaderConfiguration['uploader']::for($crudObject, $uploaderConfiguration); |
|
| 166 | + return $uploaderConfiguration['uploader']::for ($crudObject, $uploaderConfiguration); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $uploader = app('UploadersRepository')->hasUploadFor($crudObject['type'], $this->macro); |
| 170 | 170 | |
| 171 | 171 | if ($uploader) { |
| 172 | - return app('UploadersRepository')->getUploadFor($crudObject['type'], $this->macro)::for($crudObject, $uploaderConfiguration); |
|
| 172 | + return app('UploadersRepository')->getUploadFor($crudObject['type'], $this->macro)::for ($crudObject, $uploaderConfiguration); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | throw new Exception('Undefined upload type for '.$this->crudObjectType.' type: '.$crudObject['type']); |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | private function getSubfieldModel(array $subfield, UploaderInterface $uploader) |
| 187 | 187 | { |
| 188 | - if (! $uploader->isRelationship()) { |
|
| 188 | + if (!$uploader->isRelationship()) { |
|
| 189 | 189 | return $subfield['baseModel'] ?? get_class(app('crud')->getModel()); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - switch($subfield['relation_type']) { |
|
| 192 | + switch ($subfield['relation_type']) { |
|
| 193 | 193 | case 'BelongsToMany': |
| 194 | 194 | case 'MorphToMany': |
| 195 | 195 | return app('crud')->getModel()->{$subfield['baseEntity']}()->getPivotClass(); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | private function getRetrieveModel(string $model, UploaderInterface $uploader) |
| 202 | 202 | { |
| 203 | - if (! $uploader->isRelationship()) { |
|
| 203 | + if (!$uploader->isRelationship()) { |
|
| 204 | 204 | return $model; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $uploader) { |
| 77 | 77 | $uploadedValues = $uploader->uploadRepeatableFiles($values->pluck($uploader->getAttributeName())->toArray(), $this->getPreviousRepeatableValues($entry, $uploader)); |
| 78 | 78 | |
| 79 | - $values = $values->map(function ($item, $key) use ($uploadedValues, $uploader) { |
|
| 79 | + $values = $values->map(function($item, $key) use ($uploadedValues, $uploader) { |
|
| 80 | 80 | $item[$uploader->getAttributeName()] = $uploadedValues[$key] ?? null; |
| 81 | 81 | |
| 82 | 82 | return $item; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | $values = $entry->{$this->getRepeatableContainerName()}; |
| 98 | 98 | $values = is_string($values) ? json_decode($values, true) : $values; |
| 99 | - $values = array_map(function ($item) use ($repeatableUploaders) { |
|
| 99 | + $values = array_map(function($item) use ($repeatableUploaders) { |
|
| 100 | 100 | foreach ($repeatableUploaders as $upload) { |
| 101 | 101 | $item[$upload->getAttributeName()] = $this->getValuesWithPathStripped($item, $upload); |
| 102 | 102 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | private function retrieveRepeatableRelationFiles(Model $entry) |
| 113 | 113 | { |
| 114 | - switch($this->getRepeatableRelationType()) { |
|
| 114 | + switch ($this->getRepeatableRelationType()) { |
|
| 115 | 115 | case 'BelongsToMany': |
| 116 | 116 | case 'MorphToMany': |
| 117 | 117 | $pivotClass = app('crud')->getModel()->{$this->getUploaderSubfield()['baseEntity']}()->getPivotClass(); |
@@ -150,23 +150,23 @@ discard block |
||
| 150 | 150 | private function deleteRepeatableFiles(Model $entry): void |
| 151 | 151 | { |
| 152 | 152 | if ($this->isRelationship) { |
| 153 | - switch($this->getRepeatableRelationType()) { |
|
| 153 | + switch ($this->getRepeatableRelationType()) { |
|
| 154 | 154 | case 'BelongsToMany': |
| 155 | 155 | case 'MorphToMany': |
| 156 | 156 | $pivotAttributes = $entry->getAttributes(); |
| 157 | - $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function ($item) use ($pivotAttributes) { |
|
| 157 | + $connectedPivot = $entry->pivotParent->{$this->getRepeatableContainerName()}->where(function($item) use ($pivotAttributes) { |
|
| 158 | 158 | $itemPivotAttributes = $item->pivot->only(array_keys($pivotAttributes)); |
| 159 | 159 | |
| 160 | 160 | return $itemPivotAttributes === $pivotAttributes; |
| 161 | 161 | })->first(); |
| 162 | 162 | |
| 163 | - if (! $connectedPivot) { |
|
| 163 | + if (!$connectedPivot) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $files = $connectedPivot->getOriginal()['pivot_'.$this->getAttributeName()]; |
| 168 | 168 | |
| 169 | - if (! $files) { |
|
| 169 | + if (!$files) { |
|
| 170 | 170 | return; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -192,12 +192,12 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $repeatableValues = collect($entry->{$this->getName()}); |
| 194 | 194 | foreach (app('UploadersRepository')->getRepeatableUploadersFor($this->getRepeatableContainerName()) as $upload) { |
| 195 | - if (! $upload->shouldDeleteFiles()) { |
|
| 195 | + if (!$upload->shouldDeleteFiles()) { |
|
| 196 | 196 | continue; |
| 197 | 197 | } |
| 198 | 198 | $values = $repeatableValues->pluck($upload->getName())->toArray(); |
| 199 | 199 | foreach ($values as $value) { |
| 200 | - if (! $value) { |
|
| 200 | + if (!$value) { |
|
| 201 | 201 | continue; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | /** |
| 221 | 221 | * Given two multidimensional arrays/collections, merge them recursively. |
| 222 | 222 | */ |
| 223 | - protected function mergeValuesRecursive(array|Collection $array1, array|Collection $array2): array|Collection |
|
| 223 | + protected function mergeValuesRecursive(array | Collection $array1, array | Collection $array2): array | Collection |
|
| 224 | 224 | { |
| 225 | 225 | $merged = $array1; |
| 226 | 226 | foreach ($array2 as $key => &$value) { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | { |
| 243 | 243 | $items = CRUD::getRequest()->input('_order_'.$this->getRepeatableContainerName()) ?? []; |
| 244 | 244 | |
| 245 | - array_walk($items, function (&$key, $value) { |
|
| 245 | + array_walk($items, function(&$key, $value) { |
|
| 246 | 246 | $requestValue = $key[$this->getName()] ?? null; |
| 247 | 247 | $key = $this->handleMultipleFiles ? (is_string($requestValue) ? explode(',', $requestValue) : $requestValue) : $requestValue; |
| 248 | 248 | }); |
@@ -254,18 +254,18 @@ discard block |
||
| 254 | 254 | { |
| 255 | 255 | $previousValues = json_decode($entry->getOriginal($uploader->getRepeatableContainerName()), true); |
| 256 | 256 | |
| 257 | - if (! empty($previousValues)) { |
|
| 257 | + if (!empty($previousValues)) { |
|
| 258 | 258 | $previousValues = array_column($previousValues, $uploader->getName()); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | return $previousValues ?? []; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - private function getValuesWithPathStripped(array|string|null $item, UploaderInterface $upload) |
|
| 264 | + private function getValuesWithPathStripped(array | string | null $item, UploaderInterface $upload) |
|
| 265 | 265 | { |
| 266 | 266 | $uploadedValues = $item[$upload->getName()] ?? null; |
| 267 | 267 | if (is_array($uploadedValues)) { |
| 268 | - return array_map(function ($value) use ($upload) { |
|
| 268 | + return array_map(function($value) use ($upload) { |
|
| 269 | 269 | return Str::after($value, $upload->getPath()); |
| 270 | 270 | }, $uploadedValues); |
| 271 | 271 | } |