Code Duplication    Length = 29-29 lines in 2 locations

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

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