From 0c9a7540ca96a22afe387fbdc734e7b5d8fd69e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Thu, 28 Nov 2024 17:26:47 +0100 Subject: [PATCH 1/9] feat(import): dynamic form action --- resources/views/pages/import.blade.php | 2 +- src/Http/Controllers/Admin/Traits/HasImportButton.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/import.blade.php b/resources/views/pages/import.blade.php index 2f1a419..c73d818 100644 --- a/resources/views/pages/import.blade.php +++ b/resources/views/pages/import.blade.php @@ -28,7 +28,7 @@
@include('crud::inc.grouped_errors') -
+ @csrf @includeFirst( diff --git a/src/Http/Controllers/Admin/Traits/HasImportButton.php b/src/Http/Controllers/Admin/Traits/HasImportButton.php index 891f957..1167932 100644 --- a/src/Http/Controllers/Admin/Traits/HasImportButton.php +++ b/src/Http/Controllers/Admin/Traits/HasImportButton.php @@ -32,6 +32,7 @@ public function import(): View $this->data['crud'] = $this->crud; $this->data['title'] = $this->crud->getTitle(); + $this->data['action'] = url($this->crud->route . '/import'); return view('backpack-async-export::pages.import', $this->data); } From 6c694506910ee6c49bc55415a332a827208360d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Thu, 28 Nov 2024 17:37:27 +0100 Subject: [PATCH 2/9] style(phpstan): update configuration --- phpstan.neon | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 4db9f1d..2c30cf3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,20 +2,6 @@ includes: - ./vendor/nunomaduro/larastan/extension.neon parameters: - - paths: - - src/ - - # Level 9 is the highest level - level: 6 - -# ignoreErrors: -# - '#PHPDoc tag @var#' -# -# excludePaths: -# - ./*/*/FileToBeExcluded.php -# -# checkMissingIterableValueType: false - checkMissingIterableValueType: false - - checkGenericClassInNonGenericObjectType: false + level: 6 + paths: + - src From daed6ddd4110a8b841df4ca771df4b3088a6eae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Thu, 28 Nov 2024 18:04:15 +0100 Subject: [PATCH 3/9] style(phpstan): ignore errors --- phpstan.neon | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 2c30cf3..f2e6a7a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,3 +5,6 @@ parameters: level: 6 paths: - src + ignoreErrors: + - '#Class [a-zA-Z0-9\\_]+ implements generic interface [a-zA-Z0-9\\_]+ but does not specify its types: [a-zA-Z0-9\\_]+#' + - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) return type with generic class [a-zA-Z0-9\\_]+ does not specify its types: .+#' From 0de99a0a4e243658a8cd82f0e86473539330d7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Thu, 28 Nov 2024 18:04:27 +0100 Subject: [PATCH 4/9] style(phpstan): add phpdoc --- src/Http/Controllers/Admin/Interfaces/ExportableCrud.php | 3 +++ src/Http/Controllers/Admin/Interfaces/ImportableCrud.php | 3 +++ .../Controllers/Admin/Interfaces/MultiExportableCrud.php | 3 +++ src/Http/Requests/ImportRequest.php | 3 +++ src/Jobs/ExportJob.php | 6 ++++-- src/Jobs/ImportJob.php | 3 +++ src/Models/ImportExport.php | 7 +++++-- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Http/Controllers/Admin/Interfaces/ExportableCrud.php b/src/Http/Controllers/Admin/Interfaces/ExportableCrud.php index d5bec1f..ba02f74 100644 --- a/src/Http/Controllers/Admin/Interfaces/ExportableCrud.php +++ b/src/Http/Controllers/Admin/Interfaces/ExportableCrud.php @@ -8,5 +8,8 @@ interface ExportableCrud { public function getExport(): ImportExport; + /** + * @return array + */ public function getExportParameters(): array; } diff --git a/src/Http/Controllers/Admin/Interfaces/ImportableCrud.php b/src/Http/Controllers/Admin/Interfaces/ImportableCrud.php index 3b13f8c..684d2b8 100644 --- a/src/Http/Controllers/Admin/Interfaces/ImportableCrud.php +++ b/src/Http/Controllers/Admin/Interfaces/ImportableCrud.php @@ -8,5 +8,8 @@ interface ImportableCrud { public function getImport(): ImportExport; + /** + * @return array + */ public function getImportParameters(): array; } diff --git a/src/Http/Controllers/Admin/Interfaces/MultiExportableCrud.php b/src/Http/Controllers/Admin/Interfaces/MultiExportableCrud.php index 16c59f3..001142c 100644 --- a/src/Http/Controllers/Admin/Interfaces/MultiExportableCrud.php +++ b/src/Http/Controllers/Admin/Interfaces/MultiExportableCrud.php @@ -7,5 +7,8 @@ interface MultiExportableCrud public const QUERY_PARAM = 'export'; public const DEFAULT_EXPORT_NAME = 'default'; + /** + * @return array + */ public function getAvailableExports(): array; } diff --git a/src/Http/Requests/ImportRequest.php b/src/Http/Requests/ImportRequest.php index 787c586..8f2d9dd 100644 --- a/src/Http/Requests/ImportRequest.php +++ b/src/Http/Requests/ImportRequest.php @@ -8,6 +8,9 @@ class ImportRequest extends FormRequest { const PARAM_FILE = 'file'; + /** + * @return array + */ public function rules(): array { return [ diff --git a/src/Jobs/ExportJob.php b/src/Jobs/ExportJob.php index 05dc43d..3778629 100644 --- a/src/Jobs/ExportJob.php +++ b/src/Jobs/ExportJob.php @@ -26,9 +26,11 @@ class ExportJob implements ShouldQueue use SerializesModels; private ImportExport $export; - private array $exportParameters; - public function __construct(ImportExport $export, array $exportParameters) + /** + * @param array $exportParameters + */ + public function __construct(ImportExport $export, private array $exportParameters) { $this->export = $export; $this->exportParameters = $exportParameters; diff --git a/src/Jobs/ImportJob.php b/src/Jobs/ImportJob.php index 2136d8a..4a259df 100644 --- a/src/Jobs/ImportJob.php +++ b/src/Jobs/ImportJob.php @@ -21,6 +21,9 @@ class ImportJob implements ShouldQueue use Queueable; use SerializesModels; + /** + * @param array $exportParameters + */ public function __construct( private ImportExport $export, private array $exportParameters diff --git a/src/Models/ImportExport.php b/src/Models/ImportExport.php index d3012f5..58f22db 100644 --- a/src/Models/ImportExport.php +++ b/src/Models/ImportExport.php @@ -59,6 +59,9 @@ class ImportExport extends Model implements ImportExportInterface self::COLUMN_STATUS => ImportExportStatus::class, ]; + /** + * @var array|string[] + */ protected array $dates = [ self::COLUMN_COMPLETED_AT, ]; @@ -68,7 +71,7 @@ public function user(): BelongsTo return $this->belongsTo(config('backpack-async-import-export.user_model')); } - protected static function boot() + protected static function boot(): void { parent::boot(); ImportExport::saving(function (ImportExport $export) { @@ -128,7 +131,7 @@ public function getDownloadButton(): string protected function isReady(): Attribute { return Attribute::make( - get: fn (): bool => ImportExportStatus::Successful === $this->{ImportExport::COLUMN_STATUS} + get: fn(): bool => ImportExportStatus::Successful === $this->{ImportExport::COLUMN_STATUS} && Storage::disk($this->disk)->exists($this->{self::COLUMN_FILENAME}), ); } From bd9653e7506042334c35dc4dacefd30aec057a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Fri, 29 Nov 2024 09:04:38 +0100 Subject: [PATCH 5/9] build(composer): remove spatie/laravel-ray --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index f87b7f7..ca31777 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,6 @@ "orchestra/testbench": "^9.0", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.1", - "spatie/laravel-ray": "^1.30", "squizlabs/php_codesniffer": "^3.7", "vimeo/psalm": "^5.0" }, From 9011f984fe503c36110db27cfa36fd0552959943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Fri, 29 Nov 2024 09:06:06 +0100 Subject: [PATCH 6/9] build(composer): upgrade PHPStan --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ca31777..a503490 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ "require-dev": { "laravel/scout": "^10.10", "nunomaduro/collision": "^8.1", - "nunomaduro/larastan": "^2.0", + "nunomaduro/larastan": "^3.0", "orchestra/testbench": "^9.0", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^10.1", "squizlabs/php_codesniffer": "^3.7", "vimeo/psalm": "^5.0" From a05587fc674abba0d6e859c5386918bbdbbaa0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Fri, 29 Nov 2024 09:49:10 +0100 Subject: [PATCH 7/9] style(phpstan): ignore errors --- phpstan.neon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index f2e6a7a..8061fae 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,5 @@ parameters: ignoreErrors: - '#Class [a-zA-Z0-9\\_]+ implements generic interface [a-zA-Z0-9\\_]+ but does not specify its types: [a-zA-Z0-9\\_]+#' - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) return type with generic class [a-zA-Z0-9\\_]+ does not specify its types: .+#' + - '#Trait [a-zA-Z0-9\\_]+ is used zero times and is not analysed.#' + - '#Unable to resolve the template type TRelatedModel in call to method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#' From 63ce9cc0d29dcde623742cc6f30403f60c5fdcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Fri, 29 Nov 2024 09:49:44 +0100 Subject: [PATCH 8/9] fix(phpstan): dead catch - exception is never thrown in the try block --- src/Jobs/ImportJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jobs/ImportJob.php b/src/Jobs/ImportJob.php index 4a259df..6a8f16d 100644 --- a/src/Jobs/ImportJob.php +++ b/src/Jobs/ImportJob.php @@ -73,7 +73,7 @@ public function handle(): void ->implode(', '); throw new \Exception($message); } - } catch (\Exception|\Throwable $exception) { + } catch (\Throwable $exception) { $this->export->update([ ImportExport::COLUMN_STATUS => ImportExportStatus::Error, ImportExport::COLUMN_ERROR => $exception->getMessage(), From d5ce26f1d477a3fe24c0bd4263934d0f911d7224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20ARGOUD?= Date: Fri, 29 Nov 2024 09:58:26 +0100 Subject: [PATCH 9/9] refactor(import): use configuration --- src/Http/Controllers/Admin/Traits/HasImportButton.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Http/Controllers/Admin/Traits/HasImportButton.php b/src/Http/Controllers/Admin/Traits/HasImportButton.php index 1167932..2ca69fb 100644 --- a/src/Http/Controllers/Admin/Traits/HasImportButton.php +++ b/src/Http/Controllers/Admin/Traits/HasImportButton.php @@ -32,7 +32,9 @@ public function import(): View $this->data['crud'] = $this->crud; $this->data['title'] = $this->crud->getTitle(); - $this->data['action'] = url($this->crud->route . '/import'); + $this->data['action'] = url( + $this->crud->route . '/' . config('backpack-async-import-export.admin_import_route'), + ); return view('backpack-async-export::pages.import', $this->data); }