| Conditions | 5 |
| Paths | 16 |
| Total Lines | 71 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 94 | public function testFilterWillApplyFiltering(array $criteria): void |
||
| 95 | { |
||
| 96 | $fieldName = $criteria['field'] ?? 'testFieldName'; |
||
| 97 | $alias = $criteria['alias'] ?? null; |
||
| 98 | |||
| 99 | $mapping = [ |
||
| 100 | 'type' => 4 |
||
| 101 | ]; |
||
| 102 | |||
| 103 | $this->metadata->expects($this->once()) |
||
| 104 | ->method('hasField') |
||
| 105 | ->with($fieldName) |
||
| 106 | ->willReturn(true); |
||
| 107 | |||
| 108 | $this->metadata->expects($this->once()) |
||
| 109 | ->method('hasAssociation') |
||
| 110 | ->with($fieldName) |
||
| 111 | ->willReturn(true); |
||
| 112 | |||
| 113 | $this->metadata->expects($this->once()) |
||
| 114 | ->method('getAssociationMapping') |
||
| 115 | ->with($fieldName) |
||
| 116 | ->willReturn($mapping); |
||
| 117 | |||
| 118 | /** @var Expr&MockObject $expr */ |
||
| 119 | $expr = $this->createMock(Expr::class); |
||
| 120 | |||
| 121 | $this->queryBuilder->expects($this->once()) |
||
| 122 | ->method('expr') |
||
| 123 | ->willReturn($expr); |
||
| 124 | |||
| 125 | /** @var Expr\Comparison&MockObject $comparisonExpr */ |
||
| 126 | $comparisonExpr = $this->createMock(Expr\Comparison::class); |
||
| 127 | |||
| 128 | if (null === $alias) { |
||
| 129 | $alias = 'entity'; |
||
| 130 | $this->queryBuilder->expects($this->once()) |
||
| 131 | ->method('getRootAlias') |
||
| 132 | ->willReturn($alias); |
||
| 133 | } |
||
| 134 | |||
| 135 | $expressionString = $this->getExpressionString($fieldName, $alias, $criteria); |
||
| 136 | |||
| 137 | $expr->expects($this->once()) |
||
| 138 | ->method($this->expressionMethodName) |
||
| 139 | ->willReturn($comparisonExpr); |
||
| 140 | |||
| 141 | $comparisonExpr->expects($this->once()) |
||
| 142 | ->method('__toString') |
||
| 143 | ->willReturn($expressionString); |
||
| 144 | |||
| 145 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
| 146 | ? 'andWhere' |
||
| 147 | : 'orWhere'; |
||
| 148 | |||
| 149 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
| 150 | |||
| 151 | if (array_key_exists('value', $criteria)) { |
||
| 152 | $this->typecaster->expects($this->once()) |
||
| 153 | ->method('typecast') |
||
| 154 | ->with($this->metadata, $fieldName, $criteria['value']) |
||
| 155 | ->willReturn($criteria['value']); |
||
| 156 | |||
| 157 | $this->queryBuilder->expects($this->once()) |
||
| 158 | ->method('setParameter') |
||
| 159 | ->with($this->callback(static function ($argument) { |
||
| 160 | return is_string($argument); |
||
| 161 | }), $criteria['value']); |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
| 165 | } |
||
| 185 |
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.