| Conditions | 32 |
| Paths | 888 |
| Total Lines | 199 |
| Code Lines | 128 |
| Lines | 141 |
| Ratio | 70.85 % |
| Changes | 4 | ||
| 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 |
||
| 171 | public function scheduleDateOccurrences($game) |
||
| 172 | { |
||
| 173 | $f = $game->getOccurrenceDrawFrequency(); |
||
| 174 | $today = new \DateTime("now"); |
||
| 175 | $end = new \DateTime("now"); |
||
| 176 | $interval = 'P10D'; |
||
| 177 | if ($game->getStartDate() && $game->getStartDate() > $today) { |
||
| 178 | $beginning = $game->getStartDate(); |
||
| 179 | } else { |
||
| 180 | $beginning = $today; |
||
| 181 | } |
||
| 182 | |||
| 183 | if ($game->getEndDate()) { |
||
| 184 | $end = $game->getEndDate(); |
||
| 185 | } else { |
||
| 186 | $end->add(new \DateInterval($interval)); |
||
| 187 | } |
||
| 188 | |||
| 189 | // Summertimes timezone management |
||
| 190 | $timezone = $today->getTimezone(); |
||
| 191 | $transitions = $timezone->getTransitions($beginning->getTimestamp(), $end->getTimestamp()); |
||
| 192 | |||
| 193 | // There is a time transition between these datetimes() |
||
| 194 | if (count($transitions) == 2) { |
||
| 195 | $shift = $transitions[0]['offset'] - $transitions[1]['offset']; |
||
| 196 | if ($shift > 0) { |
||
| 197 | $end->sub(new \DateInterval('PT'.abs($shift).'S')); |
||
| 198 | } else { |
||
| 199 | $end->add(new \DateInterval('PT'.abs($shift).'S')); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | // DateInterval takes the day @ 00:00 to calculate the difference between the dates, so 1 day is always missing |
||
| 204 | // as we consider the last day @ 23:59:59 in Playground :) |
||
| 205 | if ($end->format('His') == 0) { |
||
| 206 | $end->add(new \DateInterval('P1D')); |
||
| 207 | } |
||
| 208 | |||
| 209 | $dateInterval = (int)(($end->getTimestamp() - $beginning->getTimestamp())/60); |
||
| 210 | |||
| 211 | // Je recherche tous les IG non gagnés |
||
| 212 | $occurrences = $this->getInstantWinOccurrenceMapper()->findBy(array('instantwin' => $game)); |
||
| 213 | $nbExistingOccurrences = count($occurrences); |
||
| 214 | $nbOccurencesToCreate = 0; |
||
| 215 | |||
| 216 | switch ($f) { |
||
| 217 | case null: |
||
| 218 | case 'game': |
||
| 219 | $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences; |
||
| 220 | if ($nbOccurencesToCreate > 0) { |
||
| 221 | $this->createRandomOccurrences($game, $beginning, $end, $nbOccurencesToCreate); |
||
| 222 | } |
||
| 223 | |||
| 224 | break; |
||
| 225 | View Code Duplication | case 'hour': |
|
| 226 | $nbInterval = (int) ($dateInterval/60); |
||
| 227 | |||
| 228 | // If a hour don't last 60min, I consider it as a hour anyway. |
||
| 229 | if ($dateInterval%60 > 0) { |
||
| 230 | ++$nbInterval; |
||
| 231 | } |
||
| 232 | if ($nbInterval > 0) { |
||
| 233 | $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval); |
||
| 234 | } |
||
| 235 | |||
| 236 | $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s')); |
||
| 237 | $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H'). ':59:59'); |
||
| 238 | |||
| 239 | if ($nbOccurencesToCreate > 0) { |
||
| 240 | for ($d=1; $d<=$nbInterval; $d++) { |
||
| 241 | $this->createRandomOccurrences( |
||
| 242 | $game, |
||
| 243 | $beginningDrawDate, |
||
| 244 | $endDrawDate, |
||
| 245 | $nbOccurencesToCreate |
||
| 246 | ); |
||
| 247 | $beginningDrawDate = \DateTime::createFromFormat( |
||
| 248 | 'm/d/Y H:i:s', |
||
| 249 | $beginningDrawDate->format('m/d/Y H'). ':00:00' |
||
| 250 | ); |
||
| 251 | $beginningDrawDate->add(new \DateInterval('PT1H')); |
||
| 252 | $endDrawDate->add(new \DateInterval('PT1H')); |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | break; |
||
| 257 | View Code Duplication | case 'day': |
|
| 258 | $nbInterval = (int) ($dateInterval/(60*24)); |
||
| 259 | |||
| 260 | // Prise en compte des changements d'horaires |
||
| 261 | // If a day don't last 24h, I consider it as a day anyway |
||
| 262 | |||
| 263 | if ($dateInterval%(60*24) > 0) { |
||
| 264 | ++$nbInterval; |
||
| 265 | } |
||
| 266 | |||
| 267 | if ($nbInterval > 0) { |
||
| 268 | $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval); |
||
| 269 | } |
||
| 270 | |||
| 271 | $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s')); |
||
| 272 | $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y'). ' 23:59:59'); |
||
| 273 | |||
| 274 | if ($nbOccurencesToCreate > 0) { |
||
| 275 | for ($d=1; $d<=$nbInterval; $d++) { |
||
| 276 | $this->createRandomOccurrences( |
||
| 277 | $game, |
||
| 278 | $beginningDrawDate, |
||
| 279 | $endDrawDate, |
||
| 280 | $nbOccurencesToCreate |
||
| 281 | ); |
||
| 282 | // As the first beginning date was not @ midnight, |
||
| 283 | // I recreate the beginning date |
||
| 284 | $beginningDrawDate = \DateTime::createFromFormat( |
||
| 285 | 'm/d/Y H:i:s', |
||
| 286 | $beginningDrawDate->format('m/d/Y'). ' 00:00:00' |
||
| 287 | ); |
||
| 288 | $beginningDrawDate->add(new \DateInterval('P1D')); |
||
| 289 | $endDrawDate->add(new \DateInterval('P1D')); |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 293 | break; |
||
| 294 | View Code Duplication | case 'week': |
|
| 295 | $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences; |
||
| 296 | $nbWeeksInterval = (int) ($dateInterval/(60*24*7)); |
||
| 297 | // If a week don't last 7d, I consider it as a week anyway. |
||
| 298 | if ($dateInterval%(60*24*7) > 0) { |
||
| 299 | ++$nbWeeksInterval; |
||
| 300 | } |
||
| 301 | $beginningDrawDate = \DateTime::createFromFormat( |
||
| 302 | 'm/d/Y H:i:s', |
||
| 303 | $beginning->format('m/d/Y'). ' 00:00:00' |
||
| 304 | ); |
||
| 305 | $endDrawDate = \DateTime::createFromFormat( |
||
| 306 | 'm/d/Y H:i:s', |
||
| 307 | $beginning->format('m/d/Y'). ' 23:59:59' |
||
| 308 | ); |
||
| 309 | $endDrawDate->add(new \DateInterval('P6D')); |
||
| 310 | if ($endDrawDate > $end) { |
||
| 311 | $endDrawDate = $end; |
||
| 312 | } |
||
| 313 | |||
| 314 | if ($nbOccurencesToCreate > 0) { |
||
| 315 | for ($d=1; $d<=$nbWeeksInterval; $d++) { |
||
| 316 | $this->createRandomOccurrences( |
||
| 317 | $game, |
||
| 318 | $beginningDrawDate, |
||
| 319 | $endDrawDate, |
||
| 320 | $nbOccurencesToCreate |
||
| 321 | ); |
||
| 322 | $beginningDrawDate->add(new \DateInterval('P1W')); |
||
| 323 | $endDrawDate->add(new \DateInterval('P1W')); |
||
| 324 | if ($endDrawDate > $end) { |
||
| 325 | $endDrawDate = $end; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | break; |
||
| 331 | View Code Duplication | case 'month': |
|
| 332 | $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences; |
||
| 333 | $nbMonthsInterval = (int) ($dateInterval/(60*24*30)); |
||
| 334 | // If a week don't last 30d, I consider it as a month anyway. |
||
| 335 | if ($dateInterval%(60*24*30) > 0) { |
||
| 336 | ++$nbMonthsInterval; |
||
| 337 | } |
||
| 338 | $beginningDrawDate = \DateTime::createFromFormat( |
||
| 339 | 'm/d/Y H:i:s', |
||
| 340 | $beginning->format('m/d/Y'). ' 00:00:00' |
||
| 341 | ); |
||
| 342 | $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y'). ' 23:59:59'); |
||
| 343 | $endDrawDate->add(new \DateInterval('P1M')); |
||
| 344 | $endDrawDate->sub(new \DateInterval('P1D')); |
||
| 345 | if ($endDrawDate > $end) { |
||
| 346 | $endDrawDate = $end; |
||
| 347 | } |
||
| 348 | |||
| 349 | if ($nbOccurencesToCreate > 0) { |
||
| 350 | for ($d=1; $d<=$nbMonthsInterval; $d++) { |
||
| 351 | $this->createRandomOccurrences( |
||
| 352 | $game, |
||
| 353 | $beginningDrawDate, |
||
| 354 | $endDrawDate, |
||
| 355 | $nbOccurencesToCreate |
||
| 356 | ); |
||
| 357 | $beginningDrawDate->add(new \DateInterval('P1M')); |
||
| 358 | $endDrawDate->add(new \DateInterval('P1M')); |
||
| 359 | if ($endDrawDate > $end) { |
||
| 360 | $endDrawDate = $end; |
||
| 361 | } |
||
| 362 | } |
||
| 363 | } |
||
| 364 | |||
| 365 | break; |
||
| 366 | } |
||
| 367 | |||
| 368 | return true; |
||
| 369 | } |
||
| 370 | |||
| 664 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.