Conditions | 4 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 36 |
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 |
||
88 | public function testFilterWillApplyIsEqualFiltering(): void |
||
89 | { |
||
90 | $filter = new IsEqual($this->queryFilterManager); |
||
91 | |||
92 | $fieldName = 'FieldNameTest'; |
||
93 | $criteria = [ |
||
94 | 'field' => $fieldName, |
||
95 | 'alias' => 'test', |
||
96 | 'where' => WhereType::AND, |
||
97 | 'value' => 123, |
||
98 | 'format' => null, |
||
99 | ]; |
||
100 | |||
101 | $this->metadata->expects($this->once()) |
||
102 | ->method('hasField') |
||
103 | ->with($fieldName) |
||
104 | ->willReturn(true); |
||
105 | |||
106 | /** @var Expr|MockObject $expr */ |
||
107 | $expr = $this->createMock(Expr::class); |
||
108 | |||
109 | $this->queryBuilder->expects($this->once()) |
||
110 | ->method('expr') |
||
111 | ->willReturn($expr); |
||
112 | |||
113 | /** @var Expr\Comparison|MockObject $eq */ |
||
114 | $eq = $this->createMock(Expr\Comparison::class); |
||
115 | |||
116 | $isEqualString = $criteria['alias'] . '.' . $fieldName . '=' . ':param_name'; |
||
117 | $expr->expects($this->once()) |
||
118 | ->method('eq') |
||
119 | ->with($criteria['alias'] . '.' . $fieldName, $this->stringStartsWith(':')) |
||
120 | ->willReturn($eq); |
||
121 | |||
122 | $eq->expects($this->once()) |
||
123 | ->method('__toString') |
||
124 | ->willReturn($isEqualString); |
||
125 | |||
126 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
127 | ? 'andWhere' |
||
128 | : 'orWhere'; |
||
129 | |||
130 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
131 | |||
132 | if (array_key_exists('value', $criteria)) { |
||
133 | $this->queryBuilder->expects($this->once()) |
||
134 | ->method('setParameter') |
||
135 | ->with($this->callback(static function ($argument) { |
||
136 | return is_string($argument); |
||
137 | }), $criteria['value']); |
||
138 | } |
||
139 | |||
140 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
141 | } |
||
143 |