From 2beaac854f8e3c85116a0608c9faf76bff484e1b Mon Sep 17 00:00:00 2001 From: Ramon Rietdijk Date: Fri, 23 Aug 2024 18:33:53 +0200 Subject: [PATCH] Added phpstan/phpstan-strict-rules (#79) --- composer.json | 3 ++- phpstan.neon | 5 +++++ src/Concerns/HasColumns.php | 6 +++--- src/Concerns/HasPagination.php | 2 +- src/Concerns/HasRelations.php | 4 ++-- src/Concerns/HasSearch.php | 4 ++-- src/Concerns/HasSession.php | 2 +- src/Filters/DateFilter.php | 2 +- src/Livewire/LivewireTable.php | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 53aadca..ab35d4e 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,10 @@ "livewire/livewire": "^3.0" }, "require-dev": { - "laravel/pint": "^1.16", "larastan/larastan": "^2.9", + "laravel/pint": "^1.16", "orchestra/testbench": "^9.2", + "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "^11.2" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon index 04556cc..4109f1b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ includes: + - ./vendor/phpstan/phpstan-strict-rules/rules.neon - ./vendor/larastan/larastan/extension.neon parameters: @@ -6,3 +7,7 @@ parameters: - src - tests level: 9 + ignoreErrors: + - identifier: staticMethod.dynamicCall + - identifier: property.dynamicName + - identifier: method.dynamicName diff --git a/src/Concerns/HasColumns.php b/src/Concerns/HasColumns.php index 8645112..81a4175 100644 --- a/src/Concerns/HasColumns.php +++ b/src/Concerns/HasColumns.php @@ -31,9 +31,9 @@ public function reorderColumn(string $from, string $to, bool $above): void return; } - $currentOrder = (int) array_search($from, $this->columnOrder); + $currentOrder = (int) array_search($from, $this->columnOrder, true); - $toOrder = (int) array_search($to, $this->columnOrder); + $toOrder = (int) array_search($to, $this->columnOrder, true); $up = $toOrder > $currentOrder; @@ -95,7 +95,7 @@ protected function columns(): array protected function resolveColumns(): Enumerable { return collect($this->columns())->sortBy(function (BaseColumn $column): int { - return (int) array_search($column->code(), $this->columnOrder); + return (int) array_search($column->code(), $this->columnOrder, true); })->values(); } } diff --git a/src/Concerns/HasPagination.php b/src/Concerns/HasPagination.php index 6506181..245d9c1 100644 --- a/src/Concerns/HasPagination.php +++ b/src/Concerns/HasPagination.php @@ -43,7 +43,7 @@ protected function perPage(): int { $options = $this->perPageOptions(); - if (! in_array($this->perPage, $options)) { + if (! in_array($this->perPage, $options, true)) { return $options[0]; } diff --git a/src/Concerns/HasRelations.php b/src/Concerns/HasRelations.php index d8f0a2d..3d9e6c1 100644 --- a/src/Concerns/HasRelations.php +++ b/src/Concerns/HasRelations.php @@ -55,11 +55,11 @@ protected function applyRelations(Builder $builder): static $fullRelation = $previous->push($segment)->implode('.'); - if (! in_array($fullRelation, $with)) { + if (! in_array($fullRelation, $with, true)) { $with[] = $fullRelation; } - if (! in_array($fullRelation, $join) && $shouldJoin) { + if (! in_array($fullRelation, $join, true) && $shouldJoin) { $join[] = $fullRelation; $lookup[$fullRelation] = $this->joinEloquentRelation($builder, $relation, $model, $segment, $alias); diff --git a/src/Concerns/HasSearch.php b/src/Concerns/HasSearch.php index 48dbd99..05b7b22 100644 --- a/src/Concerns/HasSearch.php +++ b/src/Concerns/HasSearch.php @@ -67,7 +67,7 @@ protected function applyGlobalSearch(Builder $builder): static } $columns = $this->resolveColumns()->filter(function (BaseColumn $column): bool { - return $column->isSearchable() && in_array($column->code(), $this->columns); + return $column->isSearchable() && in_array($column->code(), $this->columns, true); }); $builder->where(function (Builder $builder) use ($columns): void { @@ -89,7 +89,7 @@ protected function applyColumnSearch(Builder $builder): static } $columns = $this->resolveColumns()->filter(function (BaseColumn $column): bool { - return $column->isSearchable() && in_array($column->code(), $this->columns); + return $column->isSearchable() && in_array($column->code(), $this->columns, true); }); $builder->where(function (Builder $builder) use ($columns): void { diff --git a/src/Concerns/HasSession.php b/src/Concerns/HasSession.php index 904a284..71f5924 100644 --- a/src/Concerns/HasSession.php +++ b/src/Concerns/HasSession.php @@ -22,7 +22,7 @@ public function updatedHasSession(string $property): void $property = Str::of($property)->before('.')->toString(); - if (! in_array($property, $this->sessionProperties)) { + if (! in_array($property, $this->sessionProperties, true)) { return; } diff --git a/src/Filters/DateFilter.php b/src/Filters/DateFilter.php index 70a4809..adde11e 100644 --- a/src/Filters/DateFilter.php +++ b/src/Filters/DateFilter.php @@ -8,9 +8,9 @@ class DateFilter extends BaseFilter { protected string $view = 'livewire-table::filters.date'; - /** @param array $value */ public function filter(Builder $builder, mixed $value): void { + /** @var array $value */ $from = $value['from'] ?? null; $to = $value['to'] ?? null; diff --git a/src/Livewire/LivewireTable.php b/src/Livewire/LivewireTable.php index d0ababf..0fff114 100644 --- a/src/Livewire/LivewireTable.php +++ b/src/Livewire/LivewireTable.php @@ -50,7 +50,7 @@ class LivewireTable extends Component protected string $model = Model::class; - /** @var array */ + /** @var mixed */ protected $listeners = [ 'refreshLivewireTable' => '$refresh', ];