Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
"require": {
"php": "^8.2",
"ext-json": "*",
"complex-heart/domain-model": "^4.0.0"
"complex-heart/domain-model": "^5.0.0"
},
"require-dev": {
"mockery/mockery": "^1.6.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-faker": "^2.0",
"phpstan/phpstan": "^1.12",
"pestphp/pest": "^3.8.4",
"pestphp/pest-plugin-faker": "^3.0.0",
"phpstan/phpstan": "^1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-mockery": "^1.1"
"phpstan/phpstan-mockery": "^1.1",
"laravel/pint": "^1.25"
},
"autoload": {
"psr-4": {
Expand All @@ -34,9 +35,11 @@
}
},
"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 --no-progress"
"test": "vendor/bin/pest --configuration=phpunit.xml --coverage --coverage-clover=coverage.xml --log-junit=test.xml",
"test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage --coverage-html=coverage",
"analyse": "vendor/bin/phpstan analyse --no-progress --memory-limit=4G",
"pint-test": "vendor/bin/pint --preset=psr12 --test",
"pint": "vendor/bin/pint --preset=psr12"
},
"config": {
"allow-plugins": {
Expand Down
4 changes: 2 additions & 2 deletions src/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function fromSource(CriteriaSource $source): self
{
return self::create(
groups: map(
fn(array $g): FilterGroup => FilterGroup::fromArray($g),
fn (array $g): FilterGroup => FilterGroup::fromArray($g),
$source->filterGroups()
),
order: Order::create($source->orderBy(), OrderType::make($source->orderType())),
Expand Down Expand Up @@ -230,7 +230,7 @@ public function pageOffset(): int

public function __toString(): string
{
$groups = join('||', map(fn(FilterGroup $group): string => $group->__toString(), $this->groups));
$groups = join('||', map(fn (FilterGroup $group): string => $group->__toString(), $this->groups));
$order = $this->order->__toString();
$page = $this->page->__toString();

Expand Down
2 changes: 1 addition & 1 deletion src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function create(string $field, Operator $operator, bool|float|int|
public static function fromArray(array $filter): self
{
// check if the array is indexed or associative.
$isIndexed = fn($source): bool => ([] !== $source) && array_keys($source) === range(0, count($source) - 1);
$isIndexed = fn ($source): bool => ([] !== $source) && array_keys($source) === range(0, count($source) - 1);

return ($isIndexed($filter))
? self::create(
Expand Down
6 changes: 3 additions & 3 deletions src/FilterGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function create(Filter ...$filters): self
public static function fromArray(array $filters): self
{
return self::create(
...map(fn(array $filter): Filter => Filter::fromArray($filter), $filters)
...map(fn (array $filter): Filter => Filter::fromArray($filter), $filters)
);
}

Expand All @@ -60,7 +60,7 @@ public static function fromArray(array $filters): self
*/
public function addFilter(Filter $new): self
{
if ($this->filter(fn(Filter $filter): bool => $filter->equals($new))->count() > 0) {
if ($this->filter(fn (Filter $filter): bool => $filter->equals($new))->count() > 0) {
return $this;
}

Expand Down Expand Up @@ -196,6 +196,6 @@ public function addFilterNotContains(string $field, string $value): self
*/
public function __toString(): string
{
return join('+', map(fn(Filter $filter): string => $filter->__toString(), $this));
return join('+', map(fn (Filter $filter): string => $filter->__toString(), $this));
}
}
4 changes: 2 additions & 2 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ final class Page implements ValueObject
{
use IsValueObject;

const DEFAULT_LIMIT = 25;
const DEFAULT_OFFSET = 0;
public const DEFAULT_LIMIT = 25;
public const DEFAULT_OFFSET = 0;

/**
* Page constructor.
Expand Down
13 changes: 8 additions & 5 deletions tests/CriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use ComplexHeart\Domain\Criteria\Page;

test('Criteria should be successfully created from source.', function () {
$c = Criteria::fromSource(new class implements CriteriaSource {
$c = Criteria::fromSource(new class () implements CriteriaSource {
public function filterGroups(): array
{
return [
Expand Down Expand Up @@ -59,7 +59,7 @@ public function pageNumber(): int

test('Criteria should throw exception for invalid filter groups.', function () {
try {
Criteria::default()->withFilterGroup(fn() => [1, 2, 3]);
Criteria::default()->withFilterGroup(fn () => [1, 2, 3]);
} catch (CriteriaError $e) {
expect($e->violations())->toHaveCount(1);
}
Expand Down Expand Up @@ -119,11 +119,13 @@ public function pageNumber(): int

test('Criteria should add or filter group to criteria object.', function () {
$c = Criteria::default()
->withFilterGroup(FilterGroup::create()
->withFilterGroup(
FilterGroup::create()
->addFilterEqual('name', 'Vincent')
->addFilterEqual('status', 'deceased')
)
->withFilterGroup(FilterGroup::create()
->withFilterGroup(
FilterGroup::create()
->addFilterEqual('name', 'Jules')
->addFilterEqual('deceased', 'alive')
);
Expand All @@ -137,7 +139,8 @@ public function pageNumber(): int

test('Criteria should be correctly serialized to string.', function () {
$c = Criteria::default()
->withFilterGroup(FilterGroup::create()
->withFilterGroup(
FilterGroup::create()
->addFilterEqual('name', 'Vincent')
->addFilterGreaterOrEqualThan('age', '35')
)
Expand Down
2 changes: 0 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@
| global functions to help you to reduce the number of lines of code in your test files.
|
*/