Code Duplication    Length = 32-37 lines in 2 locations

src/Service/InstantWin.php 2 locations

@@ 316-347 (lines=32) @@
313
                }
314
315
                break;
316
            case 'hour':
317
                $nbInterval = (int) ($dateInterval/60);
318
319
                // If a hour don't last 60min, I consider it as a hour anyway.
320
                if ($dateInterval%60 > 0) {
321
                    ++$nbInterval;
322
                }
323
                if ($nbInterval > 0) {
324
                    $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval);
325
                }
326
327
                $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s'));
328
                $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H'). ':59:59');
329
                
330
                if ($nbOccurencesToCreate > 0) {
331
                    for ($d=1; $d<=$nbInterval; $d++) {
332
                        $this->createRandomOccurrences(
333
                            $game,
334
                            $beginningDrawDate,
335
                            $endDrawDate,
336
                            $nbOccurencesToCreate
337
                        );
338
                        $beginningDrawDate = \DateTime::createFromFormat(
339
                            'm/d/Y H:i:s',
340
                            $beginningDrawDate->format('m/d/Y H'). ':00:00'
341
                        );
342
                        $beginningDrawDate->add(new \DateInterval('PT1H'));
343
                        $endDrawDate->add(new \DateInterval('PT1H'));
344
                    }
345
                }
346
347
                break;
348
            case 'day':
349
                $nbInterval = (int) ($dateInterval/(60*24));
350
@@ 348-384 (lines=37) @@
345
                }
346
347
                break;
348
            case 'day':
349
                $nbInterval = (int) ($dateInterval/(60*24));
350
351
                // Prise en compte des changements d'horaires
352
                // If a day don't last 24h, I consider it as a day anyway
353
354
                if ($dateInterval%(60*24) > 0) {
355
                    ++$nbInterval;
356
                }
357
358
                if ($nbInterval > 0) {
359
                    $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval);
360
                }
361
362
                $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s'));
363
                $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y'). ' 23:59:59');
364
                
365
                if ($nbOccurencesToCreate > 0) {
366
                    for ($d=1; $d<=$nbInterval; $d++) {
367
                        $this->createRandomOccurrences(
368
                            $game,
369
                            $beginningDrawDate,
370
                            $endDrawDate,
371
                            $nbOccurencesToCreate
372
                        );
373
                        // As the first beginning date was not @ midnight,
374
                        // I recreate the beginning date
375
                        $beginningDrawDate = \DateTime::createFromFormat(
376
                            'm/d/Y H:i:s',
377
                            $beginningDrawDate->format('m/d/Y'). ' 00:00:00'
378
                        );
379
                        $beginningDrawDate->add(new \DateInterval('P1D'));
380
                        $endDrawDate->add(new \DateInterval('P1D'));
381
                    }
382
                }
383
384
                break;
385
            case 'week':
386
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
387
                $nbWeeksInterval = (int) ($dateInterval/(60*24*7));