Code Duplication    Length = 29-29 lines in 2 locations

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

@@ 184-212 (lines=29) @@
181
     *
182
     * @return JsonResponse
183
     */
184
    public function claimStepAction($id)
185
    {
186
        $user = $this->getUser();
187
        $step = $this->get('badger.game.repository.adventure_step')->find($id);
188
189
        if (null === $step) {
190
            return new JsonResponse('No step with this id.', 404);
191
        }
192
193
        if (!$this->get('security.authorization_checker')->isGranted('view', $step->getAdventure())) {
194
            return new JsonResponse('No step with this id.', 404);
195
        }
196
197
        $stepCompletion = $this->get('badger.game.repository.adventure_step_completion')->findOneBy([
198
            'user' => $user,
199
            'step' => $step
200
        ]);
201
202
        if (null !== $stepCompletion) {
203
            return new JsonResponse('This step is already claimed.', 400);
204
        }
205
206
        $stepCompletionFactory = $this->get('badger.game.adventure_step_completion.factory');
207
        $stepCompletion = $stepCompletionFactory->create($user, $step);
208
209
        $this->get('badger.game.saver.adventure_step_completion')->save($stepCompletion);
210
211
        return new JsonResponse();
212
    }
213
214
    /**
215
     * @Route("/claim/quest/{id}", name="claimquest")
@@ 220-248 (lines=29) @@
217
     *
218
     * @return JsonResponse
219
     */
220
    public function claimQuestAction($id)
221
    {
222
        $user = $this->getUser();
223
        $quest = $this->get('badger.game.repository.quest')->find($id);
224
225
        if (null === $quest) {
226
            return new JsonResponse('No quest with this id.', 400);
227
        }
228
229
        if (!$this->get('security.authorization_checker')->isGranted('view', $quest)) {
230
            return new JsonResponse('No quest with this id.', 400);
231
        }
232
233
        $questCompletion = $this->get('badger.game.repository.quest_completion')->findOneBy([
234
            'user' => $user,
235
            'quest' => $quest
236
        ]);
237
238
        if (null !== $questCompletion) {
239
            return new JsonResponse('This quest is already claimed.', 400);
240
        }
241
242
        $questCompletionFactory = $this->get('badger.game.quest_completion.factory');
243
        $questCompletion = $questCompletionFactory->create($user, $quest);
244
245
        $this->get('badger.game.saver.quest_completion')->save($questCompletion);
246
247
        return new JsonResponse();
248
    }
249
250
    /**
251
     * @Route("/badges", name="badges")