Skip to content

Commit 0d0d63e

Browse files
authored
Merge pull request #60 from chrillep/feat/laravel-pint
add linting using laravel/pint -> https://laravel.com/docs/10.x/pint
2 parents 8498979 + 0afac58 commit 0d0d63e

File tree

13 files changed

+48
-44
lines changed

13 files changed

+48
-44
lines changed

composer.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
"laravel/nova": "^4.0",
1212
"maatwebsite/excel": "^3.1"
1313
},
14+
"require-dev": {
15+
"laravel/pint": "^1.6"
16+
},
1417
"autoload": {
1518
"psr-4": {
1619
"SimonHamp\\LaravelNovaCsvImport\\": "src/"
1720
}
1821
},
22+
"scripts": {
23+
"lint": "@pint",
24+
"lint:test": "@pint --test",
25+
"lint:dirty": "@pint --dirty",
26+
"pint": "vendor/bin/pint"
27+
},
1928
"extra": {
2029
"laravel": {
2130
"providers": [

src/Concerns/HasModifiers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ protected function modifyValue($value = null, array $modifiers = [])
7878
$value = $instance->handle($value, $modifier['settings'] ?? []);
7979
}
8080

81-
8281
return $value;
8382
}
8483

@@ -104,4 +103,4 @@ protected function formatModifierSettings(array $settings = [])
104103

105104
return $normalised_settings;
106105
}
107-
}
106+
}

src/Http/Controllers/ImportController.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace SimonHamp\LaravelNovaCsvImport\Http\Controllers;
44

5-
use Illuminate\Support\Collection;
65
use Illuminate\Contracts\Filesystem\Filesystem;
7-
use Illuminate\Validation\ValidationException;
6+
use Illuminate\Support\Collection;
87
use Inertia\Response;
8+
use Laravel\Nova\Actions\ActionResource;
9+
use Laravel\Nova\Fields\Field;
10+
use Laravel\Nova\Http\Requests\NovaRequest;
911
use Laravel\Nova\Nova;
1012
use Laravel\Nova\Resource;
11-
use Laravel\Nova\Fields\Field;
1213
use Laravel\Nova\Rules\Relatable;
13-
use Laravel\Nova\Actions\ActionResource;
14-
use Laravel\Nova\Http\Requests\NovaRequest;
1514
use Maatwebsite\Excel\Concerns\ToModel as ModelImporter;
1615

1716
class ImportController
@@ -43,15 +42,15 @@ public function configure(NovaRequest $request, string $file): Response
4342

4443
$rows = $import->take(10)->all();
4544

46-
$resources = $this->getAvailableResourcesForImport($request);
45+
$resources = $this->getAvailableResourcesForImport($request);
4746

4847
$fields = $resources->mapWithKeys(function ($resource) use ($request) {
4948
return $this->getAvailableFieldsForImport($resource, $request);
5049
});
5150

5251
$resources = $resources->mapWithKeys(function ($resource) {
5352
return [
54-
$resource::uriKey() => $resource::label()
53+
$resource::uriKey() => $resource::label(),
5554
];
5655
});
5756

@@ -64,7 +63,6 @@ public function configure(NovaRequest $request, string $file): Response
6463
}
6564

6665
/**
67-
*
6866
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
6967
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
7068
*/
@@ -86,7 +84,7 @@ public function storeConfig(NovaRequest $request)
8684
->reject(function ($modifier) {
8785
return empty($modifier['name']);
8886
});
89-
})
87+
}),
9088
],
9189
),
9290
JSON_PRETTY_PRINT
@@ -201,8 +199,8 @@ protected function getAvailableFieldsForImport(string $resource, NovaRequest $re
201199
$fieldsCollection = collect($novaResource->creationFields($request));
202200

203201
if (method_exists($novaResource, 'excludeAttributesFromImport')) {
204-
$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) {
205-
return !in_array($field->attribute, $novaResource::excludeAttributesFromImport($request));
202+
$fieldsCollection = $fieldsCollection->filter(function (Field $field) use ($novaResource, $request) {
203+
return ! in_array($field->attribute, $novaResource::excludeAttributesFromImport($request));
206204
});
207205
}
208206

@@ -213,8 +211,8 @@ protected function getAvailableFieldsForImport(string $resource, NovaRequest $re
213211
'rules' => $this->extractValidationRules($novaResource, $request)->get($field->attribute),
214212
];
215213
});
216-
217-
// Note: ->values() is used here to avoid this array being turned into an object due to
214+
215+
// Note: ->values() is used here to avoid this array being turned into an object due to
218216
// non-sequential keys (which might happen due to the filtering above.
219217
return [
220218
$novaResource->uriKey() => $fields->values(),
@@ -230,19 +228,19 @@ protected function getAvailableResourcesForImport(NovaRequest $request): Collect
230228
return false;
231229
}
232230

233-
if (!isset($resource::$model)) {
231+
if (! isset($resource::$model)) {
234232
return false;
235233
}
236-
234+
237235
$resourceReflection = (new \ReflectionClass((string) $resource));
238-
236+
239237
if ($resourceReflection->hasMethod('canImportResource')) {
240238
return $resource::canImportResource($request);
241239
}
242240

243241
$static_vars = $resourceReflection->getStaticProperties();
244242

245-
if (!isset($static_vars['canImportResource'])) {
243+
if (! isset($static_vars['canImportResource'])) {
246244
return true;
247245
}
248246

@@ -262,6 +260,7 @@ protected function extractValidationRules(Resource $resource, NovaRequest $reque
262260
if (is_a($r, Relatable::class)) {
263261
$rule[$i] = function () use ($r) {
264262
$r->query = $r->query->newQuery();
263+
265264
return $r;
266265
};
267266
}

src/Http/Controllers/UploadController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace SimonHamp\LaravelNovaCsvImport\Http\Controllers;
44

55
use Illuminate\Contracts\Filesystem\Filesystem;
6-
use Illuminate\Support\Facades\Log;
76
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Facades\Log;
88
use Illuminate\Support\Facades\Validator;
99
use Laravel\Nova\Http\Requests\NovaRequest;
1010
use Maatwebsite\Excel\Concerns\ToModel as ModelImporter;
@@ -35,7 +35,7 @@ public function handle(NovaRequest $request): Response
3535
$this->importer->toCollection($file);
3636
} catch (\Exception $e) {
3737
Log::error('Failed to parse uploaded file', [$e]);
38-
38+
3939
return response()->json(['message' => 'Sorry, we could not import that file'], 422);
4040
}
4141

@@ -58,7 +58,7 @@ public function handle(NovaRequest $request): Response
5858
);
5959

6060
return response()->json([
61-
'configure' => "/csv-import/configure/{$new_filename}"
61+
'configure' => "/csv-import/configure/{$new_filename}",
6262
]);
6363
}
6464
}

src/Http/Middleware/Authorize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function handle($request, $next)
2424
/**
2525
* Determine whether this tool belongs to the package.
2626
*
27-
* @param \Laravel\Nova\Tool $tool
27+
* @param \Laravel\Nova\Tool $tool
2828
* @return bool
2929
*/
3030
public function matchesTool($tool)

src/Importer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
use Maatwebsite\Excel\Concerns\WithValidation;
2020
use SimonHamp\LaravelNovaCsvImport\Concerns\HasModifiers;
2121

22-
class Importer implements ToModel, WithValidation, WithHeadingRow, WithMapping, WithBatchInserts, WithChunkReading,
23-
SkipsOnFailure, SkipsOnError, SkipsEmptyRows
22+
class Importer implements ToModel, WithValidation, WithHeadingRow, WithMapping, WithBatchInserts, WithChunkReading, SkipsOnFailure, SkipsOnError, SkipsEmptyRows
2423
{
2524
use Importable, SkipsFailures, SkipsErrors, HasModifiers;
2625

27-
/** @var Resource */
28-
protected $resource;
26+
protected Resource $resource;
2927

3028
protected $attribute_map = [];
3129

src/LaravelNovaCsvImport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace SimonHamp\LaravelNovaCsvImport;
44

5-
use Laravel\Nova\Nova;
6-
use Laravel\Nova\Tool;
75
use Illuminate\Http\Request;
86
use Laravel\Nova\Menu\MenuSection;
7+
use Laravel\Nova\Nova;
8+
use Laravel\Nova\Tool;
99

1010
class LaravelNovaCsvImport extends Tool
1111
{

src/Modifiers/ExcelDate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public function title(): string
1414

1515
public function description(): string
1616
{
17-
return "Interprets the given value as an Excel date-time float and converts it to a DateTime object
18-
and formatted according to the supplied `format` setting";
17+
return 'Interprets the given value as an Excel date-time float and converts it to a DateTime object
18+
and formatted according to the supplied `format` setting';
1919
}
2020

2121
public function settings(): array
@@ -24,7 +24,7 @@ public function settings(): array
2424
'format' => [
2525
'type' => 'string',
2626
'default' => 'Y-m-d H:i:s',
27-
]
27+
],
2828
];
2929
}
3030

src/Modifiers/Hash.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function title(): string
1313

1414
public function description(): string
1515
{
16-
return "Hash the value using the given hashing algorithm.";
16+
return 'Hash the value using the given hashing algorithm.';
1717
}
1818

1919
public function settings(): array

src/Modifiers/Prefix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function title(): string
1414

1515
public function description(): string
1616
{
17-
return "Prefix each row with a given string";
17+
return 'Prefix each row with a given string';
1818
}
1919

2020
public function settings(): array

0 commit comments

Comments
 (0)