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