| 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(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 = ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $request = $this->getRequest(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  | 
            
                        
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.