vivait /
AuthBundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Vivait\AuthBundle\Controller; |
||
| 4 | |||
| 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
| 6 | use Symfony\Component\HttpFoundation\Request; |
||
| 7 | use Vivait\AuthBundle\Entity\Tenant; |
||
| 8 | |||
| 9 | class TenantController extends Controller { |
||
| 10 | View Code Duplication | public function indexAction() { |
|
| 11 | ################################################ SETTINGS ################################################ |
||
| 12 | $repo = 'VivaitAuthBundle:Tenant'; |
||
| 13 | $twig = 'VivaitAuthBundle:Default:tenants.html.twig'; |
||
| 14 | ############################################################################################################ |
||
| 15 | $db = $this->getDoctrine() |
||
| 16 | ->getRepository($repo) |
||
| 17 | ->findAll(); |
||
| 18 | |||
| 19 | $params[''] = ''; |
||
|
0 ignored issues
–
show
|
|||
| 20 | return $this->render($twig, array('db' => $db, 'params' => $params)); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function editAction(Request $request) { |
||
| 24 | ################################################ SETTINGS ################################################ |
||
| 25 | $name = 'tenant'; |
||
| 26 | $repo = 'VivaitAuthBundle:Tenant'; |
||
| 27 | $formtpl['title'] = 'Add/Edit ' . ucfirst($name); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$formtpl was never initialized. Although not strictly required by PHP, it is generally a good practice to add $formtpl = 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 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...
|
|||
| 28 | $obj = new Tenant(); |
||
| 29 | $key = $request->query->get('id', 0); |
||
| 30 | $foreign_objs = array( # array( |
||
| 31 | # 'repo' => 'VivaBravoBundle:Product', |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% 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...
|
|||
| 32 | # 'key' => $request->query->get('pid', 0), |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% 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...
|
|||
| 33 | # 'method' => 'setProduct', |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% 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...
|
|||
| 34 | # 'name' => 'product'), |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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...
|
|||
| 35 | ); |
||
| 36 | ############################################################################################################ |
||
| 37 | |||
| 38 | View Code Duplication | if(!$key) { |
|
| 39 | ### CREATING A NEW OBJECT ### |
||
| 40 | |||
| 41 | #if there are foreign objects that should be bound to this object, bind them all here |
||
| 42 | foreach($foreign_objs as $fo) { |
||
| 43 | $foreign_obj = $this->getDoctrine() |
||
| 44 | ->getRepository($fo['repo']) |
||
| 45 | ->find($fo['key']); |
||
| 46 | if(!$foreign_obj) { |
||
| 47 | $this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $fo['name'])); |
||
| 48 | return $this->redirect($request->query->get('parent', $request->request->get('parent', $request->headers->get('referer')))); |
||
| 49 | } |
||
| 50 | call_user_func(array($obj, $fo['method'], $foreign_obj)); |
||
| 51 | } |
||
| 52 | } else { |
||
| 53 | ### EDITING AN EXISTING OBJECT ### |
||
| 54 | $obj = $this->getDoctrine() |
||
| 55 | ->getRepository($repo) |
||
| 56 | ->find($key); |
||
| 57 | |||
| 58 | if(!$obj) { |
||
| 59 | $this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $name)); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | ############################################## CREATE FORM ############################################### |
||
| 64 | $form = $this->createFormBuilder($obj) |
||
| 65 | ->add('code', 'text', array('label' => 'Account')) |
||
| 66 | ->add('tenant', 'text', array('label' => 'Tenant')) |
||
| 67 | ->add('active', 'checkbox') |
||
| 68 | ->add('licenseduntil', 'datetime', array( |
||
| 69 | 'label' => 'Licensed Until', |
||
| 70 | 'format' => 'yyyy-MM-dd HH:mm', |
||
| 71 | 'widget' => 'single_text', |
||
| 72 | 'datetimepicker' => true, |
||
| 73 | )) |
||
| 74 | ->add('users', 'entity', array( |
||
| 75 | 'class' => 'VivaitAuthBundle:User', |
||
| 76 | 'property' => 'fullname', |
||
| 77 | 'multiple' => true, |
||
| 78 | 'attr' => array('size' => 15), |
||
| 79 | 'required' => true, |
||
| 80 | 'label' => 'Users', |
||
| 81 | 'by_reference'=>false |
||
| 82 | )) |
||
| 83 | ->getForm(); |
||
| 84 | ############################################################################################################ |
||
| 85 | |||
| 86 | View Code Duplication | if($request->isMethod('POST')) { |
|
| 87 | $form->bind($request); |
||
| 88 | if($form->isValid()) { |
||
| 89 | $em = $this->getDoctrine()->getManager(); |
||
| 90 | $em->persist($obj); |
||
| 91 | $em->flush(); |
||
| 92 | $this->get('session')->getFlashBag()->add('success', sprintf('The %s has been %s successfully', $name, $key ? 'modified' : 'created')); |
||
| 93 | return $this->render('VivaitBootstrapBundle:Default:redirect.html.twig', array('redirect' => $request->query->get('parent', $request->request->get('parent', $request->headers->get('referer'))))); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | if(isset($form)) { |
||
| 97 | $formtpl['form'] = $form->createView(); |
||
| 98 | } |
||
| 99 | $formtpl['action'] = $this->generateUrl($this->container->get('request')->get('_route'), $request->query->all()); |
||
| 100 | |||
| 101 | return $this->render('VivaitBootstrapBundle:Default:form.html.twig', array( |
||
| 102 | 'form' => array_merge($formtpl, array('parent' => $request->query->get('parent', $request->request->get('parent', $request->headers->get('referer'))))))); |
||
| 103 | } |
||
| 104 | |||
| 105 | View Code Duplication | public function deleteAction(Request $request) { |
|
| 106 | ################################################ SETTINGS ################################################ |
||
| 107 | $name = 'tenant'; |
||
| 108 | $repo = 'VivaitAuthBundle:Tenant'; |
||
| 109 | $id = $request->query->get('id', 0); |
||
| 110 | $msg_notfound = "The $name could not be found"; |
||
| 111 | $msg_success = "The $name has been removed"; |
||
| 112 | ############################################################################################################ |
||
| 113 | |||
| 114 | $obj = $this->getDoctrine() |
||
| 115 | ->getRepository($repo) |
||
| 116 | ->find($id); |
||
| 117 | |||
| 118 | if(!$obj) { |
||
| 119 | $this->get('session')->getFlashBag()->add('error', $msg_notfound); |
||
| 120 | } else { |
||
| 121 | $em = $this->getDoctrine()->getManager(); |
||
| 122 | $em->remove($obj); |
||
| 123 | $em->flush(); |
||
| 124 | $this->get('session')->getFlashBag()->add('success', $msg_success); |
||
| 125 | } |
||
| 126 | |||
| 127 | return $this->redirect($request->headers->get('referer')); |
||
| 128 | } |
||
| 129 | } |
||
| 130 |
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:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.