From b1c923c2d59a325ff264fa12915afe675aa74746 Mon Sep 17 00:00:00 2001 From: Unay Santisteban Date: Tue, 2 Apr 2024 12:09:44 +1000 Subject: [PATCH 1/3] Feature/Upgrade domain model to 4.0 (#24) * Dropped support for PHP 8.1.x. --- .github/workflows/test.yml | 2 +- .gitignore | 1 + composer.json | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99e1a3b..bffef68 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - php-version: [ '8.1', '8.2', '8.3' ] + php-version: [ '8.2', '8.3' ] steps: - name: Checkout source code diff --git a/.gitignore b/.gitignore index 939b17b..14cd4aa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage.xml test.xml .phpunit.result.cache composer.lock +/.phpunit.cache diff --git a/composer.json b/composer.json index 54055e5..d93c29d 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,13 @@ ], "minimum-stability": "stable", "require": { - "php": "^8.1", - "complex-heart/domain-model": "^3.0.0", - "ext-json": "*" + "php": "^8.2", + "ext-json": "*", + "complex-heart/domain-model": "^4.0.0" }, "require-dev": { + "mockery/mockery": "^1.6.0", "pestphp/pest": "^2.0", - "pestphp/pest-plugin-mock": "^2.0", "pestphp/pest-plugin-faker": "^2.0", "phpstan/phpstan": "^1.0", "phpstan/extension-installer": "^1.3", From 5940732d08948427bd36962e77c8becd65d74a28 Mon Sep 17 00:00:00 2001 From: Unay Santisteban Date: Wed, 14 Aug 2024 12:56:22 +1000 Subject: [PATCH 2/3] Hotfix/Array to String on Filter from Array (#25) --- src/Filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter.php b/src/Filter.php index 1fe3ba2..3f668ab 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -63,7 +63,7 @@ public static function fromArray(array $filter): self : self::create( "{$filter['field']}", Operator::create("{$filter['operator']}"), - "{$filter['value']}" + $filter['value'] ); } From d5b2742f6317f89c037763802d22ff999583de6f Mon Sep 17 00:00:00 2001 From: Unay Santisteban Date: Sat, 8 Feb 2025 16:10:05 +0100 Subject: [PATCH 3/3] Feature/Add support for PHP 8.4 and typing hint enhancement. (#26) --- .gitattributes | 5 +- .github/workflows/test.yml | 2 +- composer.json | 8 +-- phpstan.neon | 5 ++ src/Criteria.php | 2 +- src/Errors/CriteriaError.php | 10 ++-- src/Filter.php | 96 +++++++++++++++++++++++++++++------- src/FilterGroup.php | 50 +++++++++++++++++++ 8 files changed, 148 insertions(+), 30 deletions(-) create mode 100644 phpstan.neon diff --git a/.gitattributes b/.gitattributes index b7477b5..c13f51c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,7 @@ /phpunit.xml export-ignore /tests export-ignore /README.md export-ignore -sonar-project.properties export-ignore +/sonar-project.properties export-ignore +/phpstan.neon export-ignore +test.xml export-ignore +/wiki export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bffef68..e930cc7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - php-version: [ '8.2', '8.3' ] + php-version: [ '8.2', '8.3', '8.4'] steps: - name: Checkout source code diff --git a/composer.json b/composer.json index d93c29d..783eeb4 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "mockery/mockery": "^1.6.0", "pestphp/pest": "^2.0", "pestphp/pest-plugin-faker": "^2.0", - "phpstan/phpstan": "^1.0", + "phpstan/phpstan": "^1.12", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-mockery": "^1.1" }, @@ -36,11 +36,7 @@ "scripts": { "test": "vendor/bin/pest --configuration=phpunit.xml --coverage-clover=coverage.xml --log-junit=test.xml", "test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage-html=coverage", - "analyse": "vendor/bin/phpstan analyse src tests --no-progress --level=8", - "check": [ - "@analyse", - "@test" - ] + "analyse": "vendor/bin/phpstan analyse --no-progress" }, "config": { "allow-plugins": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..3844657 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + paths: + - src/ + - tests/ + level: 9 diff --git a/src/Criteria.php b/src/Criteria.php index 1376fa6..32bf587 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -179,7 +179,7 @@ public function withPageOffset(int $offset): self ); } - public function withPageNumber(int $number, int $size = null): self + public function withPageNumber(int $number, ?int $size = null): self { return self::create( groups: $this->groups, diff --git a/src/Errors/CriteriaError.php b/src/Errors/CriteriaError.php index 69394c8..dd9629e 100644 --- a/src/Errors/CriteriaError.php +++ b/src/Errors/CriteriaError.php @@ -28,8 +28,12 @@ class CriteriaError extends Error * @param Throwable|null $previous * @param array $violations */ - public function __construct(string $message = "", int $code = 0, Throwable $previous = null, array $violations = []) - { + public function __construct( + string $message = "", + int $code = 0, + ?Throwable $previous = null, + array $violations = [] + ) { parent::__construct($message, $code, $previous); $this->violations = $violations; @@ -42,7 +46,7 @@ public function __construct(string $message = "", int $code = 0, Throwable $prev * @param Throwable|null $previous * @return self */ - public static function create(string $message, array $violations, int $code = 0, Throwable $previous = null): self + public static function create(string $message, array $violations, int $code = 0, ?Throwable $previous = null): self { return new self($message, $code, $previous, $violations); } diff --git a/src/Filter.php b/src/Filter.php index 3f668ab..e98e9a2 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -22,12 +22,12 @@ final class Filter implements ValueObject * * @param string $field * @param Operator $operator - * @param mixed $value + * @param scalar|null|array $value */ public function __construct( private readonly string $field, private readonly Operator $operator, - private readonly mixed $value, + private readonly bool|float|int|string|null|array $value, ) { $this->check(); } @@ -37,10 +37,10 @@ public function __construct( * * @param string $field * @param Operator $operator - * @param mixed $value + * @param scalar|null|array $value * @return Filter */ - public static function create(string $field, Operator $operator, mixed $value): self + public static function create(string $field, Operator $operator, bool|float|int|string|null|array $value): self { return new self($field, $operator, $value); } @@ -67,62 +67,122 @@ public static function fromArray(array $filter): self ); } - public static function equal(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function equal(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::EQUAL, $value); } - public static function notEqual(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function notEqual(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::NOT_EQUAL, $value); } - public static function greaterThan(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function greaterThan(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::GT, $value); } - public static function greaterOrEqualThan(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function greaterOrEqualThan(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::GTE, $value); } - public static function lessThan(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function lessThan(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::LT, $value); } - public static function lessOrEqualThan(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function lessOrEqualThan(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::LTE, $value); } - public static function in(string $field, mixed $value): self + /** + * @param string $field + * @param array $value + * @return self + */ + public static function in(string $field, array $value): self { return self::create($field, Operator::IN, $value); } - public static function notIn(string $field, mixed $value): self + /** + * @param string $field + * @param array $value + * @return self + */ + public static function notIn(string $field, array $value): self { return self::create($field, Operator::NOT_IN, $value); } - public static function like(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function like(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::LIKE, $value); } - public static function notLike(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function notLike(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::NOT_LIKE, $value); } - public static function contains(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function contains(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::CONTAINS, $value); } - public static function notContains(string $field, mixed $value): self + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ + public static function notContains(string $field, bool|float|int|string|null $value): self { return self::create($field, Operator::NOT_CONTAINS, $value); } @@ -150,9 +210,9 @@ public function operator(): Operator /** * Return the field value. * - * @return mixed + * @return scalar|null|array */ - public function value(): mixed + public function value(): bool|float|int|string|null|array { return $this->value; } diff --git a/src/FilterGroup.php b/src/FilterGroup.php index c6605c8..8140189 100644 --- a/src/FilterGroup.php +++ b/src/FilterGroup.php @@ -69,31 +69,61 @@ public function addFilter(Filter $new): self return $this; } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterEqual(string $field, mixed $value): self { return $this->addFilter(Filter::equal($field, $value)); } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterNotEqual(string $field, mixed $value): self { return $this->addFilter(Filter::notEqual($field, $value)); } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterGreaterThan(string $field, mixed $value): self { return $this->addFilter(Filter::greaterThan($field, $value)); } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterGreaterOrEqualThan(string $field, mixed $value): self { return $this->addFilter(Filter::greaterOrEqualThan($field, $value)); } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterLessThan(string $field, mixed $value): self { return $this->addFilter(Filter::lessThan($field, $value)); } + /** + * @param string $field + * @param bool|float|int|string|null $value + * @return self + */ public function addFilterLessOrEqualThan(string $field, mixed $value): self { return $this->addFilter(Filter::lessOrEqualThan($field, $value)); @@ -119,21 +149,41 @@ public function addFilterNotIn(string $field, array $value): self return $this->addFilter(Filter::notIn($field, $value)); } + /** + * @param string $field + * @param string $value + * @return self + */ public function addFilterLike(string $field, string $value): self { return $this->addFilter(Filter::like($field, $value)); } + /** + * @param string $field + * @param string $value + * @return self + */ public function addFilterNotLike(string $field, string $value): self { return $this->addFilter(Filter::notLike($field, $value)); } + /** + * @param string $field + * @param string $value + * @return self + */ public function addFilterContains(string $field, string $value): self { return $this->addFilter(Filter::contains($field, $value)); } + /** + * @param string $field + * @param string $value + * @return self + */ public function addFilterNotContains(string $field, string $value): self { return $this->addFilter(Filter::notContains($field, $value));