Code Duplication    Length = 29-29 lines in 2 locations

src/Badger/Bundle/GameBundle/Controller/DefaultController.php 2 locations

@@ 227-255 (lines=29) @@
224
     *
225
     * @return JsonResponse
226
     */
227
    public function claimStepAction($id)
228
    {
229
        $user = $this->getUser();
230
        $step = $this->get('badger.game.repository.adventure_step')->find($id);
231
232
        if (null === $step) {
233
            return new JsonResponse('No step with this id.', 404);
234
        }
235
236
        if (!$this->get('security.authorization_checker')->isGranted('view', $step->getAdventure())) {
237
            return new JsonResponse('No step with this id.', 404);
238
        }
239
240
        $stepCompletion = $this->get('badger.game.repository.adventure_step_completion')->findOneBy([
241
            'user' => $user,
242
            'step' => $step
243
        ]);
244
245
        if (null !== $stepCompletion) {
246
            return new JsonResponse('This step is already claimed.', 400);
247
        }
248
249
        $stepCompletionFactory = $this->get('badger.game.adventure_step_completion.factory');
250
        $stepCompletion = $stepCompletionFactory->create($user, $step);
251
252
        $this->get('badger.game.saver.adventure_step_completion')->save($stepCompletion);
253
254
        return new JsonResponse();
255
    }
256
257
    /**
258
     * @Route("/claim/quest/{id}", name="claimquest")
@@ 263-291 (lines=29) @@
260
     *
261
     * @return JsonResponse
262
     */
263
    public function claimQuestAction($id)
264
    {
265
        $user = $this->getUser();
266
        $quest = $this->get('badger.game.repository.quest')->find($id);
267
268
        if (null === $quest) {
269
            return new JsonResponse('No quest with this id.', 400);
270
        }
271
272
        if (!$this->get('security.authorization_checker')->isGranted('view', $quest)) {
273
            return new JsonResponse('No quest with this id.', 400);
274
        }
275
276
        $questCompletion = $this->get('badger.game.repository.quest_completion')->findOneBy([
277
            'user' => $user,
278
            'quest' => $quest
279
        ]);
280
281
        if (null !== $questCompletion) {
282
            return new JsonResponse('This quest is already claimed.', 400);
283
        }
284
285
        $questCompletionFactory = $this->get('badger.game.quest_completion.factory');
286
        $questCompletion = $questCompletionFactory->create($user, $quest);
287
288
        $this->get('badger.game.saver.quest_completion')->save($questCompletion);
289
290
        return new JsonResponse();
291
    }
292
293
    /**
294
     * @Route("/badges", name="badges")