From 2e7576c52b4ea21b3cfe409e0c7184a2f38f682b Mon Sep 17 00:00:00 2001 From: lrljoe Date: Mon, 1 Jul 2024 13:40:47 +0100 Subject: [PATCH] Two improvements to improve typehinting, migrate to larastan/larastan, cleanup of test --- composer.json | 2 +- phpstan.neon | 6 +++--- src/LaravelLivewireTablesServiceProvider.php | 2 +- src/Traits/Helpers/TableAttributeHelpers.php | 4 ++-- tests/Views/Columns/LinkColumnTest.php | 6 ++---- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index d3e9e6372..bda267c29 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "laravel/pint": "^1.10", "monolog/monolog": "*", "nunomaduro/collision": "^6.0|^7.0|^8.0", - "nunomaduro/larastan": "^2.6", + "larastan/larastan": "^2.6", "orchestra/testbench": "^7.0|^8.0|^9.0", "phpunit/phpunit": "^9.0|^10.0|^11.0" }, diff --git a/phpstan.neon b/phpstan.neon index 7ed8f5027..a0324459d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - vendor/nunomaduro/larastan/extension.neon + - vendor/larastan/larastan/extension.neon parameters: paths: @@ -10,11 +10,11 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false treatPhpDocTypesAsCertain: false reportUnmatchedIgnoredErrors: false - checkGenericClassInNonGenericObjectType: false ignoreErrors: + - identifier: missingType.generics + - identifier: missingType.iterableValue - '#Access to an undefined property Rappasoft\\LaravelLivewireTables\\Views\\Column\:\:\$view#' - "#Unsafe usage of new static#" - '#on array\, mixed\>\> in empty\(\) does not exist.#' diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index c3c32fe2d..e10027b51 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -44,7 +44,7 @@ public function boot(): void } - public function consoleCommands() + public function consoleCommands(): void { if ($this->app->runningInConsole()) { diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 3da2da12e..866e72526 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -84,12 +84,12 @@ public function hasTableRowUrl(): bool return $this->trUrlCallback !== null; } - public function getTableRowUrl($row): ?string + public function getTableRowUrl(int|Model $row): ?string { return $this->trUrlCallback ? call_user_func($this->trUrlCallback, $row) : null; } - public function getTableRowUrlTarget($row): ?string + public function getTableRowUrlTarget(int|Model $row): ?string { return $this->trUrlTargetCallback ? call_user_func($this->trUrlTargetCallback, $row) : null; } diff --git a/tests/Views/Columns/LinkColumnTest.php b/tests/Views/Columns/LinkColumnTest.php index 4a204c0ff..d981d7aad 100644 --- a/tests/Views/Columns/LinkColumnTest.php +++ b/tests/Views/Columns/LinkColumnTest.php @@ -44,8 +44,7 @@ public function test_can_render_field_if_title_and_location_callback(): void $this->assertNotEmpty($column); } - /** @test */ - public function can_check_ishtml_from_html_column(): void + public function test_can_check_ishtml_from_html_column(): void { $column = LinkColumn::make('Name', 'name') ->title(fn ($row) => 'Title') @@ -55,8 +54,7 @@ public function can_check_ishtml_from_html_column(): void $this->assertTrue($column->isHtml()); } - /** @test */ - public function can_get_html_from_html_label_column(): void + public function test_can_get_html_from_html_label_column(): void { $column = LinkColumn::make('Name', 'name') ->title(fn ($row) => 'My Label')