From 51f4c945948a057e65f550cfbc6109eb41e7a864 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Wed, 3 Jul 2024 23:14:24 +0100 Subject: [PATCH] Fix missing typehints (#1757) * Add additional typehints * Fix styling * Add filterCollection typehint * Fix styling * trUrlCallback fixes * Use Collection rather than collect() helper * Fix styling * Add ignore for "Unable to resolve the template type" for Illuminate Collection, add typehint for empty * Add ignore for $model has no defined type (allows for non Eloquent Model to be used longer term) * Adjust concurrency * Adjust Test * Adjust Again * Adjust PHPStan * Add Max Parallel * Use v4 of checkout/cache * Run one at a time * Add Clear Cache Workflow * Fix * Migrate to v4 and adjust workflows * Adjust workflow run rules * Adjust Run-Tests to separate L10 and L11 jobs * Adjust run-tests * Adjust Test * Add Laravel matrix * Adjust Concurrency * Adjust * Adjust Pull Jobs to Match Push jobs --------- Co-authored-by: lrljoe --- .github/workflows/discord-releases.yml | 2 +- .github/workflows/pint.yml | 7 +- .github/workflows/run-phpstan.yml | 18 ++- .github/workflows/run-tests-pcov-pull.yml | 6 +- .github/workflows/run-tests-pull.yml | 111 +++++++++++++++--- .github/workflows/run-tests.yml | 105 +++++++++++++++-- phpstan.neon | 3 + src/Commands/MakeCommand.php | 12 +- src/Mechanisms/RappasoftFrontendAssets.php | 2 +- .../Configuration/FilterConfiguration.php | 2 +- src/Traits/Helpers/FilterHelpers.php | 2 +- src/Traits/Helpers/FooterHelpers.php | 4 +- src/Traits/Helpers/SecondaryHeaderHelpers.php | 4 +- src/Traits/Helpers/TableAttributeHelpers.php | 14 +-- src/Traits/WithData.php | 2 +- src/Traits/WithEvents.php | 4 +- src/Traits/WithFilters.php | 3 +- src/Traits/WithFooter.php | 4 +- src/Traits/WithPagination.php | 2 +- src/Traits/WithSecondaryHeader.php | 4 +- src/Traits/WithTableAttributes.php | 12 +- src/Traits/WithTableHooks.php | 4 +- .../Filters/MultiSelectDropdownFilter.php | 5 +- src/Views/Filters/SelectFilter.php | 8 +- .../Traits/Helpers/ColorColumnHelpers.php | 3 +- src/Views/Traits/Helpers/ColumnHelpers.php | 2 +- 26 files changed, 265 insertions(+), 80 deletions(-) diff --git a/.github/workflows/discord-releases.yml b/.github/workflows/discord-releases.yml index c75bedd41..84ea5b888 100644 --- a/.github/workflows/discord-releases.yml +++ b/.github/workflows/discord-releases.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Package Releases uses: SethCohen/github-releases-to-discord@v1.13.1 with: diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 097689b83..230a58799 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -2,6 +2,11 @@ name: Fix PHP code style issues on: push: + branches: + - '*' # matches every branch that doesn't contain a '/' + - '*/*' # matches every branch containing a single '/' + - '**' # matches every branch + - '!master' paths: - '**.php' @@ -14,7 +19,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} diff --git a/.github/workflows/run-phpstan.yml b/.github/workflows/run-phpstan.yml index a94ed2a24..4faf52718 100644 --- a/.github/workflows/run-phpstan.yml +++ b/.github/workflows/run-phpstan.yml @@ -1,6 +1,16 @@ name: run-phpstan -on: [push, pull_request] +on: + pull_request: + branches: + - 'master' + - 'development' + push: + branches: + - '*' # matches every branch that doesn't contain a '/' + - '*/*' # matches every branch containing a single '/' + - '**' # matches every branch + - '!master' jobs: test: @@ -20,7 +30,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup cache environment id: extcache @@ -31,7 +41,7 @@ jobs: key: ${{ env.extensionKey }} - name: Cache extensions - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} key: ${{ steps.extcache.outputs.key }} @@ -55,7 +65,7 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-PHPStan-P${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index 0a5f52d3e..3a24a91ba 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup cache environment id: extcache @@ -47,7 +47,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Cache extensions - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} key: ${{ steps.extcache.outputs.key }} @@ -61,7 +61,7 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-PCOV-PULL-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index 1abeaeee8..38f635f9c 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -8,27 +8,25 @@ on: - 'master' jobs: - test: + test-laravel10: runs-on: ${{ matrix.os }} strategy: fail-fast: false + max-parallel: 3 matrix: os: [ubuntu-latest] php: [8.1, 8.2, 8.3] - laravel: [10.*,11.*] + laravel: [10.*] stability: [prefer-dist] - exclude: - - laravel: 11.* - php: 8.1 - name: STD-PULL - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + name: PULL PHP-${{ matrix.php }} - Laravel-10 env: - extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L{{ matrix.laravel }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup cache environment id: extcache @@ -36,14 +34,14 @@ jobs: with: php-version: ${{ matrix.php }} extensions: ${{ env.extensions }} - key: ${{ runner.os }}-${{ env.extensionKey }} + key: ${{ env.extensionKey }} - name: Cache extensions - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} - key: ${{ steps.extcache.outputs.key }} - restore-keys: ${{ steps.extcache.outputs.key }} + key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -64,11 +62,11 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-STDPULL-PHP-${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-STDPULL-PHP-${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -79,7 +77,90 @@ jobs: run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update - name: Update dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' run: composer update --${{ matrix.stability }} --no-interaction + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Run Unit Tests + run: php ./vendor/bin/paratest --no-coverage --processes=4 + + + test-laravel11: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + max-parallel: 2 + matrix: + os: [ubuntu-latest] + php: [8.2, 8.3] + laravel: [11.*] + stability: [prefer-dist] + + name: PULL PHP-${{ matrix.php }} - Laravel-11 + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L{{ matrix.laravel }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + tools: phpunit:latest + ini-values: memory_limit=512M + coverage: none + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Get composer cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + + - name: Add token + run: | + composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update + + - name: Update dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer update --${{ matrix.stability }} --no-interaction + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Run Unit Tests run: php ./vendor/bin/paratest --no-coverage --processes=4 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ce258214d..9f6997a6c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,29 +1,33 @@ name: run-tests -on: [push] +on: + push: + branches: + - '*' # matches every branch that doesn't contain a '/' + - '*/*' # matches every branch containing a single '/' + - '**' # matches every branch + - '!master' jobs: - test: + test-laravel10: runs-on: ${{ matrix.os }} strategy: fail-fast: false + max-parallel: 3 matrix: os: [ubuntu-latest] php: [8.1, 8.2, 8.3] - laravel: [10.*,11.*] + laravel: [10.*] stability: [prefer-dist] - exclude: - - laravel: 11.* - php: 8.1 - name: STD-PUSH - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + name: PHP-${{ matrix.php }} - Laravel-10 env: - extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L{{ matrix.laravel }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup cache environment id: extcache @@ -34,7 +38,7 @@ jobs: key: ${{ env.extensionKey }} - name: Cache extensions - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} @@ -59,7 +63,86 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + + - name: Add token + run: | + composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update + + - name: Update dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer update --${{ matrix.stability }} --no-interaction + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Run Unit Tests + run: php ./vendor/bin/paratest --no-coverage --processes=4 + + + test-laravel11: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + max-parallel: 2 + matrix: + os: [ubuntu-latest] + php: [8.2, 8.3] + laravel: [11.*] + stability: [prefer-dist] + + name: PHP-${{ matrix.php }} - Laravel-11 + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L{{ matrix.laravel }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + tools: phpunit:latest + ini-values: memory_limit=512M + coverage: none + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Get composer cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/phpstan.neon b/phpstan.neon index 25867a7d5..7ff21a707 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,6 +15,9 @@ parameters: ignoreErrors: - identifier: missingType.generics - identifier: missingType.iterableValue + - '#Property Rappasoft\\LaravelLivewireTables\\DataTableComponent\:\:\$model has no type specified#' + - '#Unable to resolve the template type TMapWithKeysKey in call to method Illuminate\\Support\\Collection#' + - '#Unable to resolve the template type TMapWithKeysValue in call to method Illuminate\\Support\\Collection#' - '#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/Commands/MakeCommand.php b/src/Commands/MakeCommand.php index cdaa67130..8338a1216 100644 --- a/src/Commands/MakeCommand.php +++ b/src/Commands/MakeCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use Livewire\Features\SupportConsoleCommands\Commands\ComponentParser; @@ -97,10 +98,7 @@ protected function createClass(bool $force = false): bool return $classPath; } - /** - * @param mixed $path - */ - protected function ensureDirectoryExists($path): void + protected function ensureDirectoryExists(string $path): void { if (! File::isDirectory(dirname($path))) { File::makeDirectory(dirname($path), 0777, true, true); @@ -147,7 +145,7 @@ public function getModelImport(): string /* * Credits to Harm Smits: https://stackoverflow.com/a/67099502/2263114 */ - private function getClassesList($file): array + private function getClassesList(string $file): array { $classes = []; $namespace = ''; @@ -215,7 +213,7 @@ private function generateColumns(string $modelName): string return $columns; } - protected function possibleModels() + protected function possibleModels(): array { $modelPath = is_dir(app_path('Models')) ? app_path('Models') : app_path(); @@ -226,7 +224,7 @@ protected function possibleModels() ->all(); } - protected function promptForMissingArguments(InputInterface $input, OutputInterface $output) + protected function promptForMissingArguments(InputInterface $input, OutputInterface $output): void { if ($this->didReceiveOptions($input)) { diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index 62889d0ff..d460f5431 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -56,7 +56,7 @@ public function boot(): void } - protected function registerBladeDirectives() + protected function registerBladeDirectives(): void { Blade::directive('rappasoftTableScripts', [static::class, 'rappasoftTableScripts']); Blade::directive('rappasoftTableStyles', [static::class, 'rappasoftTableStyles']); diff --git a/src/Traits/Configuration/FilterConfiguration.php b/src/Traits/Configuration/FilterConfiguration.php index 9eac5d75f..3367c9168 100644 --- a/src/Traits/Configuration/FilterConfiguration.php +++ b/src/Traits/Configuration/FilterConfiguration.php @@ -121,7 +121,7 @@ public function generateFilterGenericData(): array return (new FilterGenericData($this))->toArray(); } - public function setFilterGenericData(array $filterGenericData = []) + public function setFilterGenericData(array $filterGenericData = []): void { $this->filterGenericData = $filterGenericData; } diff --git a/src/Traits/Helpers/FilterHelpers.php b/src/Traits/Helpers/FilterHelpers.php index 55c824fad..d4c043531 100644 --- a/src/Traits/Helpers/FilterHelpers.php +++ b/src/Traits/Helpers/FilterHelpers.php @@ -312,7 +312,7 @@ public function hasFilterGenericData(): bool return ! empty($this->filterGenericData); } - public function getFilterGenericData() + public function getFilterGenericData(): array { if (! $this->hasFilterGenericData()) { $this->setFilterGenericData($this->generateFilterGenericData()); diff --git a/src/Traits/Helpers/FooterHelpers.php b/src/Traits/Helpers/FooterHelpers.php index 37e8276bd..df220e3c0 100644 --- a/src/Traits/Helpers/FooterHelpers.php +++ b/src/Traits/Helpers/FooterHelpers.php @@ -47,7 +47,7 @@ public function useHeaderAsFooterIsDisabled(): bool */ public function getFooterTrAttributes($rows): array { - return $this->footerTrAttributesCallback ? call_user_func($this->footerTrAttributesCallback, $rows) : ['default' => true]; + return isset($this->footerTrAttributesCallback) ? call_user_func($this->footerTrAttributesCallback, $rows) : ['default' => true]; } /** @@ -56,6 +56,6 @@ public function getFooterTrAttributes($rows): array */ public function getFooterTdAttributes(Column $column, $rows, int $index): array { - return $this->footerTdAttributesCallback ? call_user_func($this->footerTdAttributesCallback, $column, $rows, $index) : ['default' => true]; + return isset($this->footerTdAttributesCallback) ? call_user_func($this->footerTdAttributesCallback, $column, $rows, $index) : ['default' => true]; } } diff --git a/src/Traits/Helpers/SecondaryHeaderHelpers.php b/src/Traits/Helpers/SecondaryHeaderHelpers.php index cc7694002..6af852483 100644 --- a/src/Traits/Helpers/SecondaryHeaderHelpers.php +++ b/src/Traits/Helpers/SecondaryHeaderHelpers.php @@ -32,7 +32,7 @@ public function secondaryHeaderIsDisabled(): bool */ public function getSecondaryHeaderTrAttributes($rows): array { - return $this->secondaryHeaderTrAttributesCallback ? call_user_func($this->secondaryHeaderTrAttributesCallback, $rows) : ['default' => true]; + return isset($this->secondaryHeaderTrAttributesCallback) ? call_user_func($this->secondaryHeaderTrAttributesCallback, $rows) : ['default' => true]; } /** @@ -41,6 +41,6 @@ public function getSecondaryHeaderTrAttributes($rows): array */ public function getSecondaryHeaderTdAttributes(Column $column, $rows, int $index): array { - return $this->secondaryHeaderTdAttributesCallback ? call_user_func($this->secondaryHeaderTdAttributesCallback, $column, $rows, $index) : ['default' => true]; + return isset($this->secondaryHeaderTdAttributesCallback) ? call_user_func($this->secondaryHeaderTdAttributesCallback, $column, $rows, $index) : ['default' => true]; } } diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 866e72526..ffebab51c 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -52,7 +52,7 @@ public function getTbodyAttributes(): array */ public function getThAttributes(Column $column): array { - return $this->thAttributesCallback ? call_user_func($this->thAttributesCallback, $column) : ['default' => true]; + return isset($this->thAttributesCallback) ? call_user_func($this->thAttributesCallback, $column) : ['default' => true]; } /** @@ -60,7 +60,7 @@ public function getThAttributes(Column $column): array */ public function getThSortButtonAttributes(Column $column): array { - return $this->thSortButtonAttributesCallback ? call_user_func($this->thSortButtonAttributesCallback, $column) : ['default' => true]; + return isset($this->thSortButtonAttributesCallback) ? call_user_func($this->thSortButtonAttributesCallback, $column) : ['default' => true]; } /** @@ -68,7 +68,7 @@ public function getThSortButtonAttributes(Column $column): array */ public function getTrAttributes(Model $row, int $index): array { - return $this->trAttributesCallback ? call_user_func($this->trAttributesCallback, $row, $index) : ['default' => true]; + return isset($this->trAttributesCallback) ? call_user_func($this->trAttributesCallback, $row, $index) : ['default' => true]; } /** @@ -76,21 +76,21 @@ public function getTrAttributes(Model $row, int $index): array */ public function getTdAttributes(Column $column, Model $row, int $colIndex, int $rowIndex): array { - return $this->tdAttributesCallback ? call_user_func($this->tdAttributesCallback, $column, $row, $colIndex, $rowIndex) : ['default' => true]; + return isset($this->tdAttributesCallback) ? call_user_func($this->tdAttributesCallback, $column, $row, $colIndex, $rowIndex) : ['default' => true]; } public function hasTableRowUrl(): bool { - return $this->trUrlCallback !== null; + return isset($this->trUrlCallback); } public function getTableRowUrl(int|Model $row): ?string { - return $this->trUrlCallback ? call_user_func($this->trUrlCallback, $row) : null; + return isset($this->trUrlCallback) ? call_user_func($this->trUrlCallback, $row) : null; } public function getTableRowUrlTarget(int|Model $row): ?string { - return $this->trUrlTargetCallback ? call_user_func($this->trUrlTargetCallback, $row) : null; + return isset($this->trUrlTargetCallback) ? call_user_func($this->trUrlTargetCallback, $row) : null; } } diff --git a/src/Traits/WithData.php b/src/Traits/WithData.php index 6d3261c93..5e1ca3298 100644 --- a/src/Traits/WithData.php +++ b/src/Traits/WithData.php @@ -175,7 +175,7 @@ protected function joinRelation(Column $column): Builder return $this->getBuilder(); } - protected function performJoin($table, $foreign, $other, $type = 'left'): Builder + protected function performJoin(string $table, string $foreign, string $other, string $type = 'left'): Builder { $joins = []; diff --git a/src/Traits/WithEvents.php b/src/Traits/WithEvents.php index 448dcc69f..dca549f2a 100644 --- a/src/Traits/WithEvents.php +++ b/src/Traits/WithEvents.php @@ -4,7 +4,7 @@ trait WithEvents { - public function setSortEvent($field, $direction): void + public function setSortEvent(string $field, string $direction): void { $this->setSort($field, $direction); } @@ -14,7 +14,7 @@ public function clearSortEvent(): void $this->clearSorts(); } - public function setFilterEvent($filter, $value): void + public function setFilterEvent(string $filter, string $value): void { $this->setFilter($filter, $value); } diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index ec6c7aac2..878c660ce 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Collection; use Rappasoft\LaravelLivewireTables\Traits\Configuration\FilterConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Helpers\FilterHelpers; @@ -23,7 +24,7 @@ trait WithFilters public int $filterCount; - protected $filterCollection; + protected ?Collection $filterCollection; public array $filterComponents = []; diff --git a/src/Traits/WithFooter.php b/src/Traits/WithFooter.php index 376f2340b..b1035cf29 100644 --- a/src/Traits/WithFooter.php +++ b/src/Traits/WithFooter.php @@ -16,9 +16,9 @@ trait WithFooter protected bool $columnsWithFooter = false; - protected $footerTrAttributesCallback; + protected ?object $footerTrAttributesCallback; - protected $footerTdAttributesCallback; + protected ?object $footerTdAttributesCallback; public function setupFooter(): void { diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 6f022a9fb..946bed2cb 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -53,7 +53,7 @@ public function mountWithPagination(): void } // TODO: Test - public function updatedPerPage($value): void + public function updatedPerPage(int|string $value): void { if (! in_array((int) $value, $this->getPerPageAccepted(), false)) { $value = $this->getPerPageAccepted()[0] ?? 10; diff --git a/src/Traits/WithSecondaryHeader.php b/src/Traits/WithSecondaryHeader.php index 94022b5f1..875d0ae03 100644 --- a/src/Traits/WithSecondaryHeader.php +++ b/src/Traits/WithSecondaryHeader.php @@ -14,9 +14,9 @@ trait WithSecondaryHeader protected bool $columnsWithSecondaryHeader = false; - protected $secondaryHeaderTrAttributesCallback; + protected ?object $secondaryHeaderTrAttributesCallback; - protected $secondaryHeaderTdAttributesCallback; + protected ?object $secondaryHeaderTdAttributesCallback; public function bootedWithSecondaryHeader(): void { diff --git a/src/Traits/WithTableAttributes.php b/src/Traits/WithTableAttributes.php index f75f75f9e..b58c6baf0 100644 --- a/src/Traits/WithTableAttributes.php +++ b/src/Traits/WithTableAttributes.php @@ -21,15 +21,15 @@ trait WithTableAttributes protected array $tbodyAttributes = []; - protected $thAttributesCallback; + protected ?object $thAttributesCallback; - protected $thSortButtonAttributesCallback; + protected ?object $thSortButtonAttributesCallback; - protected $trAttributesCallback; + protected ?object $trAttributesCallback; - protected $tdAttributesCallback; + protected ?object $tdAttributesCallback; - protected $trUrlCallback; + protected ?object $trUrlCallback; - protected $trUrlTargetCallback; + protected ?object $trUrlTargetCallback; } diff --git a/src/Traits/WithTableHooks.php b/src/Traits/WithTableHooks.php index 160713e56..eb0f18fd8 100644 --- a/src/Traits/WithTableHooks.php +++ b/src/Traits/WithTableHooks.php @@ -6,14 +6,14 @@ trait WithTableHooks { - public function callHook($name, $params = []) + public function callHook(string $name, array $params = []): void { if (method_exists($this, $name)) { wrap($this)->__call($name, $params); } } - public function callTraitHook($name, $params = []) + public function callTraitHook(string $name, array $params = []): void { foreach (class_uses_recursive($this) as $trait) { $method = $name.class_basename($trait); diff --git a/src/Views/Filters/MultiSelectDropdownFilter.php b/src/Views/Filters/MultiSelectDropdownFilter.php index ae784b58c..3022ddba5 100644 --- a/src/Views/Filters/MultiSelectDropdownFilter.php +++ b/src/Views/Filters/MultiSelectDropdownFilter.php @@ -2,6 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Views\Filters; +use Illuminate\Support\Collection; use Rappasoft\LaravelLivewireTables\Views\Filter; use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables; use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasOptions,IsArrayFilter}; @@ -42,7 +43,7 @@ public function getFilterPillValue($value): ?string foreach ($value as $item) { $found = $this->getCustomFilterPillValue($item) - ?? collect($this->getOptions()) + ?? (new Collection($this->getOptions())) ->mapWithKeys(fn ($options, $optgroupLabel) => is_iterable($options) ? $options : [$optgroupLabel => $options])[$item] ?? null; @@ -54,7 +55,7 @@ public function getFilterPillValue($value): ?string return implode(', ', $values); } - public function isEmpty($value): bool + public function isEmpty(mixed $value): bool { if (! is_array($value)) { return true; diff --git a/src/Views/Filters/SelectFilter.php b/src/Views/Filters/SelectFilter.php index a62260dd9..0f247ada4 100644 --- a/src/Views/Filters/SelectFilter.php +++ b/src/Views/Filters/SelectFilter.php @@ -2,6 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Views\Filters; +use Illuminate\Support\Collection; use Rappasoft\LaravelLivewireTables\Views\Filter; use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables; use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasOptions,IsStringFilter}; @@ -22,8 +23,8 @@ class SelectFilter extends Filter public function getKeys(): array { - return collect($this->getOptions()) - ->map(fn ($value, $key) => is_iterable($value) ? collect($value)->keys() : $key) + return (new Collection($this->getOptions())) + ->map(fn ($value, $key) => is_iterable($value) ? (new Collection($value))->keys() : $key) ->flatten() ->map(fn ($value) => (string) $value) ->filter(fn ($value) => strlen($value) > 0) @@ -42,8 +43,9 @@ public function validate(string $value): array|string|bool public function getFilterPillValue($value): ?string { + return $this->getCustomFilterPillValue($value) - ?? collect($this->getOptions()) + ?? (new Collection($this->getOptions())) ->mapWithKeys(fn ($options, $optgroupLabel) => is_iterable($options) ? $options : [$optgroupLabel => $options])[$value] ?? null; } diff --git a/src/Views/Traits/Helpers/ColorColumnHelpers.php b/src/Views/Traits/Helpers/ColorColumnHelpers.php index 00f017e9e..d437243e7 100644 --- a/src/Views/Traits/Helpers/ColorColumnHelpers.php +++ b/src/Views/Traits/Helpers/ColorColumnHelpers.php @@ -2,12 +2,13 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits\Helpers; +use Illuminate\Database\Eloquent\Model; use Illuminate\View\ComponentAttributeBag; trait ColorColumnHelpers { // TODO: Test - public function getColor($row): string + public function getColor(Model|int $row): string { return $this->hasColorCallback() ? app()->call($this->getColorCallback(), ['row' => $row]) : ($this->getValue($row)); } diff --git a/src/Views/Traits/Helpers/ColumnHelpers.php b/src/Views/Traits/Helpers/ColumnHelpers.php index a43d21681..fb2fbfb38 100644 --- a/src/Views/Traits/Helpers/ColumnHelpers.php +++ b/src/Views/Traits/Helpers/ColumnHelpers.php @@ -131,7 +131,7 @@ public function getContents(Model $row): null|string|\BackedEnum|HtmlString|Data } // TODO: Test - public function getValue(Model $row) + public function getValue(Model $row): mixed { if ($this->isBaseColumn()) { return $row->{$this->getField()};