Skip to content

Commit f3aa291

Browse files
committed
fix: wip
2 parents 2395dc2 + 6fac70f commit f3aa291

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

src/Commands/PolicyCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected function replaceUserImport($stub)
5656
if ($qualifiedModel === $userQualified) {
5757
// Remove the entire user import line since it would be duplicate
5858
$stub = preg_replace('/use\s+\{\{\s*userQualified\s*\}\};\s*\n/', '', $stub);
59+
5960
return $stub;
6061
}
6162

src/Commands/RepositoryCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function handle()
4242

4343
return false;
4444
}
45-
45+
4646
// Set force option to true since user confirmed override
4747
$this->input->setOption('force', true);
4848
}
@@ -259,20 +259,20 @@ protected function getPath($name)
259259
// Apply the discovered pattern
260260
$modelBaseName = Str::before(class_basename($name), 'Repository');
261261
$patternPath = $this->applyPathPattern($modelBaseName, $existingRepositoryPath['pattern']);
262-
262+
263263
// Build the namespace path, avoiding duplication
264264
$namespaceParts = [];
265265
$baseNamespace = str_replace($this->rootNamespace().'\\', '', $existingRepositoryPath['namespace']);
266266
if ($baseNamespace) {
267267
$namespaceParts[] = $baseNamespace;
268268
}
269-
270-
if ($patternPath && !empty($patternPath)) {
269+
270+
if ($patternPath && ! empty($patternPath)) {
271271
$namespaceParts[] = str_replace('\\', '/', $patternPath);
272272
}
273-
273+
274274
$namespaceParts[] = class_basename($name);
275-
275+
276276
return $this->laravel['path'].'/'.implode('/', $namespaceParts).'.php';
277277
}
278278

@@ -286,21 +286,21 @@ protected function getDefaultNamespace($rootNamespace)
286286

287287
if ($existingRepositoryPath) {
288288
$namespace = $existingRepositoryPath['namespace'];
289-
289+
290290
// Apply pattern for the current model if needed
291291
if ($existingRepositoryPath['pattern'] && $existingRepositoryPath['pattern'] !== 'flat') {
292292
$modelBaseName = Str::before(class_basename($this->getNameInput()), 'Repository');
293293
$patternPath = $this->applyPathPattern($modelBaseName, $existingRepositoryPath['pattern']);
294-
295-
if ($patternPath && !empty($patternPath)) {
294+
295+
if ($patternPath && ! empty($patternPath)) {
296296
// Only add pattern path if it doesn't already exist in namespace
297297
$patternPathNormalized = str_replace('/', '\\', $patternPath);
298-
if (!Str::endsWith($namespace, $patternPathNormalized)) {
299-
$namespace .= '\\' . $patternPathNormalized;
298+
if (! Str::endsWith($namespace, $patternPathNormalized)) {
299+
$namespace .= '\\'.$patternPathNormalized;
300300
}
301301
}
302302
}
303-
303+
304304
return $namespace;
305305
}
306306

src/Repositories/Repository.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ public function resolveShowAttributes(RestifyRequest $request)
401401
{
402402
$fields = $this->collectFields($request)
403403
->forShow($request, $this)
404-
->filter(fn(Field $field) => $field->authorize($request))
405-
->each(fn(Field $field) => $field->resolveForShow($this))
406-
->map(fn(Field $field) => $field->serializeToValue($request))
407-
->mapWithKeys(fn($value) => $value)
404+
->filter(fn (Field $field) => $field->authorize($request))
405+
->each(fn (Field $field) => $field->resolveForShow($this))
406+
->map(fn (Field $field) => $field->serializeToValue($request))
407+
->mapWithKeys(fn ($value) => $value)
408408
->all();
409409

410410
if ($this instanceof Mergeable) {
@@ -469,17 +469,17 @@ public function resolveIndexAttributes($request)
469469
->collectFields($request)
470470
->when(
471471
$this->hasCustomColumns(),
472-
fn(FieldCollection $fields) => $fields->inList($this->getColumns())
472+
fn (FieldCollection $fields) => $fields->inList($this->getColumns())
473473
)
474474
->forIndex($request, $this)
475-
->filter(fn(Field $field) => $field->authorize($request))
475+
->filter(fn (Field $field) => $field->authorize($request))
476476
->when(
477477
$this->eagerState,
478-
fn($items) => $items->filter(fn(Field $field) => ! $field instanceof EagerField)
478+
fn ($items) => $items->filter(fn (Field $field) => ! $field instanceof EagerField)
479479
)
480-
->each(fn(Field $field) => $field->resolveForIndex($this))
481-
->map(fn(Field $field) => $field->serializeToValue($request))
482-
->mapWithKeys(fn($value) => $value)
480+
->each(fn (Field $field) => $field->resolveForIndex($this))
481+
->map(fn (Field $field) => $field->serializeToValue($request))
482+
->mapWithKeys(fn ($value) => $value)
483483
->all();
484484
}
485485

@@ -513,10 +513,10 @@ public function resolveShowPivots(RestifyRequest $request): array
513513
}
514514

515515
return $pivots
516-
->filter(fn(Field $field) => $field->authorize($request))
517-
->each(fn(Field $field) => $field->resolve($this))
518-
->map(fn(Field $field) => $field->serializeToValue($request))
519-
->mapWithKeys(fn($value) => $value)
516+
->filter(fn (Field $field) => $field->authorize($request))
517+
->each(fn (Field $field) => $field->resolve($this))
518+
->map(fn (Field $field) => $field->serializeToValue($request))
519+
->mapWithKeys(fn ($value) => $value)
520520
->all();
521521
}
522522

@@ -540,7 +540,7 @@ public function resolveRelationships($request): array
540540
->forRequest($request, $this)
541541
->mapIntoRelated($request, $this)
542542
->unserialized($request, $this)
543-
->map(fn(Related $related) => $related->resolve($request, $this)->getValue())
543+
->map(fn (Related $related) => $related->resolve($request, $this)->getValue())
544544
->map(function (mixed $items) {
545545
if ($items instanceof Collection) {
546546
return $items->filter()->values();
@@ -608,13 +608,13 @@ public function indexAsArray(RestifyRequest $request): array
608608
return $repository->authorizedToShow($request);
609609
})->values();
610610

611-
$data = $items->map(fn(self $repository) => $repository->serializeForIndex($request));
611+
$data = $items->map(fn (self $repository) => $repository->serializeForIndex($request));
612612

613613
return $this->filter([
614614
'meta' => $this->when(
615615
$meta = $this->resolveIndexMainMeta(
616616
$request,
617-
$models = $items->map(fn(self $repository) => $repository->resource),
617+
$models = $items->map(fn (self $repository) => $repository->resource),
618618
[
619619
'current_page' => $paginator->currentPage(),
620620
'from' => $paginator->firstItem(),
@@ -700,14 +700,14 @@ public function store(RestifyRequest $request)
700700
}
701701
}
702702

703-
$fields->each(fn(Field $field) => $field->invokeAfter($request, $this->resource));
703+
$fields->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
704704

705705
$this
706706
->collectFields($request)
707707
->forStore($request, $this)
708708
->withActions($request, $this)
709709
->authorizedStore($request)
710-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
710+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
711711
});
712712

713713
if (method_exists(static::class, 'stored')) {
@@ -736,14 +736,14 @@ public function storeBulk(RepositoryStoreBulkRequest $request)
736736

737737
$this->resource->save();
738738

739-
$fields->each(fn(Field $field) => $field->invokeAfter($request, $this->resource));
739+
$fields->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
740740

741741
$this
742742
->collectFields($request)
743743
->forStoreBulk($request, $this)
744744
->withActions($request, $this, $row)
745745
->authorizedUpdateBulk($request)
746-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
746+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
747747

748748
return $this->resource;
749749
});
@@ -770,15 +770,15 @@ public function update(RestifyRequest $request, $repositoryId)
770770

771771
return $fields;
772772
})->each(
773-
fn(Field $field) => $field->invokeAfter($request, $this->resource)
773+
fn (Field $field) => $field->invokeAfter($request, $this->resource)
774774
);
775775

776776
$this
777777
->collectFields($request)
778778
->forUpdate($request, $this)
779779
->withActions($request, $this)
780780
->authorizedUpdate($request)
781-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
781+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
782782

783783
return data($this->serializeForShow($request));
784784
}
@@ -790,7 +790,7 @@ public function patch(RestifyRequest $request, $repositoryId)
790790
DB::transaction(function () use ($request, $keys) {
791791
$fields = $this->collectFields($request)
792792
->filter(
793-
fn(Field $field) => in_array($field->attribute, $keys),
793+
fn (Field $field) => in_array($field->attribute, $keys),
794794
)
795795
->forUpdate($request, $this)
796796
->withoutActions($request, $this)
@@ -809,18 +809,18 @@ public function patch(RestifyRequest $request, $repositoryId)
809809

810810
return $fields;
811811
})->each(
812-
fn(Field $field) => $field->invokeAfter($request, $this->resource)
812+
fn (Field $field) => $field->invokeAfter($request, $this->resource)
813813
);
814814

815815
$this
816816
->collectFields($request)
817817
->filter(
818-
fn(Field $field) => in_array($field->attribute, $keys),
818+
fn (Field $field) => in_array($field->attribute, $keys),
819819
)
820820
->forUpdate($request, $this)
821821
->withActions($request, $this)
822822
->authorizedPatch($request)
823-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
823+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
824824

825825
return data($this->serializeForShow($request));
826826
}
@@ -841,7 +841,7 @@ public function updateBulk(RestifyRequest $request, $repositoryId, int $row)
841841
->forUpdateBulk($request, $this)
842842
->withActions($request, $this, $row)
843843
->authorizedUpdateBulk($request)
844-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
844+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
845845

846846
return response()->json();
847847
}
@@ -866,7 +866,7 @@ public function attach(RestifyRequest $request, $repositoryId, Collection $pivot
866866
$eagerField = $this->authorizeBelongsToMany($request)->belongsToManyField($request);
867867

868868
DB::transaction(function () use ($request, $pivots, $eagerField) {
869-
$fields = $eagerField->collectPivotFields()->filter(fn(
869+
$fields = $eagerField->collectPivotFields()->filter(fn (
870870
$pivotField
871871
) => $request->has($pivotField->attribute))->values();
872872

@@ -910,7 +910,7 @@ public function detach(RestifyRequest $request, $repositoryId, Collection $pivot
910910

911911
$deleted = DB::transaction(function () use ($pivots, $eagerField, $request) {
912912
return $pivots
913-
->map(fn($pivot) => $eagerField->authorizeToDetach($request, $pivot) && $pivot->delete());
913+
->map(fn ($pivot) => $eagerField->authorizeToDetach($request, $pivot) && $pivot->delete());
914914
});
915915

916916
return data($deleted, 204);
@@ -953,7 +953,7 @@ public function allowToAttach(RestifyRequest $request, Collection $attachers): s
953953
{
954954
$methodGuesser = 'attach'.Str::studly($request->relatedRepository);
955955

956-
$attachers->each(fn($model) => $this->authorizeToAttach($request, $methodGuesser, $model));
956+
$attachers->each(fn ($model) => $this->authorizeToAttach($request, $methodGuesser, $model));
957957

958958
return $this;
959959
}
@@ -971,7 +971,7 @@ public function allowToDetach(RestifyRequest $request, Collection $attachers): s
971971
{
972972
$methodGuesser = 'detach'.Str::studly($request->relatedRepository);
973973

974-
$attachers->each(fn($model) => $this->authorizeToDetach($request, $methodGuesser, $model));
974+
$attachers->each(fn ($model) => $this->authorizeToDetach($request, $methodGuesser, $model));
975975

976976
return $this;
977977
}
@@ -1075,7 +1075,7 @@ public function serializeForShow(RestifyRequest $request): array
10751075
$this->request = $request;
10761076

10771077
return $this->filter([
1078-
'id' => $this->when(optional($this->resource)?->getKey(), fn() => $this->getId($request)),
1078+
'id' => $this->when(optional($this->resource)?->getKey(), fn () => $this->getId($request)),
10791079
'type' => $this->when($type = $this->getType($request), $type),
10801080
'attributes' => $request->isShowRequest() ? $this->resolveShowAttributes($request) : $this->resolveIndexAttributes($request),
10811081
'relationships' => $this->when(value($related = $this->resolveRelationships($request)), $related),
@@ -1141,7 +1141,7 @@ private function modelAttributes(?Request $request = null): Collection
11411141
*/
11421142
protected static function fillFields(RestifyRequest $request, Model $model, Collection $fields)
11431143
{
1144-
return $fields->map(fn(Field $field) => $field->fillAttribute($request, $model));
1144+
return $fields->map(fn (Field $field) => $field->fillAttribute($request, $model));
11451145
}
11461146

11471147
protected static function fillBulkFields(
@@ -1208,14 +1208,14 @@ public function restifyjsSerialize(RestifyRequest $request): array
12081208
'match' => static::collectFilters('matches'),
12091209
'searchables' => static::collectFilters('searchables'),
12101210
'actions' => $this->resolveActions($request)
1211-
->filter(fn(mixed $action) => $action instanceof Action)
1212-
->filter(fn(Action $action) => $action->isShownOnIndex(
1211+
->filter(fn (mixed $action) => $action instanceof Action)
1212+
->filter(fn (Action $action) => $action->isShownOnIndex(
12131213
$request,
12141214
$this
12151215
))->values(),
12161216
'getters' => $this->resolveGetters($request)
1217-
->filter(fn(mixed $action) => $action instanceof Getter)
1218-
->filter(fn(Getter $action) => $action->isShownOnIndex(
1217+
->filter(fn (mixed $action) => $action instanceof Getter)
1218+
->filter(fn (Getter $action) => $action->isShownOnIndex(
12191219
$request,
12201220
$this
12211221
))->values(),

src/Traits/InteractWithSearch.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public static function collectSortables(RestifyRequest $request, Repository $rep
7171
}
7272

7373
/**
74-
* @param RestifyRequest $request
75-
* @param Repository $repository
7674
* @deprecated use collectSortables instead
77-
* @return SortCollection
7875
*/
7976
public static function collectSorts(RestifyRequest $request, Repository $repository): SortCollection
8077
{
@@ -96,8 +93,9 @@ public static function collectFieldSorts(RestifyRequest $request, Repository $re
9693
return $repository->collectFields($request)
9794
->filter(fn (Field $field) => $field->isSortable($request))
9895
->map(function (Field $field) {
99-
$sortableFilter = new SortableFilter();
96+
$sortableFilter = new SortableFilter;
10097
$sortableFilter->setColumn($field->getAttribute());
98+
10199
return $sortableFilter;
102100
});
103101
}

tests/Feature/SortableFieldIntegrationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function test_sortable_fields_are_collected_from_repository(): void
2121
$fieldSorts = TestSortableFieldRepository::collectFieldSorts($request, $repository);
2222

2323
// Debug: Let's see what we got
24-
$sortableColumns = $fieldSorts->map(fn($sort) => $sort->column)->toArray();
24+
$sortableColumns = $fieldSorts->map(fn ($sort) => $sort->column)->toArray();
2525

2626
$this->assertCount(2, $fieldSorts); // Adjusted to match actual count
2727

@@ -42,13 +42,13 @@ public function test_field_sorts_work_independently(): void
4242

4343
// Test that field sorts can be collected
4444
$fieldSorts = TestSortableFieldRepository::collectFieldSorts($request, $repository);
45-
$fieldColumns = $fieldSorts->map(fn($sort) => $sort->column)->toArray();
45+
$fieldColumns = $fieldSorts->map(fn ($sort) => $sort->column)->toArray();
4646

4747
$this->assertContains('name', $fieldColumns);
4848
$this->assertContains('created_at', $fieldColumns);
4949

5050
// Test that field sorts have proper attributes
51-
$nameSort = $fieldSorts->firstWhere(fn($sort) => $sort->column === 'name');
51+
$nameSort = $fieldSorts->firstWhere(fn ($sort) => $sort->column === 'name');
5252
$this->assertNotNull($nameSort);
5353
$this->assertInstanceOf(\Binaryk\LaravelRestify\Filters\SortableFilter::class, $nameSort);
5454
}
@@ -61,7 +61,7 @@ public function test_repository_static_sorts_take_precedence_over_field_sorts():
6161
$fieldSorts = TestSortableFieldRepositoryWithConflict::collectFieldSorts($request, $repository);
6262

6363
// Field should define 'name' as sortable
64-
$fieldSortColumns = $fieldSorts->map(fn($sort) => $sort->column)->toArray();
64+
$fieldSortColumns = $fieldSorts->map(fn ($sort) => $sort->column)->toArray();
6565
$this->assertContains('name', $fieldSortColumns);
6666

6767
// But repository static sorts should take precedence in final collection
@@ -210,7 +210,7 @@ class TestSortableModel extends Model
210210
'description',
211211
'created_at',
212212
'internal_score',
213-
'email'
213+
'email',
214214
];
215215

216216
public function getQualifiedKeyName()

0 commit comments

Comments
 (0)