Conditions | 7 |
Paths | 32 |
Total Lines | 101 |
Code Lines | 68 |
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 |
||
92 | public function testFilterIsBetween( |
||
93 | array $criteria, |
||
94 | ?string $whereType = null, |
||
95 | ?string $alias = null, |
||
96 | ?string $formatType = null |
||
97 | ): void { |
||
98 | /** @var IsBetween|MockObject $filter */ |
||
99 | $filter = $this->getMockBuilder(IsBetween::class) |
||
100 | ->setConstructorArgs([$this->queryFilterManager, $this->typecaster]) |
||
101 | ->onlyMethods(['createParamName']) |
||
102 | ->getMock(); |
||
103 | |||
104 | $rootAlias = 'entity'; |
||
105 | $from = $criteria['from'] ?? ''; |
||
106 | $to = $criteria['to'] ?? ''; |
||
107 | $fieldName = $criteria['field'] = $criteria['field'] ?? 'test'; |
||
108 | |||
109 | if (null !== $alias) { |
||
110 | $criteria['alias'] = $alias; |
||
111 | } |
||
112 | |||
113 | if (null !== $whereType) { |
||
114 | $criteria['where'] = $whereType; |
||
115 | } |
||
116 | |||
117 | if (null !== $formatType) { |
||
118 | $criteria['format'] = $formatType; |
||
119 | } |
||
120 | |||
121 | $this->metadata->expects($this->once()) |
||
122 | ->method('hasField') |
||
123 | ->with($fieldName) |
||
124 | ->willReturn(true); |
||
125 | |||
126 | if (empty($alias)) { |
||
127 | $alias = $rootAlias; |
||
128 | |||
129 | $this->queryBuilder->expects($this->once()) |
||
130 | ->method('getRootAlias') |
||
131 | ->willReturn($rootAlias); |
||
132 | } |
||
133 | |||
134 | /** @var Expr|MockObject $expr */ |
||
135 | $expr = $this->createMock(Expr::class); |
||
136 | |||
137 | $this->queryBuilder->expects($this->once()) |
||
138 | ->method('expr') |
||
139 | ->willReturn($expr); |
||
140 | |||
141 | $fromParam = $alias . 'abc123'; |
||
142 | $toParam = $alias . 'zyx999'; |
||
143 | |||
144 | $filter->expects($this->exactly(2)) |
||
145 | ->method('createParamName') |
||
146 | ->withConsecutive( |
||
147 | [$alias], |
||
148 | [$alias] |
||
149 | )->willReturnOnConsecutiveCalls( |
||
150 | $fromParam, |
||
151 | $toParam |
||
152 | ); |
||
153 | |||
154 | $isBetween = $alias . '.' . $fieldName . ' BETWEEN ' . $fromParam . ' AND ' . $toParam; |
||
155 | $expr->expects($this->once()) |
||
156 | ->method('between') |
||
157 | ->with( |
||
158 | $alias . '.' . $fieldName, |
||
159 | ':' . $fromParam, |
||
160 | ':' . $toParam |
||
161 | )->willReturn( |
||
162 | $isBetween |
||
163 | ); |
||
164 | |||
165 | if (null === $whereType || WhereType::AND === $whereType) { |
||
166 | $this->queryBuilder->expects($this->once()) |
||
167 | ->method('andWhere') |
||
168 | ->with($isBetween); |
||
169 | } else { |
||
170 | $this->queryBuilder->expects($this->once()) |
||
171 | ->method('orWhere') |
||
172 | ->with($isBetween); |
||
173 | } |
||
174 | |||
175 | $this->typecaster->expects($this->exactly(2)) |
||
176 | ->method('typecast') |
||
177 | ->withConsecutive( |
||
178 | [$this->metadata, $fieldName, $from, $formatType, []], |
||
179 | [$this->metadata, $fieldName, $to, $formatType, []], |
||
180 | )->willReturnOnConsecutiveCalls( |
||
181 | $from, |
||
182 | $to |
||
183 | ); |
||
184 | |||
185 | $this->queryBuilder->expects($this->exactly(2)) |
||
186 | ->method('setParameter') |
||
187 | ->withConsecutive( |
||
188 | [$fromParam, $from], |
||
189 | [$toParam, $to] |
||
190 | ); |
||
191 | |||
192 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
193 | } |
||
210 |