Code Duplication    Length = 38-39 lines in 2 locations

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

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