Conditions | 1 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
173 | public function testFilterWillApplyExpectedJoinWithConditions(): void |
||
174 | { |
||
175 | $fieldName = 'foo'; |
||
176 | $fieldAlias = 't'; |
||
177 | $joinAlias = 'a'; |
||
178 | |||
179 | $conditions = [ |
||
180 | [ |
||
181 | 'name' => 'eq', |
||
182 | 'field' => 'id', |
||
183 | 'alias' => $fieldAlias, |
||
184 | 'value' => $joinAlias . '.id', |
||
185 | ] |
||
186 | ]; |
||
187 | |||
188 | $criteria = [ |
||
189 | 'field' => $fieldAlias . '.' . $fieldName, |
||
190 | 'alias' => $joinAlias, |
||
191 | 'condition_type' => JoinConditionType::WITH->value, |
||
192 | 'conditions' => $conditions, |
||
193 | ]; |
||
194 | |||
195 | $associationMapping = [ |
||
196 | 'targetEntity' => 'Bar', |
||
197 | ]; |
||
198 | |||
199 | $this->metadata->expects($this->once()) |
||
200 | ->method('getAssociationMapping') |
||
201 | ->with($fieldName) |
||
202 | ->willReturn($associationMapping); |
||
203 | |||
204 | $this->metadata->expects($this->once()) |
||
205 | ->method('hasField') |
||
206 | ->with($fieldName) |
||
207 | ->willReturn(true); |
||
208 | |||
209 | /** @var QueryBuilderInterface&MockObject $conditionsQueryBuilder */ |
||
210 | $conditionsQueryBuilder = $this->createMock(QueryBuilderInterface::class); |
||
211 | $this->queryBuilder->expects($this->once()) |
||
212 | ->method('createQueryBuilder') |
||
213 | ->willReturn($conditionsQueryBuilder); |
||
214 | |||
215 | $this->queryFilterManager->expects($this->once()) |
||
216 | ->method('filter') |
||
217 | ->with( |
||
218 | $conditionsQueryBuilder, |
||
219 | $associationMapping['targetEntity'], |
||
220 | [ |
||
221 | 'filters' => [ |
||
222 | [ |
||
223 | 'name' => AndX::class, |
||
224 | 'conditions' => $conditions, |
||
225 | 'where' => null, |
||
226 | ] |
||
227 | ] |
||
228 | ] |
||
229 | ); |
||
230 | |||
231 | /** @var DoctrineAndX&MockObject $andX */ |
||
232 | $andX = $this->createMock(DoctrineAndX::class); |
||
233 | $queryParts = [ |
||
234 | 'where' => $andX, |
||
235 | ]; |
||
236 | $andXParts = [ |
||
237 | $fieldAlias . '.id = ' . $joinAlias . '.id', |
||
238 | ]; |
||
239 | |||
240 | $conditionsQueryBuilder->expects($this->once()) |
||
241 | ->method('getQueryParts') |
||
242 | ->willReturn($queryParts); |
||
243 | |||
244 | /** @var Expr&MockObject $expr */ |
||
245 | $expr = $this->createMock(Expr::class); |
||
246 | $this->queryBuilder->expects($this->once()) |
||
247 | ->method('expr') |
||
248 | ->willReturn($expr); |
||
249 | |||
250 | /** @var DoctrineAndX&MockObject $conditionAndX */ |
||
251 | $conditionAndX = $this->createMock(DoctrineAndX::class); |
||
252 | $expr->expects($this->once()) |
||
253 | ->method('andX') |
||
254 | ->willReturn($conditionAndX); |
||
255 | |||
256 | $conditionAndX->expects($this->once()) |
||
257 | ->method('addMultiple') |
||
258 | ->willReturn($andXParts); |
||
259 | |||
260 | $this->queryBuilder->expects($this->once()) |
||
261 | ->method('mergeParameters') |
||
262 | ->with($conditionsQueryBuilder); |
||
263 | |||
264 | $this->assertFilterJoin( |
||
265 | $this->queryBuilder, |
||
266 | $fieldAlias . '.' . $fieldName, |
||
267 | $joinAlias, |
||
268 | $conditionAndX, |
||
269 | JoinConditionType::WITH |
||
270 | ); |
||
271 | |||
272 | $this->filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
273 | } |
||
275 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.