| Conditions | 5 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 38 |
| 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 |
||
| 47 | public function testFilterWillApplyFiltering(array $criteria): void |
||
| 48 | { |
||
| 49 | $fieldName = $criteria['field'] ?? 'testFieldName'; |
||
| 50 | $alias = $criteria['alias'] ?? null; |
||
| 51 | |||
| 52 | $this->metadata->expects($this->once()) |
||
|
|
|||
| 53 | ->method('hasField') |
||
| 54 | ->with($fieldName) |
||
| 55 | ->willReturn(true); |
||
| 56 | |||
| 57 | /** @var Expr&MockObject $expr */ |
||
| 58 | $expr = $this->createMock(Expr::class); |
||
| 59 | |||
| 60 | $this->queryBuilder->expects($this->once()) |
||
| 61 | ->method('expr') |
||
| 62 | ->willReturn($expr); |
||
| 63 | |||
| 64 | /** @var Expr\Comparison&MockObject $comparisonExpr */ |
||
| 65 | $comparisonExpr = $this->createMock(Expr\Comparison::class); |
||
| 66 | |||
| 67 | if (null === $alias) { |
||
| 68 | $alias = 'entity'; |
||
| 69 | $this->queryBuilder->expects($this->once()) |
||
| 70 | ->method('getRootAlias') |
||
| 71 | ->willReturn($alias); |
||
| 72 | } |
||
| 73 | |||
| 74 | $expressionString = $this->getExpressionString($fieldName, $alias, $criteria); |
||
| 75 | |||
| 76 | $expr->expects($this->once()) |
||
| 77 | ->method($this->expressionMethodName) |
||
| 78 | ->willReturn($comparisonExpr); |
||
| 79 | |||
| 80 | $comparisonExpr->expects($this->once()) |
||
| 81 | ->method('__toString') |
||
| 82 | ->willReturn($expressionString); |
||
| 83 | |||
| 84 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
| 85 | ? 'andWhere' |
||
| 86 | : 'orWhere'; |
||
| 87 | |||
| 88 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
| 89 | |||
| 90 | if (array_key_exists('value', $criteria)) { |
||
| 91 | $this->typecaster->expects($this->once()) |
||
| 92 | ->method('typecast') |
||
| 93 | ->with($this->metadata, $fieldName, $criteria['value']) |
||
| 94 | ->willReturn($criteria['value']); |
||
| 95 | |||
| 96 | $this->queryBuilder->expects($this->once()) |
||
| 97 | ->method('setParameter') |
||
| 98 | ->with($this->callback(static function ($argument) { |
||
| 99 | return is_string($argument); |
||
| 100 | }), $criteria['value']); |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
| 104 | } |
||
| 117 |
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.