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