diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 60f3345..79dcd44 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,10 +14,12 @@ jobs: strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4, 8.0] - laravel: [6.*, 7.*, 8.*, 9.*] + php: [7.2, 7.3, 7.4, 8.0, 8.1] + laravel: [6.*, 7.*, 8.*, 9.*, 10.*] dependency-version: [prefer-lowest, prefer-stable] include: + - laravel: 10.* + testbench: 8.* - laravel: 9.* testbench: 7.* - laravel: 8.* @@ -29,6 +31,28 @@ jobs: exclude: - php: 7.2 laravel: 8.* + - php: 7.2 + laravel: 9.* + - php: 7.2 + laravel: 10.* + - php: 7.3 + laravel: 9.* + - php: 7.3 + laravel: 10.* + - php: 7.4 + laravel: 9.* + - php: 7.4 + laravel: 10.* + - php: 8.0 + laravel: 10.* + - php: 8.0 + laravel: 8.* + - php: 8.1 + laravel: 6.* + - php: 8.1 + laravel: 7.* + - php: 8.1 + laravel: 8.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} steps: - name: Checkout code @@ -39,7 +63,7 @@ jobs: path: ~/.composer/cache/files key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv diff --git a/README.md b/README.md index 93e0eb9..78ce0bc 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -- [Column sorting for Laravel 5.5-8](#column-sorting-for-laravel-55-8) +- [Column sorting for Laravel 5.5-10](#column-sorting-for-laravel-55-8) - [Setup](#setup) - [Composer](#composer) - [Laravel's >=5.5 auto discovery](#laravels-55-auto-discovery) diff --git a/composer.json b/composer.json index e281885..cc0470a 100755 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ ], "require": { "php": ">=7.2", - "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/database": "5.8.*|^6.0|^7.0|^8.0|^9.0" + "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/database": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0" }, "require-dev": { "phpunit/phpunit": "^8.5|^9.5.10", - "orchestra/testbench": "^5.0|^7.0" + "orchestra/testbench": "^5.0|^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 916a770..088d6b8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,13 @@ - - - - ./tests - - - - - ./src/ColumnSortable/ - - - \ No newline at end of file + + + + ./src/ColumnSortable/ + + + + + ./tests + + + diff --git a/src/ColumnSortable/Sortable.php b/src/ColumnSortable/Sortable.php index 43dcc0f..c4fcebb 100755 --- a/src/ColumnSortable/Sortable.php +++ b/src/ColumnSortable/Sortable.php @@ -5,6 +5,7 @@ use BadMethodCallException; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Support\Facades\Schema; @@ -17,13 +18,13 @@ trait Sortable { /** - * @param \Illuminate\Database\Query\Builder $query - * @param array|null $defaultParameters + * @param Builder $query + * @param array|string|null $defaultParameters * - * @return \Illuminate\Database\Query\Builder - * @throws \Kyslik\ColumnSortable\Exceptions\ColumnSortableException + * @return Builder + * @throws ColumnSortableException */ - public function scopeSortable($query, $defaultParameters = null) + public function scopeSortable(Builder $query, $defaultParameters = null): Builder { if (request()->allFilled(['sort', 'direction'])) { // allFilled() is macro return $this->queryOrderBuilder($query, request()->only(['sort', 'direction'])); @@ -51,7 +52,7 @@ public function scopeSortable($query, $defaultParameters = null) * * @return array|null */ - private function getDefaultSortable() + private function getDefaultSortable(): ?array { if (config('columnsortable.default_first_column', false)) { $sortBy = Arr::first($this->sortable); @@ -65,14 +66,14 @@ private function getDefaultSortable() /** - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param array $sortParameters * - * @return \Illuminate\Database\Query\Builder + * @return Builder * * @throws ColumnSortableException */ - private function queryOrderBuilder($query, array $sortParameters) + private function queryOrderBuilder(Builder $query, array $sortParameters): Builder { $model = $this; @@ -119,7 +120,7 @@ private function queryOrderBuilder($query, array $sortParameters) * * @return array */ - private function parseParameters(array $parameters) + private function parseParameters(array $parameters): array { $column = Arr::get($parameters, 'sort'); if (empty($column)) { @@ -136,14 +137,14 @@ private function parseParameters(array $parameters) /** - * @param \Illuminate\Database\Query\Builder $query - * @param \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\HasOne $relation + * @param Builder $query + * @param BelongsTo|\Illuminate\Database\Eloquent\Relations\HasOne $relation * - * @return \Illuminate\Database\Query\Builder + * @return Builder * * @throws \Exception */ - private function queryJoinBuilder($query, $relation) + private function queryJoinBuilder(Builder $query, $relation): Builder { $relatedTable = $relation->getRelated()->getTable(); $parentTable = $relation->getParent()->getTable(); @@ -174,7 +175,7 @@ private function queryJoinBuilder($query, $relation) * * @return bool */ - private function columnExists($model, $column) + private function columnExists($model, $column): bool { return (isset($model->sortable)) ? in_array($column, $model->sortable) : Schema::connection($model->getConnectionName())->hasColumn($model->getTable(), $column); @@ -186,7 +187,7 @@ private function columnExists($model, $column) * * @return array */ - private function formatToParameters($array) + private function formatToParameters($array): array { if (empty($array)) { return []; diff --git a/tests/SortableLinkTest.php b/tests/SortableLinkTest.php index b30dfa1..f1e1c32 100644 --- a/tests/SortableLinkTest.php +++ b/tests/SortableLinkTest.php @@ -107,15 +107,17 @@ public function testCustomTitleWithHTML() $this->assertSame('columnTitle', $link); } - + public function testCustomHrefAttribute() { + Config::set('columnsortable.sortable_icon', 'fa fa-sort'); + $link = SortableLink::render(['column', 'ColumnTitle', ['a' => 'b'], ['c' => 'd', 'href' => 'http://localhost/custom-path']]); - - $this->assertSame('ColumnTitle ', $link); + + $this->assertSame('ColumnTitle', $link); } - - + + public function testParseParameters() { $parameters = ['column'];