| Conditions | 2 |
| Paths | 2 |
| Total Lines | 88 |
| Code Lines | 52 |
| 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 |
||
| 49 | public function testFilterWillApplyTheProvidedConditions(?string $whereType): void |
||
| 50 | { |
||
| 51 | $criteria = [ |
||
| 52 | 'conditions' => [ |
||
| 53 | [ |
||
| 54 | 'name' => 'eq', |
||
| 55 | 'field' => 'test', |
||
| 56 | 'value' => 1, |
||
| 57 | ], |
||
| 58 | [ |
||
| 59 | 'name' => 'meq', |
||
| 60 | 'field' => 'hello', |
||
| 61 | 'value' => 'test', |
||
| 62 | ], |
||
| 63 | ], |
||
| 64 | ]; |
||
| 65 | |||
| 66 | if (isset($whereType)) { |
||
| 67 | $criteria['where'] = $whereType; |
||
| 68 | } |
||
| 69 | |||
| 70 | $filter = new AndX($this->queryFilterManager, $this->typecaster); |
||
| 71 | |||
| 72 | $className = 'FooEntity'; |
||
| 73 | |||
| 74 | /** @var QueryBuilderInterface&MockObject $qb */ |
||
| 75 | $qb = $this->createMock(QueryBuilderInterface::class); |
||
| 76 | |||
| 77 | $this->queryBuilder->expects($this->once()) |
||
| 78 | ->method('createQueryBuilder') |
||
| 79 | ->willReturn($qb); |
||
| 80 | |||
| 81 | $this->metadata->expects($this->once()) |
||
| 82 | ->method('getName') |
||
| 83 | ->willReturn($className); |
||
| 84 | |||
| 85 | $this->queryFilterManager->expects($this->once()) |
||
| 86 | ->method('filter') |
||
| 87 | ->with($qb, $className, ['filters' => $criteria['conditions']]); |
||
| 88 | |||
| 89 | /** @var DoctrineAndx&MockObject $where */ |
||
| 90 | $where = $this->createMock(DoctrineAndx::class); |
||
| 91 | |||
| 92 | $queryParts = [ |
||
| 93 | 'where' => $where, |
||
| 94 | ]; |
||
| 95 | |||
| 96 | $qb->expects($this->once()) |
||
| 97 | ->method('getQueryParts') |
||
| 98 | ->willReturn($queryParts); |
||
| 99 | |||
| 100 | /** @var Expr&MockObject $expr */ |
||
| 101 | $expr = $this->createMock(Expr::class); |
||
| 102 | |||
| 103 | $this->queryBuilder->expects($this->once()) |
||
| 104 | ->method('expr') |
||
| 105 | ->willReturn($expr); |
||
| 106 | |||
| 107 | /** @var DoctrineAndx&MockObject $doctrineAndX */ |
||
| 108 | $doctrineAndX = $this->createMock(DoctrineAndx::class); |
||
| 109 | |||
| 110 | $expr->expects($this->once()) |
||
| 111 | ->method('andX') |
||
| 112 | ->willReturn($doctrineAndX); |
||
| 113 | |||
| 114 | /** @var Expr\Comparison[] $whereParts */ |
||
| 115 | $whereParts = [ |
||
| 116 | $this->createMock(Expr\Comparison::class), |
||
| 117 | $this->createMock(Expr\Comparison::class), |
||
| 118 | ]; |
||
| 119 | |||
| 120 | $where->expects($this->once()) |
||
| 121 | ->method('getParts') |
||
| 122 | ->willReturn($whereParts); |
||
| 123 | |||
| 124 | $doctrineAndX->expects($this->once()) |
||
| 125 | ->method('addMultiple') |
||
| 126 | ->with($whereParts); |
||
| 127 | |||
| 128 | $this->queryBuilder->expects($this->once()) |
||
| 129 | ->method('andWhere') |
||
| 130 | ->with($doctrineAndX); |
||
| 131 | |||
| 132 | $this->queryBuilder->expects($this->once()) |
||
| 133 | ->method('mergeParameters') |
||
| 134 | ->with($qb); |
||
| 135 | |||
| 136 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
| 137 | } |
||
| 150 |