@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(SpecificationInterface $expression) |
21 | 21 | { |
22 | - if (!$expression instanceof AbstractSorter) { |
|
22 | + if (!$expression instanceof AbstractSorter){ |
|
23 | 23 | throw new \LogicException('Only sorters allowed'); |
24 | 24 | } |
25 | 25 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | { |
34 | 34 | $injector = static::INJECTION; |
35 | 35 | |
36 | - if (!class_exists($injector)) { |
|
36 | + if (!class_exists($injector)){ |
|
37 | 37 | throw new \LogicException( |
38 | 38 | sprintf('Class "%s" does not exist', $injector) |
39 | 39 | ); |
40 | 40 | } |
41 | 41 | |
42 | - if (!is_subclass_of($injector, FragmentInterface::class)) { |
|
42 | + if (!is_subclass_of($injector, FragmentInterface::class)){ |
|
43 | 43 | throw new \LogicException( |
44 | 44 | 'INJECTION class does not implement FragmentInterface' |
45 | 45 | ); |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
55 | 55 | { |
56 | - if (!$this->targetAcceptable($source)) { |
|
56 | + if (!$this->targetAcceptable($source)){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | - if ($specification instanceof Specification\FilterInterface) { |
|
60 | + if ($specification instanceof Specification\FilterInterface){ |
|
61 | 61 | return $this->writeFilter($source, $specification, $compiler); |
62 | 62 | } |
63 | 63 | |
64 | - if ($specification instanceof Specification\SorterInterface) { |
|
64 | + if ($specification instanceof Specification\SorterInterface){ |
|
65 | 65 | return $this->writeSorter($source, $specification, $compiler); |
66 | 66 | } |
67 | 67 | |
68 | - if ($specification instanceof Specification\Pagination\Limit) { |
|
68 | + if ($specification instanceof Specification\Pagination\Limit){ |
|
69 | 69 | return $source->limit($specification->getValue()); |
70 | 70 | } |
71 | 71 | |
72 | - if ($specification instanceof Specification\Pagination\Offset) { |
|
72 | + if ($specification instanceof Specification\Pagination\Offset){ |
|
73 | 73 | return $source->offset($specification->getValue()); |
74 | 74 | } |
75 | 75 | |
@@ -84,15 +84,15 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function writeFilter($source, Specification\FilterInterface $filter, Compiler $compiler) |
86 | 86 | { |
87 | - if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) { |
|
87 | + if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map){ |
|
88 | 88 | return $source->where(static function () use ($compiler, $filter, $source): void { |
89 | 89 | $compiler->compile($source, ...$filter->getFilters()); |
90 | 90 | }); |
91 | 91 | } |
92 | 92 | |
93 | - if ($filter instanceof Specification\Filter\Any) { |
|
93 | + if ($filter instanceof Specification\Filter\Any){ |
|
94 | 94 | return $source->where(static function () use ($compiler, $filter, $source): void { |
95 | - foreach ($filter->getFilters() as $subFilter) { |
|
95 | + foreach ($filter->getFilters() as $subFilter){ |
|
96 | 96 | $source->orWhere(static function () use ($compiler, $subFilter, $source): void { |
97 | 97 | $compiler->compile($source, $subFilter); |
98 | 98 | }); |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | }); |
101 | 101 | } |
102 | 102 | |
103 | - if ($filter instanceof Specification\Filter\InjectionFilter) { |
|
103 | + if ($filter instanceof Specification\Filter\InjectionFilter){ |
|
104 | 104 | $expression = $filter->getFilter(); |
105 | - if ($expression instanceof Specification\Filter\Expression) { |
|
105 | + if ($expression instanceof Specification\Filter\Expression){ |
|
106 | 106 | return $source->where( |
107 | 107 | $filter->getInjection(), |
108 | 108 | $this->getExpressionOperator($expression), |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - if ($filter instanceof Specification\Filter\Expression) { |
|
114 | + if ($filter instanceof Specification\Filter\Expression){ |
|
115 | 115 | return $source->where( |
116 | 116 | $filter->getExpression(), |
117 | 117 | $this->getExpressionOperator($filter), |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function getExpressionOperator(Specification\Filter\Expression $filter): string |
130 | 130 | { |
131 | - if ($filter instanceof Specification\Filter\Like) { |
|
131 | + if ($filter instanceof Specification\Filter\Like){ |
|
132 | 132 | return 'LIKE'; |
133 | 133 | } |
134 | 134 | |
135 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
135 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
136 | 136 | return static::ARRAY_OPERATORS[get_class($filter)]; |
137 | 137 | } |
138 | 138 | |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | */ |
146 | 146 | protected function getExpressionArgs(Specification\Filter\Expression $filter): array |
147 | 147 | { |
148 | - if ($filter instanceof Specification\Filter\Like) { |
|
148 | + if ($filter instanceof Specification\Filter\Like){ |
|
149 | 149 | return [sprintf($filter->getPattern(), $this->fetchValue($filter->getValue()))]; |
150 | 150 | } |
151 | 151 | |
152 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
152 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
153 | 153 | return [new Parameter($this->fetchValue($filter->getValue()))]; |
154 | 154 | } |
155 | 155 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | */ |
165 | 165 | protected function writeSorter($source, Specification\SorterInterface $sorter, Compiler $compiler) |
166 | 166 | { |
167 | - if ($sorter instanceof Specification\Sorter\SorterSet) { |
|
168 | - foreach ($sorter->getSorters() as $subSorter) { |
|
167 | + if ($sorter instanceof Specification\Sorter\SorterSet){ |
|
168 | + foreach ($sorter->getSorters() as $subSorter){ |
|
169 | 169 | $source = $compiler->compile($source, $subSorter); |
170 | 170 | } |
171 | 171 | |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | if ( |
176 | 176 | $sorter instanceof Specification\Sorter\AscSorter |
177 | 177 | || $sorter instanceof Specification\Sorter\DescSorter |
178 | - ) { |
|
178 | + ){ |
|
179 | 179 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)]; |
180 | - foreach ($sorter->getExpressions() as $expression) { |
|
180 | + foreach ($sorter->getExpressions() as $expression){ |
|
181 | 181 | $source = $source->orderBy($expression, $direction); |
182 | 182 | } |
183 | 183 | |
184 | 184 | return $source; |
185 | 185 | } |
186 | 186 | |
187 | - if ($sorter instanceof InjectionSorter) { |
|
187 | + if ($sorter instanceof InjectionSorter){ |
|
188 | 188 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)] ?? 'ASC'; |
189 | - foreach ($sorter->getInjections() as $injection) { |
|
189 | + foreach ($sorter->getInjections() as $injection){ |
|
190 | 190 | $source = $source->orderBy($injection, $direction); |
191 | 191 | } |
192 | 192 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function fetchValue($value) |
206 | 206 | { |
207 | - if ($value instanceof Specification\ValueInterface) { |
|
207 | + if ($value instanceof Specification\ValueInterface){ |
|
208 | 208 | throw new CompilerException('Value expects user input, none given'); |
209 | 209 | } |
210 | 210 | |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | */ |
218 | 218 | protected function targetAcceptable($target): bool |
219 | 219 | { |
220 | - if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) { |
|
220 | + if (class_exists(SelectQuery::class) && $target instanceof SelectQuery){ |
|
221 | 221 | return true; |
222 | 222 | } |
223 | 223 | |
224 | - if (class_exists(Select::class) && $target instanceof Select) { |
|
224 | + if (class_exists(Select::class) && $target instanceof Select){ |
|
225 | 225 | return true; |
226 | 226 | } |
227 | 227 |