Code Duplication    Length = 32-37 lines in 2 locations

src/PlaygroundGame/Service/InstantWin.php 2 locations

@@ 225-256 (lines=32) @@
222
                }
223
224
                break;
225
            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
            case 'day':
258
                $nbInterval = (int) ($dateInterval/(60*24));
259
@@ 257-293 (lines=37) @@
254
                }
255
256
                break;
257
            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
            case 'week':
295
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
296
                $nbWeeksInterval = (int) ($dateInterval/(60*24*7));