Completed
Push — master ( a74bd2...08e6ab )
by Laurent
04:38
created

AbstractInstallController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 51
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B stepAction() 0 39 5
1
<?php
2
/**
3
 * AbstractInstallController controller d'installation de l'application GLSR.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version   since 1.0.0
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Controller\Install;
16
17
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
18
use Symfony\Component\HttpFoundation\Request;
19
20
/**
21
 * AbstractInstall controller
22
 *
23
 * @category Controller
24
 */
25
abstract class AbstractInstallController extends Controller
26
{
27
    /**
28
     * Etape X de l'installation.
29
     * Fonction adaptable aux différentes phases de l'installation.
30
     *
31
     * @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire
32
     *
33
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|
34
     *     array<string,string|null|Settings|\Symfony\Component\Form\FormView> Rendue de la page
35
     */
36
    public function stepAction(Request $request, $entity, $entityPath, $typePath, $number)
37
    {
38
        $etm = $this->getDoctrine()->getManager();
39
        ${'ct'.$entity} = count($etm->getRepository('AppBundle:'.$entity)->findAll());
40
        ${strtolower($entity)} = $etm->getClassMetadata($entityPath)->newInstance();
41
        $message = null;
42
        
43
//        if (${'ct'.$entity} > 0 && $request->getMethod() == 'GET' && is_int($number)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
//            $message = 'gestock.install.st'.$number.'.yet_exist';
45
//        }
46
        $form = $this->createForm(new $typePath(), ${strtolower($entity)}, array(
47
            'action' => $this->generateUrl('gs_install_st'.$number)
48
        ));
49
        if (is_int($number)) {
50
            $return = array('message' => $message, 'form' => $form->createView(),);
51
        } else {
52
            $return = array(
53
                strtolower($entity) => ${strtolower($entity)},
54
                'form' => $form->createView(),
55
            );
56
        }       
57
58
        if ($form->handleRequest($request)->isValid()) {
59
            $etm = $this->getDoctrine()->getManager();
60
            $etm->persist(${strtolower($entity)});
61
            $etm->flush();
62
63
            if ($form->get('save')->isSubmitted()) {
64
                $return = $this->redirect($this->generateUrl('gs_install_st4'));
65
            } elseif ($form->get('addmore')->isSubmitted()) {
66
                $return = $this->redirect($this->generateUrl('gs_install_st'.$number));
67
            } else {
68
                $return = $this->redirect($this->generateUrl('gs_install_st'.$number));
69
            }
70
            $this->addFlash('info', 'gestock.install.st'.$number.'.flash');
71
        }
72
        
73
        return $return;
74
    }
75
}
76