Code Duplication    Length = 38-39 lines in 2 locations

src/Surfnet/StepupRa/RaBundle/Controller/RaManagementController.php 2 locations

@@ 198-236 (lines=39) @@
195
     * @param         $identityId
196
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
197
     */
198
    public function amendRaInformationAction(Request $request, $identityId)
199
    {
200
        $this->denyAccessUnlessGranted(['ROLE_RAA', 'ROLE_SRAA']);
201
202
        $logger = $this->get('logger');
203
        $logger->notice(sprintf("Loading information amendment form for RA(A) '%s'", $identityId));
204
205
        $raListing = $this->getRaListingService()->get($identityId);
206
207
        if (!$raListing) {
208
            $logger->warning(sprintf("RA listing for identity ID '%s' not found", $identityId));
209
            throw new NotFoundHttpException(sprintf("RA listing for identity ID '%s' not found", $identityId));
210
        }
211
212
        $command = new AmendRegistrationAuthorityInformationCommand();
213
        $command->identityId = $raListing->identityId;
214
        $command->location = $raListing->location;
215
        $command->contactInformation = $raListing->contactInformation;
216
217
        $form = $this->createForm(AmendRegistrationAuthorityInformationType::class, $command)->handleRequest($request);
218
        if ($form->isSubmitted() && $form->isValid()) {
219
            $logger->notice(sprintf("RA(A) '%s' information amendment form submitted, processing", $identityId));
220
221
            if ($this->get('ra.service.ra')->amendRegistrationAuthorityInformation($command)) {
222
                $this->addFlash('success', $this->get('translator')->trans('ra.management.amend_ra_info.info_amended'));
223
224
                $logger->notice(sprintf("RA(A) '%s' information successfully amended", $identityId));
225
                return $this->redirectToRoute('ra_management_manage');
226
            }
227
228
            $logger->notice(sprintf("Information of RA(A) '%s' failed to be amended, informing user", $identityId));
229
            $form->addError(new FormError('ra.management.amend_ra_info.error.middleware_command_failed'));
230
        }
231
232
        return $this->render('SurfnetStepupRaRaBundle:RaManagement:amendRaInformation.html.twig', [
233
            'raListing' => $raListing,
234
            'form' => $form->createView(),
235
        ]);
236
    }
237
238
    /**
239
     * @param Request $request
@@ 243-280 (lines=38) @@
240
     * @param         $identityId
241
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
242
     */
243
    public function changeRaRoleAction(Request $request, $identityId)
244
    {
245
        $this->denyAccessUnlessGranted(['ROLE_RAA', 'ROLE_SRAA']);
246
        $logger = $this->get('logger');
247
248
        $logger->notice(sprintf("Loading change Ra Role form for RA(A) '%s'", $identityId));
249
250
        $raListing = $this->getRaListingService()->get($identityId);
251
        if (!$raListing) {
252
            $logger->warning(sprintf("RA listing for identity ID '%s' not found", $identityId));
253
            throw new NotFoundHttpException(sprintf("RA listing for identity ID '%s' not found", $identityId));
254
        }
255
256
        $command              = new ChangeRaRoleCommand();
257
        $command->identityId  = $raListing->identityId;
258
        $command->institution = $raListing->institution;
259
        $command->role        = $raListing->role;
260
261
        $form = $this->createForm(ChangeRaRoleType::class, $command)->handleRequest($request);
262
        if ($form->isSubmitted() && $form->isValid()) {
263
            $logger->notice(sprintf('RA(A) "%s" Change Role form submitted, processing', $identityId));
264
265
            if ($this->get('ra.service.ra')->changeRegistrationAuthorityRole($command)) {
266
                $logger->notice('Role successfully changed');
267
268
                $this->addFlash('success', $this->get('translator')->trans('ra.management.change_ra_role_changed'));
269
                return $this->redirectToRoute('ra_management_manage');
270
            }
271
272
            $logger->notice(sprintf('Role of RA(A) "%s" could not be changed, informing user', $identityId));
273
            $form->addError(new FormError('ra.management.change_ra_role.middleware_command_failed'));
274
        }
275
276
        return $this->render('SurfnetStepupRaRaBundle:RaManagement:changeRaRole.html.twig', [
277
            'raListing' => $raListing,
278
            'form'      => $form->createView()
279
        ]);
280
    }
281
282
    /**
283
     * @param Request $request