| 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 |
||
| 63 | public function testFilterWillApplyFiltering(array $criteria): void |
||
| 64 | { |
||
| 65 | $fieldName = $criteria['field'] ?? 'testFieldName'; |
||
| 66 | $alias = $criteria['alias'] ?? null; |
||
| 67 | |||
| 68 | $this->metadata->expects($this->once()) |
||
| 69 | ->method('hasField') |
||
| 70 | ->with($fieldName) |
||
| 71 | ->willReturn(true); |
||
| 72 | |||
| 73 | /** @var Expr|MockObject $expr */ |
||
| 74 | $expr = $this->createMock(Expr::class); |
||
| 75 | |||
| 76 | $this->queryBuilder->expects($this->once()) |
||
| 77 | ->method('expr') |
||
| 78 | ->willReturn($expr); |
||
| 79 | |||
| 80 | /** @var Expr\Comparison|MockObject $comparisonExpr */ |
||
| 81 | $comparisonExpr = $this->createMock(Expr\Comparison::class); |
||
| 82 | |||
| 83 | if (null === $alias) { |
||
| 84 | $alias = 'entity'; |
||
| 85 | $this->queryBuilder->expects($this->once()) |
||
| 86 | ->method('getRootAlias') |
||
| 87 | ->willReturn($alias); |
||
| 88 | } |
||
| 89 | |||
| 90 | $expressionString = $this->getExpressionString($fieldName, $alias, $criteria); |
||
| 91 | |||
| 92 | $expr->expects($this->once()) |
||
| 93 | ->method($this->expressionMethodName) |
||
| 94 | ->willReturn($comparisonExpr); |
||
| 95 | |||
| 96 | $comparisonExpr->expects($this->once()) |
||
| 97 | ->method('__toString') |
||
| 98 | ->willReturn($expressionString); |
||
| 99 | |||
| 100 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
| 101 | ? 'andWhere' |
||
| 102 | : 'orWhere'; |
||
| 103 | |||
| 104 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
| 105 | |||
| 106 | if (array_key_exists('value', $criteria)) { |
||
| 107 | $this->typecaster->expects($this->once()) |
||
| 108 | ->method('typecast') |
||
| 109 | ->with($this->metadata, $fieldName, $criteria['value']) |
||
| 110 | ->willReturn($criteria['value']); |
||
| 111 | |||
| 112 | $this->queryBuilder->expects($this->once()) |
||
| 113 | ->method('setParameter') |
||
| 114 | ->with($this->callback(static function ($argument) { |
||
| 115 | return is_string($argument); |
||
| 116 | }), $criteria['value']); |
||
| 117 | } |
||
| 118 | |||
| 119 | $this->filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
| 120 | } |
||
| 143 |