Code Duplication    Length = 38-39 lines in 2 locations

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

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