Code Duplication    Length = 29-29 lines in 2 locations

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

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