Conditions | 2 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
140 | public function testForecastOfOpportunitiesValuesWithCompareDate() |
||
141 | { |
||
142 | $start = new \DateTime(); |
||
143 | $start->setDate(2016, 6, 1)->setTime(0, 0, 0); |
||
144 | $end = clone $start; |
||
145 | $end->setDate(2016, 7, 1); |
||
146 | $diff = $start->diff($end); |
||
147 | $prevStart = clone $start; |
||
148 | $prevStart->sub($diff); |
||
149 | $prevEnd = clone $end; |
||
150 | $prevEnd->sub($diff); |
||
151 | $prevStart->setTime(0, 0, 0); |
||
152 | $prevEnd->setTime(23, 59, 59); |
||
153 | |||
154 | $dateRange = [ |
||
155 | 'start' => $start, |
||
156 | 'end' => $end, |
||
157 | 'prev_start' => $prevStart, |
||
158 | 'prev_end' => $prevEnd, |
||
159 | 'type' => AbstractDateFilterType::TYPE_BETWEEN, |
||
160 | ]; |
||
161 | $widgetOptions = new WidgetOptionBag( |
||
162 | [ |
||
163 | 'compareToDate' => ['useDate' => true, 'date' => null], |
||
164 | 'dateRange' => $dateRange |
||
165 | ] |
||
166 | ); |
||
167 | |||
168 | $forecastDataCallback = function ($users, $start, $end, $moment) { |
||
169 | if ($moment === null) { |
||
170 | return ['inProgressCount' => 5, 'budgetAmount' => 1000, 'weightedForecast' => 500]; |
||
171 | } |
||
172 | |||
173 | return ['inProgressCount' => 2, 'budgetAmount' => 200, 'weightedForecast' => 50]; |
||
174 | }; |
||
175 | $this->dateHelper |
||
176 | ->expects($this->once()) |
||
177 | ->method('getCurrentDateTime') |
||
178 | ->willReturn(new \DateTime()); |
||
179 | |||
180 | $reflection = new \ReflectionObject($this->provider); |
||
181 | $method = $reflection->getMethod('getMoment'); |
||
182 | $method->setAccessible(true); |
||
183 | $prevMoment = $method->invokeArgs($this->provider, [$dateRange, $start]); |
||
184 | |||
185 | $this->forecastProvider->expects($this->exactly(6)) |
||
186 | ->method('getForecastData') |
||
187 | ->with( |
||
188 | [], |
||
189 | $this->logicalOr($start, $prevStart), |
||
190 | $this->logicalOr($end, $prevEnd), |
||
191 | $this->logicalOr(null, $prevMoment) |
||
192 | ) |
||
193 | ->will($this->returnCallback($forecastDataCallback)); |
||
194 | |||
195 | $this->filterDateRangeConverter->expects($this->any()) |
||
196 | ->method('getViewValue') |
||
197 | ->with(['start' => $prevStart, 'end' => $prevEnd, 'type' => AbstractDateFilterType::TYPE_BETWEEN]) |
||
198 | ->will($this->returnValue('prev range')); |
||
199 | |||
200 | $result = $this->provider |
||
201 | ->getForecastOfOpportunitiesValues($widgetOptions, 'inProgressCount', 'integer', false); |
||
202 | $this->assertEquals( |
||
203 | ['value' => 5, 'deviation' => '+3 (+1.5)', 'isPositive' => true, 'previousRange' => 'prev range'], |
||
204 | $result |
||
205 | ); |
||
206 | |||
207 | $result = $this->provider |
||
208 | ->getForecastOfOpportunitiesValues($widgetOptions, 'budgetAmount', 'currency', false); |
||
209 | $this->assertEquals( |
||
210 | ['value' => 1000, 'deviation' => '+800 (+4)', 'isPositive' => 1, 'previousRange' => 'prev range'], |
||
211 | $result |
||
212 | ); |
||
213 | |||
214 | $result = $this->provider |
||
215 | ->getForecastOfOpportunitiesValues($widgetOptions, 'weightedForecast', 'currency', false); |
||
216 | $this->assertEquals( |
||
217 | ['value' => 500, 'deviation' => '+450 (+9)', 'isPositive' => 1, 'previousRange' => 'prev range'], |
||
218 | $result |
||
219 | ); |
||
220 | } |
||
221 | } |
||
222 |
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.