Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| UnaryAbstract | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toSql | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| toInMemoryFilter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSqlTemplate | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| evaluateUnary | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| createUnaryFilter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Domain\Specification; |
| 11 | |
| 12 | use Override; |
| 13 | |
| 14 | abstract readonly class UnaryAbstract extends SpecificationAbstract implements SpecificationInterface |
| 15 | { |
| 16 | public function __construct(protected SpecificationInterface $specification) {} |
| 17 | |
| 18 | #[Override] |
| 19 | public function toSql(): array |
| 20 | { |
| 21 | $specSql = $this->specification->toSql(); |
| 22 | |
| 23 | $template = $this->getSqlTemplate(); |
| 24 | $sql = str_replace('SPEC', $specSql['sql'], $template); |
| 25 | |
| 26 | return [ |
| 27 | 'sql' => $sql, |
| 28 | 'params' => $specSql['params'], |
| 29 | ]; |
| 30 | } |
| 31 | |
| 32 | #[Override] |
| 33 | public function toInMemoryFilter(): callable |
| 34 | { |
| 35 | $filter = $this->specification->toInMemoryFilter(); |
| 36 | |
| 37 | return $this->createUnaryFilter($filter); |
| 38 | } |
| 39 | |
| 40 | abstract protected function getSqlTemplate(): string; |
| 41 | |
| 42 | abstract protected function evaluateUnary(callable $filter, array $row): bool; |
| 43 | |
| 44 | private function createUnaryFilter(callable $filter): callable |
| 45 | { |
| 46 | return fn (array $row): bool => $this->evaluateUnary($filter, $row); |
| 47 | } |
| 48 | } |