Skip to content

Commit 317b4e9

Browse files
fix(Bulk Update): Only Validate Data for Current Item in Loop (#612)
* fix(Bulk Update): Only Validate Data for Current Item in Loop * Fix styling * Run pint * Fix styling --------- Co-authored-by: arthurkirkosa <[email protected]>
1 parent ab53475 commit 317b4e9

26 files changed

+52
-52
lines changed

src/Commands/PublishAuthCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function checkDirectory(string $path): self
6868

6969
protected function copyDirectory(string $path, string $stubDirectory, string $format, ?array $actions = []): self
7070
{
71-
$filesystem = new Filesystem();
71+
$filesystem = new Filesystem;
7272

7373
collect($filesystem->allFiles(__DIR__.$stubDirectory))
7474
->filter(function (SplFileInfo $file) use ($actions) {

src/Fields/Concerns/Attachable.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function authorizeToAttach(RestifyRequest $request)
8989
);
9090

9191
if (! $this->authorizedToAttach($request, $pivot)) {
92-
throw new AuthorizationException();
92+
throw new AuthorizationException;
9393
}
9494
});
9595

@@ -106,7 +106,7 @@ public function authorizeToSync(RestifyRequest $request)
106106
);
107107

108108
if (! $this->authorizedToSync($request, $pivot)) {
109-
throw new AuthorizationException();
109+
throw new AuthorizationException;
110110
}
111111
});
112112

@@ -123,7 +123,7 @@ public function authorizedToDetach(RestifyRequest $request, Pivot $pivot): bool
123123
public function authorizeToDetach(RestifyRequest $request, Pivot $pivot)
124124
{
125125
if (! $this->authorizedToDetach($request, $pivot)) {
126-
throw new AuthorizationException();
126+
throw new AuthorizationException;
127127
}
128128

129129
return $this;
@@ -156,8 +156,8 @@ public function initializePivot(RestifyRequest $request, $relationship, $related
156156

157157
if ($relationship->withTimestamps) {
158158
$pivot->forceFill([
159-
$relationship->createdAt() => new DateTime(),
160-
$relationship->updatedAt() => new DateTime(),
159+
$relationship->createdAt() => new DateTime,
160+
$relationship->updatedAt() => new DateTime,
161161
]);
162162
}
163163

src/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __invoke(Request $request)
2929
$request->input('url') ?? config('restify.auth.password_reset_url')
3030
);
3131

32-
(new AnonymousNotifiable())->route('mail', $user->email)->notify(new ForgotPasswordNotification($url));
32+
(new AnonymousNotifiable)->route('mail', $user->email)->notify(new ForgotPasswordNotification($url));
3333

3434
return ok(__('Reset password link sent to your email.'));
3535
}

src/Http/Controllers/RepositoryUpdateBulkController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __invoke(RepositoryUpdateBulkRequest $request)
2121
$repository = $request->repositoryWith($model);
2222

2323
return $repository
24-
->allowToUpdateBulk($request)
24+
->allowToUpdateBulk($request, $item)
2525
->updateBulk(
2626
$request,
2727
$id,

src/Http/Controllers/RestResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ public function __call($func, $args)
252252
public function respond($response = null): JsonResponse
253253
{
254254
if (! func_num_args()) {
255-
$response = new \stdClass();
256-
$response->data = new \stdClass();
255+
$response = new \stdClass;
256+
$response->data = new \stdClass;
257257

258258
foreach (static::$RESPONSE_DEFAULT_ATTRIBUTES as $property) {
259259
if (isset($this->{$property})) {
@@ -537,7 +537,7 @@ public function model(Model $model): self
537537

538538
public static function created()
539539
{
540-
return (new self())->code(201);
540+
return (new self)->code(201);
541541
}
542542

543543
public static function index(AbstractPaginator|Paginator $paginator, array $meta = []): JsonResponse

src/LaravelRestifyServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function packageRegistered(): void
6262

6363
// Register the main class to use with the facade
6464
$this->app->singleton('laravel-restify', function () {
65-
return new Restify();
65+
return new Restify;
6666
});
6767
}
6868

src/Repositories/ValidatingTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static function validatorForUpdateBulk(RestifyRequest $request, $resource
171171
})->toArray();
172172

173173
return Validator::make(
174-
$plainPayload ?? $request->all(),
174+
[$plainPayload] ?? $request->all(),
175175
$on->getUpdatingBulkRules($request),
176176
$messages
177177
)->after(function ($validator) use ($request) {

src/Restify.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static function repositories(array $repositories)
132132
(new BootRepository($repository))->boot();
133133
});
134134

135-
return new static();
135+
return new static;
136136
}
137137

138138
/**
@@ -149,7 +149,7 @@ public static function repositoriesFrom(string $directory, string $namespace): v
149149
return;
150150
}
151151

152-
foreach ((new Finder())->in($directory)->files() as $repository) {
152+
foreach ((new Finder)->in($directory)->files() as $repository) {
153153
$repository = $namespace.str_replace(
154154
['/', '.php'],
155155
['\\', ''],

src/RestifyApplicationServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function routes(): void
133133
protected function singleton(): void
134134
{
135135
if (! App::runningUnitTests()) {
136-
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto());
136+
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto);
137137
}
138138
}
139139
}

src/Services/Search/RepositorySearchService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ protected function applyFilters(RestifyRequest $request, Repository $repository,
219219

220220
public static function make(): static
221221
{
222-
return new static();
222+
return new static;
223223
}
224224
}

src/Traits/AuthorizableModels.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public function authorizeToSync(Request $request, $method, Collection $keys): bo
145145
public function authorizeToDetach(Request $request, $method, $model)
146146
{
147147
if (! static::authorizable()) {
148-
throw new AuthorizationException();
148+
throw new AuthorizationException;
149149
}
150150

151151
$authorized = method_exists(Gate::getPolicyFor($this->model()), $method)
152152
? Gate::check($method, [$this->model(), $model])
153153
: false;
154154

155155
if ($authorized === false) {
156-
throw new AuthorizationException();
156+
throw new AuthorizationException;
157157
}
158158
}
159159

@@ -194,7 +194,7 @@ public function authorizedToDelete(Request $request): bool
194194
public function authorizeTo(Request $request, iterable|string $ability): void
195195
{
196196
if ($this->authorizedTo($request, $ability) === false) {
197-
throw new AuthorizationException();
197+
throw new AuthorizationException;
198198
}
199199
}
200200

@@ -213,6 +213,6 @@ public function authorizedTo(Request $request, iterable|string $ability): bool
213213

214214
public static function isRepositoryContext(): bool
215215
{
216-
return new static() instanceof Repository;
216+
return new static instanceof Repository;
217217
}
218218
}

src/Traits/AuthorizesRequests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function auth($callback)
2121
{
2222
static::$authUsing = $callback;
2323

24-
return new static();
24+
return new static;
2525
}
2626

2727
/**

src/Traits/InteractWithSQLight.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function resolveConnection($connection = null)
1919

2020
public static function bootSushi()
2121
{
22-
$instance = (new static());
22+
$instance = (new static);
2323
$cacheFileName = 'sushi-'.Str::kebab(str_replace('\\', '', static::class)).'.sqlite';
2424
$cacheDirectory = realpath(config('sushi.cache-path', storage_path('framework/cache')));
2525
$cachePath = $cacheDirectory.'/'.$cacheFileName;

src/Traits/InteractWithSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function collectFilters($type): Collection
113113

114114
return $type instanceof Filter
115115
? tap($type, fn ($filter) => $filter->column = $filter->column ?? $column)
116-
: tap(new $base(), function (Filter $filter) use ($column, $type) {
116+
: tap(new $base, function (Filter $filter) use ($column, $type) {
117117
$filter->type = $type ? $type : 'value';
118118
$filter->column = $column;
119119
});

tests/Actions/FieldActionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FieldActionTest extends IntegrationTestCase
1616
#[Test]
1717
public function can_use_actionable_field(): void
1818
{
19-
$action = new class() extends Action
19+
$action = new class extends Action
2020
{
2121
public bool $showOnShow = true;
2222

@@ -56,7 +56,7 @@ public function handle(RestifyRequest $request, Post $post)
5656
#[Test]
5757
public function can_use_actionable_field_on_bulk_store(): void
5858
{
59-
$action = new class() extends Action
59+
$action = new class extends Action
6060
{
6161
public bool $showOnShow = true;
6262

@@ -101,7 +101,7 @@ public function handle(RestifyRequest $request, Post $post, int $row)
101101
#[Test]
102102
public function can_use_actionable_field_on_bulk_update(): void
103103
{
104-
$action = new class() extends Action
104+
$action = new class extends Action
105105
{
106106
public bool $showOnShow = true;
107107

tests/Actions/PerformActionControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function test_could_perform_action_using_all(): void
6464
PostRepository::partialMock()
6565
->shouldReceive('actions')
6666
->andReturn([
67-
new class() extends Action
67+
new class extends Action
6868
{
6969
public static $uriKey = 'publish';
7070

tests/Controllers/Index/IndexRelatedFeatureTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function setUp(): void
3434
{
3535
parent::setUp();
3636

37-
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto());
37+
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto);
3838
}
3939

4040
public function test_can_retrieve_nested_relationships(): void
@@ -45,7 +45,7 @@ public function test_can_retrieve_nested_relationships(): void
4545
'owner',
4646
'users' => HasMany::make('users', UserRepository::class),
4747
'extraData' => fn () => ['country' => 'Romania'],
48-
'extraMeta' => new InvokableExtraMeta(),
48+
'extraMeta' => new InvokableExtraMeta,
4949
]);
5050

5151
UserRepository::partialMock()

tests/Controllers/RepositoryAttachControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function test_many_to_many_field_can_intercept_attach_method(): void
186186

187187
return true;
188188
})
189-
->attachCallback(new AttachInvokable()),
189+
->attachCallback(new AttachInvokable),
190190
]);
191191

192192
$this->postJson(CompanyRepository::route("$company->id/attach/users"), [

tests/Feature/ActionLogTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function test_can_create_log_for_repository_custom_action(): void
105105

106106
$user = User::factory()->create();
107107

108-
$action = new class() extends Action
108+
$action = new class extends Action
109109
{
110110
public static $uriKey = 'test action';
111111
};

tests/Feature/Filters/MatchFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MatchFilterTest extends IntegrationTestCase
1616
{
1717
public function test_matchable_filter_has_key(): void
1818
{
19-
$filter = new class() extends MatchFilter
19+
$filter = new class extends MatchFilter
2020
{
2121
public ?string $column = 'approved_at';
2222
};

0 commit comments

Comments
 (0)