Skip to content

Commit 944884f

Browse files
authored
Feature/PHP 8.1 Upgrade (#13)
* Now the minimum php version is 8.1. * Updated Operator class to use Enums. * Added several mixed type hint.
1 parent 0337a91 commit 944884f

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php-version: [ '8.0', '8.1 ']
15+
php-version: [ '8.1' ]
1616

1717
steps:
1818
- name: Checkout source code

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": "^8.0.2",
14+
"php": "^8.1.0",
1515
"complex-heart/domain-model": "^2.0.0",
1616
"ext-json": "*"
1717
},
1818
"require-dev": {
19-
"phpstan/phpstan": "^1.9.0",
20-
"pestphp/pest": "^1.4"
19+
"pestphp/pest": "^1.22.3",
20+
"pestphp/pest-plugin-mock": "^1.0.0",
21+
"pestphp/pest-plugin-faker": "^1.0.0",
22+
"phpstan/phpstan": "^1.9.0"
2123
},
2224
"autoload": {
2325
"psr-4": {
@@ -31,6 +33,7 @@
3133
},
3234
"scripts": {
3335
"test": "vendor/bin/pest --configuration=phpunit.xml --coverage-clover=coverage.xml --log-junit=test.xml",
36+
"test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage-html=coverage",
3437
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=5"
3538
},
3639
"config": {

src/Domain/Filter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class Filter implements ValueObject
3636
*
3737
* @var mixed
3838
*/
39-
private $value; // @phpstan-ignore-line
39+
private mixed $value; // @phpstan-ignore-line
4040

4141
/**
4242
* Filter constructor.
@@ -45,7 +45,7 @@ final class Filter implements ValueObject
4545
* @param Operator $operator
4646
* @param mixed $value
4747
*/
48-
public function __construct(string $field, Operator $operator, $value)
48+
public function __construct(string $field, Operator $operator, mixed $value)
4949
{
5050
$this->initialize(compact('field', 'operator', 'value'));
5151
}
@@ -59,7 +59,7 @@ public function __construct(string $field, Operator $operator, $value)
5959
*
6060
* @return Filter
6161
*/
62-
public static function create(string $field, Operator $operator, $value): self
62+
public static function create(string $field, Operator $operator, mixed $value): self
6363
{
6464
return new self($field, $operator, $value);
6565
}
@@ -70,8 +70,8 @@ public static function createFromArray(array $filter): self
7070
$isIndexed = fn($source): bool => ([] !== $source) && array_keys($source) === range(0, count($source) - 1);
7171

7272
return ($isIndexed($filter))
73-
? self::create($filter[0], new Operator($filter[1]), $filter[2])
74-
: self::create($filter['field'], new Operator($filter['operator']), $filter['value']);
73+
? self::create($filter[0], Operator::make($filter[1]), $filter[2])
74+
: self::create($filter['field'], Operator::make($filter['operator']), $filter['value']);
7575
}
7676

7777
public static function createEqual(string $field, $value): self
@@ -144,7 +144,7 @@ public function operator(): Operator
144144
*
145145
* @return mixed
146146
*/
147-
public function value()
147+
public function value(): mixed
148148
{
149149
return $this->value;
150150
}
@@ -154,7 +154,7 @@ public function __toString(): string
154154
return sprintf(
155155
'%s.%s.%s',
156156
$this->field(),
157-
$this->operator(),
157+
$this->operator()->value,
158158
is_array($this->value())
159159
? implode('|', $this->value())
160160
: $this->value()

src/Domain/Operator.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,72 @@
44

55
namespace ComplexHeart\Domain\Criteria;
66

7-
use ComplexHeart\Domain\Model\ValueObjects\EnumValue;
87

98
/**
109
* Class Operator
1110
*
1211
* @author Unay Santisteban <usantisteban@othercode.es>
1312
* @package ComplexHeart\Domain\Criteria
1413
*/
15-
final class Operator extends EnumValue
14+
enum Operator: string
1615
{
17-
public const EQUAL = '=';
18-
public const NOT_EQUAL = '!=';
19-
public const GT = '>';
20-
public const GTE = '>=';
21-
public const LT = '<';
22-
public const LTE = '<=';
23-
public const IN = 'in';
24-
public const NOT_IN = 'notIn';
25-
public const LIKE = 'like';
16+
case EQUAL = '=';
17+
case NOT_EQUAL = '!=';
18+
case GT = '>';
19+
case GTE = '>=';
20+
case LT = '<';
21+
case LTE = '<=';
22+
case IN = 'in';
23+
case NOT_IN = 'notIn';
24+
case LIKE = 'like';
25+
26+
public static function make(string $value): self
27+
{
28+
return self::from($value);
29+
}
2630

2731
public static function equal(): self
2832
{
29-
return new self(self::EQUAL);
33+
return self::EQUAL;
3034
}
3135

3236
public static function notEqual(): self
3337
{
34-
return new self(self::NOT_EQUAL);
38+
return self::NOT_EQUAL;
3539
}
3640

3741
public static function gt(): self
3842
{
39-
return new self(self::GT);
43+
return self::GT;
4044
}
4145

4246
public static function gte(): self
4347
{
44-
return new self(self::GTE);
48+
return self::GTE;
4549
}
4650

4751
public static function lt(): self
4852
{
49-
return new self(self::LT);
53+
return self::LT;
5054
}
5155

5256
public static function lte(): self
5357
{
54-
return new self(self::LTE);
58+
return self::LTE;
5559
}
5660

5761
public static function in(): self
5862
{
59-
return new self(self::IN);
63+
return self::IN;
6064
}
6165

6266
public static function notIn(): self
6367
{
64-
return new self(self::NOT_IN);
68+
return self::NOT_IN;
6569
}
6670

6771
public static function like(): self
6872
{
69-
return new self(self::LIKE);
73+
return self::LIKE;
7074
}
71-
}
75+
}

0 commit comments

Comments
 (0)