Code Duplication    Length = 29-29 lines in 2 locations

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

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