Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.43% covered (success)
96.43%
27 / 28
95.24% covered (success)
95.24%
20 / 21
CRAP
0.00% covered (danger)
0.00%
0 / 1
MapperExpressionBuilder
96.43% covered (success)
96.43%
27 / 28
95.24% covered (success)
95.24%
20 / 21
26
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 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
 mapField
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
6.07
1<?php
2
3declare(strict_types=1);
4
5namespace Symftony\Xpression\Expr;
6
7class MapperExpressionBuilder implements ExpressionBuilderInterface
8{
9    /**
10     * @param string[] $fieldMapping
11     */
12    public function __construct(
13        private ExpressionBuilderInterface $expressionBuilder,
14        private array $fieldMapping = [],
15    ) {}
16
17    public function getSupportedTokenType(): int
18    {
19        return $this->expressionBuilder->getSupportedTokenType();
20    }
21
22    public function parameter(mixed $value, bool $isValue = false): mixed
23    {
24        return $this->expressionBuilder->parameter($value, $isValue);
25    }
26
27    public function string(mixed $value): mixed
28    {
29        return $this->expressionBuilder->string($value);
30    }
31
32    public function isNull(string $field): mixed
33    {
34        return $this->expressionBuilder->isNull($this->mapField($field));
35    }
36
37    public function eq(string $field, mixed $value): mixed
38    {
39        return $this->expressionBuilder->eq($this->mapField($field), $value);
40    }
41
42    public function neq(string $field, mixed $value): mixed
43    {
44        return $this->expressionBuilder->neq($this->mapField($field), $value);
45    }
46
47    public function gt(string $field, mixed $value): mixed
48    {
49        return $this->expressionBuilder->gt($this->mapField($field), $value);
50    }
51
52    public function gte(string $field, mixed $value): mixed
53    {
54        return $this->expressionBuilder->gte($this->mapField($field), $value);
55    }
56
57    public function lt(string $field, mixed $value): mixed
58    {
59        return $this->expressionBuilder->lt($this->mapField($field), $value);
60    }
61
62    public function lte(string $field, mixed $value): mixed
63    {
64        return $this->expressionBuilder->lte($this->mapField($field), $value);
65    }
66
67    public function in(string $field, array $values): mixed
68    {
69        return $this->expressionBuilder->in($this->mapField($field), $values);
70    }
71
72    public function notIn(string $field, array $values): mixed
73    {
74        return $this->expressionBuilder->notIn($this->mapField($field), $values);
75    }
76
77    public function contains(string $field, mixed $value): mixed
78    {
79        return $this->expressionBuilder->contains($this->mapField($field), $value);
80    }
81
82    public function notContains(string $field, mixed $value): mixed
83    {
84        return $this->expressionBuilder->notContains($this->mapField($field), $value);
85    }
86
87    public function andX(array $expressions): mixed
88    {
89        return $this->expressionBuilder->andX($expressions);
90    }
91
92    public function nandX(array $expressions): mixed
93    {
94        return $this->expressionBuilder->nandX($expressions);
95    }
96
97    public function orX(array $expressions): mixed
98    {
99        return $this->expressionBuilder->orX($expressions);
100    }
101
102    public function norX(array $expressions): mixed
103    {
104        return $this->expressionBuilder->norX($expressions);
105    }
106
107    public function xorX(array $expressions): mixed
108    {
109        return $this->expressionBuilder->xorX($expressions);
110    }
111
112    private function mapField(mixed $field): mixed
113    {
114        if (
115            \is_array($field)
116            || \is_object($field) && !method_exists($field, '__toString')
117        ) {
118            return $field;
119        }
120
121        if (\array_key_exists((string) $field, $this->fieldMapping)) {
122            return sprintf($this->fieldMapping[(string) $field], $field);
123        }
124
125        if (\array_key_exists('*', $this->fieldMapping)) {
126            return sprintf($this->fieldMapping['*'], $field);
127        }
128
129        return $field;
130    }
131}