Skip to content

Commit 52671f9

Browse files
committed
fix: pint
1 parent 0b46483 commit 52671f9

8 files changed

+85
-117
lines changed

src/DataTablesEditor.php

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ abstract class DataTablesEditor
9696
/**
9797
* Process dataTables editor action request.
9898
*
99-
* @param Request $request
10099
* @return JsonResponse|mixed
101100
*
102101
* @throws DataTablesEditorException
@@ -113,7 +112,7 @@ public function process(Request $request)
113112
return $this->{$this->action}($request);
114113
} catch (Exception $exception) {
115114
$error = config('app.debug')
116-
? '<strong>Server Error:</strong> ' . $exception->getMessage()
115+
? '<strong>Server Error:</strong> '.$exception->getMessage()
117116
: $this->getUseFriendlyErrorMessage();
118117

119118
app('log')->error($exception);
@@ -133,8 +132,6 @@ protected function getUseFriendlyErrorMessage()
133132
/**
134133
* Display success data in dataTables editor format.
135134
*
136-
* @param array $data
137-
* @param array $errors
138135
* @param string $error
139136
* @return JsonResponse
140137
*/
@@ -144,16 +141,16 @@ protected function toJson(array $data, array $errors = [], $error = '')
144141

145142
$response = [
146143
'action' => $this->action,
147-
'data' => $data,
144+
'data' => $data,
148145
];
149146

150147
if ($error) {
151-
$code = 422;
148+
$code = 422;
152149
$response['error'] = $error;
153150
}
154151

155152
if ($errors) {
156-
$code = 422;
153+
$code = 422;
157154
$response['fieldErrors'] = $errors;
158155
}
159156

@@ -163,29 +160,28 @@ protected function toJson(array $data, array $errors = [], $error = '')
163160
/**
164161
* Process create action request.
165162
*
166-
* @param Request $request
167163
* @return JsonResponse
168164
*
169165
* @throws \Exception
170166
*/
171167
public function create(Request $request)
172168
{
173-
$model = $this->resolveModel();
169+
$model = $this->resolveModel();
174170
$connection = $model->getConnection();
175-
$affected = [];
176-
$errors = [];
171+
$affected = [];
172+
$errors = [];
177173

178174
$connection->beginTransaction();
179175
foreach ($request->get('data') as $data) {
180176
$this->currentData = $data;
181177

182-
$instance = $model->newInstance();
178+
$instance = $model->newInstance();
183179
$validator = $this->getValidationFactory()
184-
->make(
185-
$data,
186-
$this->createRules(), $this->messages() + $this->createMessages(),
187-
$this->attributes()
188-
);
180+
->make(
181+
$data,
182+
$this->createRules(), $this->messages() + $this->createMessages(),
183+
$this->attributes()
184+
);
189185
if ($validator->fails()) {
190186
foreach ($this->formatErrors($validator) as $error) {
191187
$errors[] = $error;
@@ -284,7 +280,6 @@ public function attributes()
284280
}
285281

286282
/**
287-
* @param Validator $validator
288283
* @return array
289284
*/
290285
protected function formatErrors(Validator $validator)
@@ -293,7 +288,7 @@ protected function formatErrors(Validator $validator)
293288

294289
collect($validator->errors())->each(function ($error, $key) use (&$errors) {
295290
$errors[] = [
296-
'name' => $key,
291+
'name' => $key,
297292
'status' => $error[0],
298293
];
299294
});
@@ -304,7 +299,6 @@ protected function formatErrors(Validator $validator)
304299
/**
305300
* Process restore action request.
306301
*
307-
* @param \Illuminate\Http\Request $request
308302
* @return \Illuminate\Http\JsonResponse
309303
*/
310304
public function restore(Request $request)
@@ -317,26 +311,25 @@ public function restore(Request $request)
317311
/**
318312
* Process edit action request.
319313
*
320-
* @param Request $request
321314
* @return JsonResponse
322315
*/
323316
public function edit(Request $request)
324317
{
325318
$connection = $this->getBuilder()->getConnection();
326-
$affected = [];
327-
$errors = [];
319+
$affected = [];
320+
$errors = [];
328321

329322
$connection->beginTransaction();
330323
foreach ($request->get('data') as $key => $data) {
331324
$this->currentData = $data;
332325

333-
$model = $this->getBuilder()->findOrFail($key);
326+
$model = $this->getBuilder()->findOrFail($key);
334327
$validator = $this->getValidationFactory()
335-
->make(
336-
$data,
337-
$this->editRules($model), $this->messages() + $this->editMessages(),
338-
$this->attributes()
339-
);
328+
->make(
329+
$data,
330+
$this->editRules($model), $this->messages() + $this->editMessages(),
331+
$this->attributes()
332+
);
340333
if ($validator->fails()) {
341334
foreach ($this->formatErrors($validator) as $error) {
342335
$errors[] = $error;
@@ -395,7 +388,6 @@ protected function getBuilder()
395388
/**
396389
* Get edit action validation rules.
397390
*
398-
* @param Model $model
399391
* @return array
400392
*/
401393
public function editRules(Model $model)
@@ -418,7 +410,6 @@ protected function editMessages()
418410
/**
419411
* Process force delete action request.
420412
*
421-
* @param \Illuminate\Http\Request $request
422413
* @return \Illuminate\Http\JsonResponse
423414
*
424415
* @throws \Exception
@@ -433,28 +424,27 @@ public function forceDelete(Request $request)
433424
/**
434425
* Process remove action request.
435426
*
436-
* @param Request $request
437427
* @return JsonResponse
438428
*
439429
* @throws \Exception
440430
*/
441431
public function remove(Request $request)
442432
{
443433
$connection = $this->getBuilder()->getConnection();
444-
$affected = [];
445-
$errors = [];
434+
$affected = [];
435+
$errors = [];
446436

447437
$connection->beginTransaction();
448438
foreach ($request->get('data') as $key => $data) {
449439
$this->currentData = $data;
450440

451-
$model = $this->getBuilder()->findOrFail($key);
441+
$model = $this->getBuilder()->findOrFail($key);
452442
$validator = $this->getValidationFactory()
453-
->make(
454-
$data,
455-
$this->removeRules($model), $this->messages() + $this->removeMessages(),
456-
$this->attributes()
457-
);
443+
->make(
444+
$data,
445+
$this->removeRules($model), $this->messages() + $this->removeMessages(),
446+
$this->attributes()
447+
);
458448
if ($validator->fails()) {
459449
foreach ($this->formatErrors($validator) as $error) {
460450
$errors[] = $error['status'];
@@ -502,7 +492,6 @@ public function remove(Request $request)
502492
/**
503493
* Get remove action validation rules.
504494
*
505-
* @param Model $model
506495
* @return array
507496
*/
508497
public function removeRules(Model $model)
@@ -525,8 +514,6 @@ protected function removeMessages()
525514
/**
526515
* Get remove query exception message.
527516
*
528-
* @param QueryException $exception
529-
* @param Model $model
530517
* @return string
531518
*/
532519
protected function removeExceptionMessage(QueryException $exception, Model $model)
@@ -573,39 +560,38 @@ public function unguard($state = true)
573560
/**
574561
* Handle uploading of file.
575562
*
576-
* @param \Illuminate\Http\Request $request
577563
* @return \Illuminate\Http\JsonResponse
578564
*/
579565
public function upload(Request $request)
580566
{
581-
$field = $request->input('uploadField');
567+
$field = $request->input('uploadField');
582568
$storage = $this->getDisk();
583569

584570
try {
585-
$rules = $this->uploadRules();
571+
$rules = $this->uploadRules();
586572
$fieldRules = ['upload' => $rules[$field] ?? []];
587573

588574
$this->validate($request, $fieldRules, $this->messages(), $this->attributes());
589575

590576
$uploadedFile = $request->file('upload');
591-
$id = $this->storeUploadedFile($field, $uploadedFile);
577+
$id = $this->storeUploadedFile($field, $uploadedFile);
592578

593579
if (method_exists($this, 'uploaded')) {
594580
$id = $this->uploaded($id);
595581
}
596582

597583
return response()->json([
598584
'action' => $this->action,
599-
'data' => [],
600-
'files' => [
585+
'data' => [],
586+
'files' => [
601587
'files' => [
602588
$id => [
603-
'filename' => $id,
589+
'filename' => $id,
604590
'original_name' => $uploadedFile->getClientOriginalName(),
605-
'size' => $uploadedFile->getSize(),
606-
'directory' => $this->getUploadDirectory(),
607-
'disk' => $this->disk,
608-
'url' => $storage->url($id),
591+
'size' => $uploadedFile->getSize(),
592+
'directory' => $this->getUploadDirectory(),
593+
'disk' => $this->disk,
594+
'url' => $storage->url($id),
609595
],
610596
],
611597
],
@@ -615,11 +601,11 @@ public function upload(Request $request)
615601
]);
616602
} catch (ValidationException $exception) {
617603
return response()->json([
618-
'action' => $this->action,
619-
'data' => [],
604+
'action' => $this->action,
605+
'data' => [],
620606
'fieldErrors' => [
621607
[
622-
'name' => $field,
608+
'name' => $field,
623609
'status' => str_replace('upload', $field, $exception->errors()['upload'][0]),
624610
],
625611
],
@@ -639,12 +625,11 @@ public function uploadRules()
639625

640626
/**
641627
* @param string $field
642-
* @param UploadedFile $uploadedFile
643628
* @return string
644629
*/
645630
protected function getUploadedFilename($field, UploadedFile $uploadedFile)
646631
{
647-
return date('Ymd_His') . '_' . $uploadedFile->getClientOriginalName();
632+
return date('Ymd_His').'_'.$uploadedFile->getClientOriginalName();
648633
}
649634

650635
/**
@@ -665,7 +650,6 @@ protected function getDisk()
665650

666651
/**
667652
* @param string $field
668-
* @param UploadedFile $uploadedFile
669653
* @return false|string
670654
*/
671655
protected function storeUploadedFile($field, UploadedFile $uploadedFile)

0 commit comments

Comments
 (0)