Code Duplication    Length = 35-37 lines in 2 locations

src/PlaygroundGame/Service/InstantWin.php 2 locations

@@ 253-289 (lines=37) @@
250
                }
251
252
                break;
253
            case 'week':
254
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
255
                $nbWeeksInterval = (int) ($dateInterval/(60*24*7));
256
                // If a week don't last 7d, I consider it as a week anyway.
257
                if ($dateInterval%(60*24*7) > 0) {
258
                    ++$nbWeeksInterval;
259
                }
260
                $beginningDrawDate = \DateTime::createFromFormat(
261
                    'm/d/Y H:i:s',
262
                    $beginning->format('m/d/Y'). ' 00:00:00'
263
                );
264
                $endDrawDate = \DateTime::createFromFormat(
265
                    'm/d/Y H:i:s',
266
                    $beginning->format('m/d/Y'). ' 23:59:59'
267
                );
268
                $endDrawDate->add(new \DateInterval('P6D'));
269
                if ($endDrawDate > $end) {
270
                    $endDrawDate = $end;
271
                }
272
273
                if ($nbOccurencesToCreate > 0) {
274
                    for ($d=1; $d<=$nbWeeksInterval; $d++) {
275
                        $this->createRandomOccurrences(
276
                            $game,
277
                            $beginningDrawDate,
278
                            $endDrawDate,
279
                            $nbOccurencesToCreate
280
                        );
281
                        $beginningDrawDate->add(new \DateInterval('P1W'));
282
                        $endDrawDate->add(new \DateInterval('P1W'));
283
                        if ($endDrawDate > $end) {
284
                            $endDrawDate = $end;
285
                        }
286
                    }
287
                }
288
289
                break;
290
            case 'month':
291
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
292
                $nbMonthsInterval = (int) ($dateInterval/(60*24*30));
@@ 290-324 (lines=35) @@
287
                }
288
289
                break;
290
            case 'month':
291
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
292
                $nbMonthsInterval = (int) ($dateInterval/(60*24*30));
293
                // If a week don't last 30d, I consider it as a month anyway.
294
                if ($dateInterval%(60*24*30) > 0) {
295
                    ++$nbMonthsInterval;
296
                }
297
                $beginningDrawDate = \DateTime::createFromFormat(
298
                    'm/d/Y H:i:s',
299
                    $beginning->format('m/d/Y'). ' 00:00:00'
300
                );
301
                $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y'). ' 23:59:59');
302
                $endDrawDate->add(new \DateInterval('P1M'));
303
                $endDrawDate->sub(new \DateInterval('P1D'));
304
                if ($endDrawDate > $end) {
305
                    $endDrawDate = $end;
306
                }
307
308
                if ($nbOccurencesToCreate > 0) {
309
                    for ($d=1; $d<=$nbMonthsInterval; $d++) {
310
                        $this->createRandomOccurrences(
311
                            $game,
312
                            $beginningDrawDate,
313
                            $endDrawDate,
314
                            $nbOccurencesToCreate
315
                        );
316
                        $beginningDrawDate->add(new \DateInterval('P1M'));
317
                        $endDrawDate->add(new \DateInterval('P1M'));
318
                        if ($endDrawDate > $end) {
319
                            $endDrawDate = $end;
320
                        }
321
                    }
322
                }
323
324
                break;
325
        }
326
327
        return true;