From e5e844aff8ec638b4e4ea43559557efc5fbf4020 Mon Sep 17 00:00:00 2001 From: Osama Aldemeery Date: Sat, 26 Oct 2024 01:14:28 +0300 Subject: [PATCH] Set supported Laravel version. --- README.md | 2 +- composer.json | 11 +-- composer.lock | 155 +----------------------------- docker-compose.yml | 4 +- src/Concerns/Filterable.php | 16 ++- tests/BadFilter.php | 23 +++++ tests/Concerns/FilterableTest.php | 14 +++ tests/ModelWithoutFilters.php | 2 +- 8 files changed, 64 insertions(+), 163 deletions(-) create mode 100644 tests/BadFilter.php diff --git a/README.md b/README.md index e58af42..e6e22a4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ public function index(Request $request) ## Installation > [!IMPORTANT] -> This package requires Laravel 9.0 or higher. +> This package requires Laravel 11.0 or higher and PHP 8.2 or higher. You can install the package via composer: diff --git a/composer.json b/composer.json index 882d10c..6b731aa 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,11 @@ ], "minimum-stability": "stable", "require": { - "php": ">=8.0", - "illuminate/support": ">=9.0", - "illuminate/database": ">=9.0", - "illuminate/console": ">=9.00", - "aldemeery/onion": "^1.0", - "azjezz/psl": "^3.0" + "php": "^8.2", + "illuminate/support": "^11.0", + "illuminate/database": "^11.0", + "illuminate/console": "^11.0", + "aldemeery/onion": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 53af367..1a00a06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0b2ef4d1a30ae510b84cb770eb842658", + "content-hash": "b4d7fbea48b7a31161ead7aba0a6c7cd", "packages": [ { "name": "aldemeery/onion", @@ -73,81 +73,6 @@ }, "time": "2024-10-21T08:29:51+00:00" }, - { - "name": "azjezz/psl", - "version": "3.0.2", - "source": { - "type": "git", - "url": "https://github.com/azjezz/psl.git", - "reference": "6683d60ba4d3abf8b4a4a9d94c39d0d08caa0214" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/azjezz/psl/zipball/6683d60ba4d3abf8b4a4a9d94c39d0d08caa0214", - "reference": "6683d60ba4d3abf8b4a4a9d94c39d0d08caa0214", - "shasum": "" - }, - "require": { - "ext-bcmath": "*", - "ext-intl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "ext-sodium": "*", - "php": "~8.2.0 || ~8.3.0", - "revolt/event-loop": "^1.0.6" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.52.1", - "php-coveralls/php-coveralls": "^2.7.0", - "php-standard-library/psalm-plugin": "^2.3.0", - "phpbench/phpbench": "^1.2.15", - "phpunit/phpunit": "^9.6.18", - "roave/infection-static-analysis-plugin": "^1.35.0", - "squizlabs/php_codesniffer": "^3.9.0", - "vimeo/psalm": "^5.23.1" - }, - "suggest": { - "php-standard-library/phpstan-extension": "PHPStan integration", - "php-standard-library/psalm-plugin": "Psalm integration" - }, - "type": "library", - "extra": { - "thanks": { - "name": "hhvm/hsl", - "url": "https://github.com/hhvm/hsl" - } - }, - "autoload": { - "files": [ - "src/bootstrap.php" - ], - "psr-4": { - "Psl\\": "src/Psl" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "azjezz", - "email": "azjezz@protonmail.com" - } - ], - "description": "PHP Standard Library", - "support": { - "issues": "https://github.com/azjezz/psl/issues", - "source": "https://github.com/azjezz/psl/tree/3.0.2" - }, - "funding": [ - { - "url": "https://github.com/azjezz", - "type": "github" - } - ], - "time": "2024-09-13T10:34:56+00:00" - }, { "name": "brick/math", "version": "0.12.1", @@ -1506,78 +1431,6 @@ }, "time": "2021-10-29T13:26:27+00:00" }, - { - "name": "revolt/event-loop", - "version": "v1.0.6", - "source": { - "type": "git", - "url": "https://github.com/revoltphp/event-loop.git", - "reference": "25de49af7223ba039f64da4ae9a28ec2d10d0254" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/revoltphp/event-loop/zipball/25de49af7223ba039f64da4ae9a28ec2d10d0254", - "reference": "25de49af7223ba039f64da4ae9a28ec2d10d0254", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "ext-json": "*", - "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^9", - "psalm/phar": "^5.15" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Revolt\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "ceesjank@gmail.com" - }, - { - "name": "Christian Lück", - "email": "christian@clue.engineering" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "Rock-solid event loop for concurrent PHP applications.", - "keywords": [ - "async", - "asynchronous", - "concurrency", - "event", - "event-loop", - "non-blocking", - "scheduler" - ], - "support": { - "issues": "https://github.com/revoltphp/event-loop/issues", - "source": "https://github.com/revoltphp/event-loop/tree/v1.0.6" - }, - "time": "2023-11-30T05:34:44+00:00" - }, { "name": "symfony/clock", "version": "v7.1.1", @@ -6286,12 +6139,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.0" + "php": "^8.2" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/docker-compose.yml b/docker-compose.yml index fc93989..f91fc3c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,11 @@ services: laravel.test: build: - context: ./vendor/laravel/sail/runtimes/8.3 + context: ./vendor/laravel/sail/runtimes/8.2 dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' - image: sail-8.3/app + image: sail-8.2/app extra_hosts: - 'host.docker.internal:host-gateway' environment: diff --git a/src/Concerns/Filterable.php b/src/Concerns/Filterable.php index 1078658..7b89d67 100644 --- a/src/Concerns/Filterable.php +++ b/src/Concerns/Filterable.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\App; -use Psl\Type; +use RuntimeException; trait Filterable { @@ -24,7 +24,19 @@ protected function scopeFilter(Builder $query, array $params = [], array $additi fn (array $filters): array => array_merge($filters, $additional), fn (array $filters): array => array_intersect_key($filters, $params), fn (array $filters): array => array_map( - fn (string $filter): Filter => Type\instance_of(Filter::class)->assert(App::make($filter)), + function (string $filter): Filter { + $filter = App::make($filter); + + if (!$filter instanceof Filter) { + throw new RuntimeException(sprintf( + 'Filters must implement %s, but %s does not.', + Filter::class, + is_object($filter) ? get_class($filter) : gettype($filter), + )); + } + + return $filter; + }, $filters, ), fn (array $filters): true => array_walk( diff --git a/tests/BadFilter.php b/tests/BadFilter.php new file mode 100644 index 0000000..ce60c19 --- /dev/null +++ b/tests/BadFilter.php @@ -0,0 +1,23 @@ + $value, + }; + } + + /** @param Builder $query */ + public function apply(Builder $query, mixed $value): void + { + $query->where('test', $value); + } +} diff --git a/tests/Concerns/FilterableTest.php b/tests/Concerns/FilterableTest.php index 84e7d34..4b34b38 100644 --- a/tests/Concerns/FilterableTest.php +++ b/tests/Concerns/FilterableTest.php @@ -11,6 +11,8 @@ use PDO; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +use RuntimeException; +use Tests\Aldemeery\Sieve\BadFilter; use Tests\Aldemeery\Sieve\ModelWithFilters; use Tests\Aldemeery\Sieve\ModelWithoutFilters; use Tests\Aldemeery\Sieve\TestFilter; @@ -73,4 +75,16 @@ public function test_additional_filters_are_applied(): void static::assertSame('select * from "tests" where "test" = ? and "test" = ?', $query->toSql()); static::assertSame(['one', 'three'], $query->getBindings()); } + + public function test_filters_not_implementing_the_filter_interface_throw_an_exception(): void + { + App::shouldReceive('make')->with(BadFilter::class)->andReturn(new BadFilter()); + + $filterable = new ModelWithoutFilters(); + + static::expectException(RuntimeException::class); + static::expectExceptionMessage('Filters must implement Aldemeery\Sieve\Contracts\Filter, but Tests\Aldemeery\Sieve\BadFilter does not.'); + + $filterable->filter(['test-1' => 'one'], ['test-1' => BadFilter::class]); + } } diff --git a/tests/ModelWithoutFilters.php b/tests/ModelWithoutFilters.php index b858df1..36bd81e 100644 --- a/tests/ModelWithoutFilters.php +++ b/tests/ModelWithoutFilters.php @@ -7,7 +7,7 @@ use Aldemeery\Sieve\Concerns\Filterable; use Illuminate\Database\Eloquent\Model; -/** @method \Illuminate\Database\Eloquent\Builder filter(array $params) */ +/** @method \Illuminate\Database\Eloquent\Builder filter(array $params = [], array $additional = []) */ class ModelWithoutFilters extends Model { use Filterable;