Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
19 / 19
CRAP
100.00% covered (success)
100.00%
1 / 1
ExprBuilder
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
19 / 19
19
100.00% covered (success)
100.00%
1 / 1
 getSupportedTokenType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parameter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 string
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNull
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 eq
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 neq
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 gt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 gte
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 lt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 lte
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 in
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 notIn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 contains
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 notContains
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 andX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 nandX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 orX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 norX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 xorX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Symftony\Xpression\Bridge\MongoDB;
6
7use Symftony\Xpression\Exception\Expr\UnsupportedExpressionTypeException;
8use Symftony\Xpression\Expr\ExpressionBuilderInterface;
9use Symftony\Xpression\Lexer;
10
11class ExprBuilder implements ExpressionBuilderInterface
12{
13    public function getSupportedTokenType(): int
14    {
15        return Lexer::T_ALL - Lexer::T_XOR;
16    }
17
18    public function parameter(mixed $value, bool $isValue = false): mixed
19    {
20        return $value;
21    }
22
23    public function string(mixed $value): mixed
24    {
25        return $value;
26    }
27
28    public function isNull(string $field): mixed
29    {
30        return [$field => null];
31    }
32
33    public function eq(string $field, mixed $value): mixed
34    {
35        return [$field => ['$eq' => $value]];
36    }
37
38    public function neq(string $field, mixed $value): mixed
39    {
40        return [$field => ['$ne' => $value]];
41    }
42
43    public function gt(string $field, mixed $value): mixed
44    {
45        return [$field => ['$gt' => $value]];
46    }
47
48    public function gte(string $field, mixed $value): mixed
49    {
50        return [$field => ['$gte' => $value]];
51    }
52
53    public function lt(string $field, mixed $value): mixed
54    {
55        return [$field => ['$lt' => $value]];
56    }
57
58    public function lte(string $field, mixed $value): mixed
59    {
60        return [$field => ['$lte' => $value]];
61    }
62
63    public function in(string $field, array $values): mixed
64    {
65        return [$field => ['$in' => $values]];
66    }
67
68    public function notIn(string $field, array $values): mixed
69    {
70        return [$field => ['$nin' => $values]];
71    }
72
73    public function contains(string $field, mixed $value): mixed
74    {
75        return [$field => ['$regex' => $value]];
76    }
77
78    public function notContains(string $field, mixed $value): mixed
79    {
80        return ['$not' => $this->contains($field, $value)];
81    }
82
83    public function andX(array $expressions): mixed
84    {
85        return ['$and' => $expressions];
86    }
87
88    // Not A AND B = Not A OR Not B
89    public function nandX(array $expressions): mixed
90    {
91        return $this->orX(array_map(static fn ($expression) => ['$not' => $expression], $expressions));
92    }
93
94    public function orX(array $expressions): mixed
95    {
96        return ['$or' => $expressions];
97    }
98
99    public function norX(array $expressions): mixed
100    {
101        return ['$nor' => $expressions];
102    }
103
104    public function xorX(array $expressions): mixed
105    {
106        throw new UnsupportedExpressionTypeException('xorX');
107    }
108}