Skip to content

Commit 9e4585e

Browse files
binarykgithub-actions[bot]
authored andcommitted
Fix styling
1 parent f3aa291 commit 9e4585e

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

src/Fields/Field.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
use JsonSerializable;
2121
use ReturnTypeWillChange;
2222

23-
class Field extends OrganicField implements JsonSerializable, Sortable, Matchable
23+
class Field extends OrganicField implements JsonSerializable, Matchable, Sortable
2424
{
25+
use CanMatch;
26+
use CanSort;
2527
use FieldMcpSchemaDetection;
2628
use HasAction;
2729
use Make;
2830
use ValidationMethods;
29-
use CanSort;
30-
use CanMatch;
3131

3232
/**
3333
* The resource associated with the field.

src/Traits/InteractWithSearch.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Binaryk\LaravelRestify\Filters\SortCollection;
1414
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
1515
use Binaryk\LaravelRestify\Repositories\Repository;
16-
use Closure;
1716
use Illuminate\Support\Collection;
1817

1918
trait InteractWithSearch
@@ -118,19 +117,21 @@ public static function collectFieldMatches(RestifyRequest $request, Repository $
118117
->filter(fn (Field $field) => $field->isMatchable($request))
119118
->map(callback: function (Field $field) use ($request) {
120119
$matchColumn = $field->getMatchColumn($request);
121-
if ($matchColumn instanceof MatchFilter) {
120+
if ($matchColumn instanceof MatchFilter) {
122121
return $matchColumn;
123122
}
124123

125-
$matchFilter = new MatchFilter();
124+
$matchFilter = new MatchFilter;
126125

127126
if (is_callable($matchColumn)) {
128127
$matchFilter->setColumn($field->getAttribute());
128+
129129
return $matchFilter->usingClosure($matchColumn);
130130
}
131131

132132
$matchFilter->setColumn($field->getMatchColumn($request));
133133
$matchFilter->setType($field->getMatchType($request));
134+
134135
return $matchFilter;
135136
});
136137
}

tests/Feature/MatchableFieldIntegrationTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class MatchableFieldIntegrationTest extends IntegrationTestCase
1818
{
1919
public function test_field_matchable_functionality_works(): void
2020
{
21-
$repository = new PostRepository();
22-
$request = new RestifyRequest();
21+
$repository = new PostRepository;
22+
$request = new RestifyRequest;
2323

2424
// Test that field matches are collected
2525
$fieldMatches = PostRepository::collectFieldMatches($request, $repository);
@@ -28,12 +28,12 @@ public function test_field_matchable_functionality_works(): void
2828
// Test field instances have matchable functionality
2929
$fields = $repository->fields($request);
3030

31-
$titleField = collect($fields)->first(fn($field) => $field->getAttribute() === 'title');
31+
$titleField = collect($fields)->first(fn ($field) => $field->getAttribute() === 'title');
3232
$this->assertTrue($titleField->isMatchable(), 'Title field should be matchable');
3333
$this->assertEquals('title', $titleField->getMatchColumn());
3434
$this->assertEquals('text', $titleField->getMatchType());
3535

36-
$isActiveField = collect($fields)->first(fn($field) => $field->getAttribute() === 'is_active');
36+
$isActiveField = collect($fields)->first(fn ($field) => $field->getAttribute() === 'is_active');
3737
$this->assertTrue($isActiveField->isMatchable(), 'Is active field should be matchable');
3838
$this->assertEquals('is_active', $isActiveField->getMatchColumn());
3939
$this->assertEquals('bool', $isActiveField->getMatchType());
@@ -43,7 +43,7 @@ public function test_field_matchable_closure_works(): void
4343
{
4444
// Clear any existing posts to start fresh
4545
Post::query()->delete();
46-
46+
4747
// Register the test repository
4848
Restify::repositories([
4949
TestMatchableRepository::class,
@@ -69,7 +69,7 @@ public function test_field_matchable_closure_works(): void
6969
$this->getJson(TestMatchableRepository::route())
7070
->assertStatus(200)
7171
->assertJson(
72-
fn(AssertableJson $json) => $json
72+
fn (AssertableJson $json) => $json
7373
->has('data', 3) // Should have 3 posts total
7474
->etc()
7575
);
@@ -79,20 +79,20 @@ public function test_field_matchable_closure_works(): void
7979
$this->getJson(TestMatchableRepository::route(query: ['title' => 'Framework']))
8080
->assertStatus(200)
8181
->assertJson(
82-
fn(AssertableJson $json) => $json
82+
fn (AssertableJson $json) => $json
8383
->has('data', 2) // Should return exactly 2 posts matching "Framework"
8484
->has('data.0.attributes.title')
8585
->has('data.1.attributes.title')
86-
->where('data.0.attributes.title', fn($title) => in_array($title, [$post1->title, $post3->title]))
87-
->where('data.1.attributes.title', fn($title) => in_array($title, [$post1->title, $post3->title]))
86+
->where('data.0.attributes.title', fn ($title) => in_array($title, [$post1->title, $post3->title]))
87+
->where('data.1.attributes.title', fn ($title) => in_array($title, [$post1->title, $post3->title]))
8888
->etc()
8989
);
9090

91-
// Test case insensitive search - search for 'laravel' should match post1
91+
// Test case insensitive search - search for 'laravel' should match post1
9292
$this->getJson(TestMatchableRepository::route(query: ['title' => 'laravel']))
9393
->assertStatus(200)
9494
->assertJson(
95-
fn(AssertableJson $json) => $json
95+
fn (AssertableJson $json) => $json
9696
->has('data', 1) // Should return exactly 1 post matching "laravel"
9797
->where('data.0.attributes.title', $post1->title) // Laravel Framework Guide
9898
->etc()
@@ -102,7 +102,7 @@ public function test_field_matchable_closure_works(): void
102102
$this->getJson(TestMatchableRepository::route(query: ['title' => 'NonExistent']))
103103
->assertStatus(200)
104104
->assertJson(
105-
fn(AssertableJson $json) => $json
105+
fn (AssertableJson $json) => $json
106106
->has('data', 0) // Should have 0 results for non-existent search
107107
->etc()
108108
);
@@ -112,7 +112,7 @@ public function test_field_matchable_with_custom_match_filter_works(): void
112112
{
113113
// Clear any existing posts to start fresh
114114
Post::query()->delete();
115-
115+
116116
// Register the test repository
117117
Restify::repositories([
118118
TestMatchFilterRepository::class,
@@ -138,7 +138,7 @@ public function test_field_matchable_with_custom_match_filter_works(): void
138138
$this->getJson(TestMatchFilterRepository::route())
139139
->assertStatus(200)
140140
->assertJson(
141-
fn(AssertableJson $json) => $json
141+
fn (AssertableJson $json) => $json
142142
->has('data', 3) // Should have 3 posts total
143143
->etc()
144144
);
@@ -149,7 +149,7 @@ public function test_field_matchable_with_custom_match_filter_works(): void
149149
$this->getJson(TestMatchFilterRepository::route(query: ['title' => 'Laravel']))
150150
->assertStatus(200)
151151
->assertJson(
152-
fn(AssertableJson $json) => $json
152+
fn (AssertableJson $json) => $json
153153
->has('data', 1) // Should return exactly 1 post starting with "Laravel"
154154
->where('data.0.attributes.title', $post1->title) // Laravel Framework Guide
155155
->etc()
@@ -160,7 +160,7 @@ public function test_field_matchable_with_custom_match_filter_works(): void
160160
$this->getJson(TestMatchFilterRepository::route(query: ['title' => 'Framework']))
161161
->assertStatus(200)
162162
->assertJson(
163-
fn(AssertableJson $json) => $json
163+
fn (AssertableJson $json) => $json
164164
->has('data', 1) // Should return exactly 1 post starting with "Framework"
165165
->where('data.0.attributes.title', $post3->title) // Framework Comparison
166166
->etc()
@@ -170,17 +170,17 @@ public function test_field_matchable_with_custom_match_filter_works(): void
170170
$this->getJson(TestMatchFilterRepository::route(query: ['title' => 'Vue']))
171171
->assertStatus(200)
172172
->assertJson(
173-
fn(AssertableJson $json) => $json
173+
fn (AssertableJson $json) => $json
174174
->has('data', 1) // Should return exactly 1 post starting with "Vue"
175175
->where('data.0.attributes.title', $post2->title) // Vue.js Tutorial
176176
->etc()
177177
);
178-
178+
179179
// Test no matches - search for something that doesn't exist
180180
$this->getJson(TestMatchFilterRepository::route(query: ['title' => 'NonExistent']))
181181
->assertStatus(200)
182182
->assertJson(
183-
fn(AssertableJson $json) => $json
183+
fn (AssertableJson $json) => $json
184184
->has('data', 0) // Should have 0 results for non-existent search
185185
->etc()
186186
);
@@ -250,7 +250,7 @@ public function filter(RestifyRequest $request, Builder|Relation $query, $value)
250250
{
251251
// Custom filtering logic: search for titles that start with the given value
252252
$query->where('title', 'like', "{$value}%");
253-
253+
254254
return $query;
255255
}
256256
}
@@ -262,7 +262,7 @@ class TestMatchFilterRepository extends Repository
262262
public function fields(RestifyRequest $request): array
263263
{
264264
return [
265-
Field::make('title')->matchable(new CustomTitleMatchFilter()),
265+
Field::make('title')->matchable(new CustomTitleMatchFilter),
266266
Field::make('description'),
267267
];
268268
}
@@ -271,4 +271,4 @@ public static function uriKey(): string
271271
{
272272
return 'test-match-filter';
273273
}
274-
}
274+
}

tests/Feature/SortableFieldIntegrationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function test_can_sort_using_sortable_fields_via_api(): void
9494
$this->getJson('/api/restify/posts?sort=title')
9595
->assertStatus(200)
9696
->assertJson(
97-
fn(AssertableJson $json) => $json
97+
fn (AssertableJson $json) => $json
9898
->where('data.0.attributes.title', 'Alpha Post')
9999
->where('data.1.attributes.title', 'Beta Post')
100100
->where('data.2.attributes.title', 'Zeta Post')
@@ -105,7 +105,7 @@ public function test_can_sort_using_sortable_fields_via_api(): void
105105
$this->getJson('/api/restify/posts?sort=-title')
106106
->assertStatus(200)
107107
->assertJson(
108-
fn(AssertableJson $json) => $json
108+
fn (AssertableJson $json) => $json
109109
->where('data.0.attributes.title', 'Zeta Post')
110110
->where('data.1.attributes.title', 'Beta Post')
111111
->where('data.2.attributes.title', 'Alpha Post')
@@ -116,7 +116,7 @@ public function test_can_sort_using_sortable_fields_via_api(): void
116116
$this->getJson('/api/restify/posts?sort=is_active')
117117
->assertStatus(200)
118118
->assertJson(
119-
fn(AssertableJson $json) => $json
119+
fn (AssertableJson $json) => $json
120120
->where('data.0.attributes.is_active', false) // false comes first (0 < 1)
121121
->where('data.1.attributes.is_active', true)
122122
->where('data.2.attributes.is_active', true)
@@ -127,7 +127,7 @@ public function test_can_sort_using_sortable_fields_via_api(): void
127127
$this->getJson('/api/restify/posts?sort=-is_active')
128128
->assertStatus(200)
129129
->assertJson(
130-
fn(AssertableJson $json) => $json
130+
fn (AssertableJson $json) => $json
131131
->where('data.0.attributes.is_active', true) // true comes first when descending
132132
->where('data.1.attributes.is_active', true)
133133
->where('data.2.attributes.is_active', false)
@@ -138,7 +138,7 @@ public function test_can_sort_using_sortable_fields_via_api(): void
138138
$this->getJson('/api/restify/posts?sort=-is_active,title')
139139
->assertStatus(200)
140140
->assertJson(
141-
fn(AssertableJson $json) => $json
141+
fn (AssertableJson $json) => $json
142142
// First: is_active = true, ordered by title ASC
143143
->where('data.0.attributes.is_active', true)
144144
->where('data.0.attributes.title', 'Alpha Post') // Alpha comes before Beta

0 commit comments

Comments
 (0)