Completed
Pull Request — master (#45)
by Laurent
04:03
created

DefaultController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 8
Bugs 2 Features 1
Metric Value
wmc 12
c 8
b 2
f 1
lcom 1
cbo 4
dl 0
loc 107
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A indexAction() 0 15 2
B testEntities() 0 29 6
A getFamilyLogAction() 0 21 3
1
<?php
2
/**
3
 * DefaultController controller 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;
16
17
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
19
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
20
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
21
use Symfony\Component\HttpFoundation\Response;
22
23
/**
24
 * Default controller.
25
 *
26
 * @category Controller
27
 *
28
 * @Route("/")
29
 */
30
class DefaultController extends Controller
31
{
32
    private $entities;
33
    
34
    public function __construct()
35
    {
36
        // Tableau des entitées
37
        $this->entities = array(
38
            'AppBundle:User',
39
            'AppBundle:Company',
40
            'AppBundle:Settings',
41
            'AppBundle:FamilyLog',
42
            'AppBundle:SubFamilyLog',
43
            'AppBundle:ZoneStorage',
44
            'AppBundle:UnitStorage',
45
            'AppBundle:Tva',
46
            'AppBundle:Supplier',
47
            'AppBundle:Article',
48
            'AppBundle:Settings');
49
50
    }
51
52
    /**
53
     * @Route("/", name="_home")
54
     * @Method("GET")
55
     * @Template()
56
     */
57
    public function indexAction()
58
    {
59
        $url = "";
60
        /**
61
         * Test d'installation
62
         */
63
//        $url = $this->testEntities();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
64
        if (empty($url)) {
65
            $url = $this->render('default/index.html.twig');
66
        } else {
67
            $url = $this->redirectToRoute($url);
68
        }
69
        // replace this example code with whatever you need
70
        return $url;
71
    }
72
73
    /**
74
     * Test des entités
75
     *
76
     * @return array
77
     */
78
    private function testEntities()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
79
    {
80
        $url = null;
81
        $etm = $this->getDoctrine()->getManager();
82
        // vérifie que les Entitées ne sont pas vides
83
        $nbEntities = count($this->entities);
84
        for ($index = 0; $index < $nbEntities; $index++) {
85
            $entity = $etm->getRepository(
86
                $this->entities[$index]
87
            );
88
            $entityData = $entity->find(1);
89
90
            if (empty($entityData)) {
91
                $message = 'gestock.install.none';
92
//                $url = 'gs_install'; break;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
93
                $url = '_home';
94
                break;
95
            } elseif ($index === 10 && $entityData->getFirstInventory() === null) {
96
                $message = 'gestock.settings.application.first_inventory.none';
97
//                $url = 'gestock_inventory_prepare'; break;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
98
                $url = '_home';
99
                break;
100
            }
101
        }
102
        if (isset($message)) {
103
            $this->addFlash('warning', $message);
104
        }
105
        return $url;
106
    }
107
108
    /**
109
     * Récupère les FamilyLog de la requête post.
110
     *
111
     * @Route("/getfamilylog", name="getfamilylog")
112
     * @Method("POST")
113
     * @return \Symfony\Component\HttpFoundation\Response
114
     */
115
    public function getFamilyLogAction()
116
    {
117
        $id = '';
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
        $request = $this->getRequest();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
119
        $etm = $this->getDoctrine()->getManager();
120
        if ($request->isXmlHttpRequest()) {
121
            $id = $request->get('id');
122
            if ($id != '') {
123
                $supplier = $etm
124
                    ->getRepository('AppBundle:Supplier')
125
                    ->find($id);
126
                $familyLog['familylog'] = $supplier->getFamilyLog()->getId();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$familyLog was never initialized. Although not strictly required by PHP, it is generally a good practice to add $familyLog = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
127
                $response = new Response();
128
                $data = json_encode($familyLog);
129
                $response->headers->set('Content-Type', 'application/json');
130
                $response->setContent($data);
131
                return $response;
132
            }
133
        }
134
        return new Response('Error');
135
    }
136
}
137