Code Duplication    Length = 32-37 lines in 2 locations

src/PlaygroundGame/Service/InstantWin.php 2 locations

@@ 184-215 (lines=32) @@
181
                }
182
183
                break;
184
            case 'hour':
185
                $nbInterval = (int) ($dateInterval/60);
186
187
                // If a hour don't last 60min, I consider it as a hour anyway.
188
                if ($dateInterval%60 > 0) {
189
                    ++$nbInterval;
190
                }
191
                if ($nbInterval > 0) {
192
                    $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval);
193
                }
194
195
                $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s'));
196
                $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H'). ':59:59');
197
                
198
                if ($nbOccurencesToCreate > 0) {
199
                    for ($d=1; $d<=$nbInterval; $d++) {
200
                        $this->createRandomOccurrences(
201
                            $game,
202
                            $beginningDrawDate,
203
                            $endDrawDate,
204
                            $nbOccurencesToCreate
205
                        );
206
                        $beginningDrawDate = \DateTime::createFromFormat(
207
                            'm/d/Y H:i:s',
208
                            $beginningDrawDate->format('m/d/Y H'). ':00:00'
209
                        );
210
                        $beginningDrawDate->add(new \DateInterval('PT1H'));
211
                        $endDrawDate->add(new \DateInterval('PT1H'));
212
                    }
213
                }
214
215
                break;
216
            case 'day':
217
                $nbInterval = (int) ($dateInterval/(60*24));
218
@@ 216-252 (lines=37) @@
213
                }
214
215
                break;
216
            case 'day':
217
                $nbInterval = (int) ($dateInterval/(60*24));
218
219
                // Prise en compte des changements d'horaires
220
                // If a day don't last 24h, I consider it as a day anyway
221
222
                if ($dateInterval%(60*24) > 0) {
223
                    ++$nbInterval;
224
                }
225
226
                if ($nbInterval > 0) {
227
                    $nbOccurencesToCreate = $game->getOccurrenceNumber() - floor($nbExistingOccurrences/$nbInterval);
228
                }
229
230
                $beginningDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y H:i:s'));
231
                $endDrawDate = \DateTime::createFromFormat('m/d/Y H:i:s', $beginning->format('m/d/Y'). ' 23:59:59');
232
                
233
                if ($nbOccurencesToCreate > 0) {
234
                    for ($d=1; $d<=$nbInterval; $d++) {
235
                        $this->createRandomOccurrences(
236
                            $game,
237
                            $beginningDrawDate,
238
                            $endDrawDate,
239
                            $nbOccurencesToCreate
240
                        );
241
                        // As the first beginning date was not @ midnight,
242
                        // I recreate the beginning date
243
                        $beginningDrawDate = \DateTime::createFromFormat(
244
                            'm/d/Y H:i:s',
245
                            $beginningDrawDate->format('m/d/Y'). ' 00:00:00'
246
                        );
247
                        $beginningDrawDate->add(new \DateInterval('P1D'));
248
                        $endDrawDate->add(new \DateInterval('P1D'));
249
                    }
250
                }
251
252
                break;
253
            case 'week':
254
                $nbOccurencesToCreate = $game->getOccurrenceNumber() - $nbExistingOccurrences;
255
                $nbWeeksInterval = (int) ($dateInterval/(60*24*7));