geekhub-php /
serve-seattle
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 AppBundle\Controller; |
||
| 4 | |||
| 5 | use AppBundle\Entity\Survey\SurveyAnswer; |
||
| 6 | use AppBundle\Entity\Survey\SurveyType; |
||
| 7 | use AppBundle\Entity\Survey\Survey; |
||
| 8 | use AppBundle\Entity\DTO\Filter; |
||
| 9 | use AppBundle\Form\DTO\SurveyFilterType; |
||
| 10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
||
| 11 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
||
| 12 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
| 13 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
| 14 | use Symfony\Component\HttpFoundation\Request; |
||
| 15 | |||
| 16 | class SurveyController extends Controller |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @Route("/surveys", name="surveys") |
||
| 20 | * @Template("@App/surveys.html.twig") |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | 2 | public function surveysAction(Request $request) |
|
| 25 | { |
||
| 26 | 2 | $em = $this->getDoctrine()->getManager(); |
|
| 27 | |||
| 28 | 2 | $filter = new Filter(); |
|
| 29 | 2 | $filterForm = $this->createForm(SurveyFilterType::class, $filter); |
|
| 30 | 2 | $filterForm->handleRequest($request); |
|
| 31 | |||
| 32 | 2 | $surveys = $em->getRepository(Survey::class)->selectSurveysByParams($filter); |
|
| 33 | 2 | $types = $em->getRepository(SurveyType::class)->selectSurveyTypesByParams($filter); |
|
| 34 | 2 | $surveyTypes = $em->getRepository(SurveyType::class)->findAll(); |
|
| 35 | |||
| 36 | return [ |
||
| 37 | 2 | 'surveys' => $this->get('knp_paginator') |
|
| 38 | 2 | ->paginate( |
|
| 39 | 2 | $surveys, |
|
| 40 | 2 | $request->query->getInt('page', 1), |
|
| 41 | 2 | 20 |
|
| 42 | ), |
||
| 43 | 2 | 'types' => $types, |
|
| 44 | 2 | 'filterForm' => $filterForm->createView(), |
|
| 45 | 2 | 'surveyTypes' => $surveyTypes |
|
| 46 | ]; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param Survey $survey |
||
| 51 | * @Route("/surveys/{id}", name="survey") |
||
| 52 | * @Template("@App/survey.html.twig") |
||
| 53 | * @ParamConverter("survey", class="AppBundle\Entity\Survey\Survey") |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | 1 | public function surveyAction(Survey $survey) |
|
| 58 | { |
||
| 59 | 1 | $em = $this->getDoctrine()->getManager(); |
|
| 60 | 1 | if ($survey->isReviewed() == false) { |
|
|
0 ignored issues
–
show
|
|||
| 61 | 1 | $survey->setReviewed(true); |
|
| 62 | 1 | $em->persist($survey); |
|
| 63 | 1 | $em->flush(); |
|
| 64 | } |
||
| 65 | 1 | $answers = $em->getRepository(SurveyAnswer::class)->findAnswersBySurvey($survey); |
|
| 66 | 1 | View Code Duplication | if ($answers) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 67 | 1 | foreach ($answers as $answer) { |
|
| 68 | 1 | $questions[] = $answer->getQuestion()->getId(); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$questions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $questions = 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...
|
|||
| 69 | 1 | $contents[] = $answer->getContent(); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$contents was never initialized. Although not strictly required by PHP, it is generally a good practice to add $contents = 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...
|
|||
| 70 | } |
||
| 71 | 1 | $questionAnswer = array_combine($questions, $contents); |
|
|
0 ignored issues
–
show
The variable
$questions does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
The variable
$contents does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 72 | } |
||
| 73 | 1 | if (!$answers) { |
|
| 74 | $questionAnswer = null; |
||
| 75 | } |
||
| 76 | |||
| 77 | return [ |
||
| 78 | 1 | 'survey' => $survey, 'question_answers' => $questionAnswer, |
|
|
0 ignored issues
–
show
The variable
$questionAnswer does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 79 | ]; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param Request $request, SurveyType $surveyType |
||
|
0 ignored issues
–
show
There is no parameter named
$request,. Did you maybe mean $request?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. Loading history...
|
|||
| 84 | * @Route("/surveys/create/{survey_type}", name="survey_create") |
||
| 85 | * @ParamConverter("surveyType", options={"mapping": {"survey_type": "name"}}) |
||
| 86 | */ |
||
| 87 | 1 | public function surveyCreateAction(Request $request, SurveyType $surveyType) |
|
| 88 | { |
||
| 89 | 1 | $survey = new Survey(); |
|
| 90 | 1 | $survey->setType($surveyType); |
|
| 91 | 1 | $form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
|
| 92 | 1 | $form->handleRequest($request); |
|
| 93 | |||
| 94 | 1 | View Code Duplication | if ($form->isSubmitted() && $form->isValid()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 95 | 1 | $em = $this->getDoctrine()->getManager(); |
|
| 96 | 1 | $em->persist($survey); |
|
| 97 | 1 | $em->flush(); |
|
| 98 | |||
| 99 | 1 | return $this->redirectToRoute('surveys'); |
|
| 100 | } |
||
| 101 | |||
| 102 | 1 | return $this->render('@App/survey.html.twig', array( |
|
| 103 | 1 | 'form' => $form->createView(), 'survey' => $survey, 'question_answers' => null |
|
| 104 | )); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param Request $request, Survey $survey |
||
|
0 ignored issues
–
show
There is no parameter named
$request,. Did you maybe mean $request?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. Loading history...
|
|||
| 109 | * @Route("/surveys/delete/{id}", requirements={"id": "\d+"}, name="survey_delete") |
||
| 110 | * @ParamConverter("survey", class="AppBundle\Entity\Survey\Survey") |
||
| 111 | */ |
||
| 112 | 1 | public function surveyDeleteAction(Request $request, Survey $survey) |
|
| 113 | { |
||
| 114 | 1 | $em = $this->getDoctrine()->getManager(); |
|
| 115 | 1 | $answers = $em->getRepository(SurveyAnswer::class)->findAnswersBySurvey($survey); |
|
| 116 | 1 | View Code Duplication | if ($answers) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 117 | 1 | foreach ($answers as $answer) { |
|
| 118 | 1 | $questions[] = $answer->getQuestion()->getId(); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$questions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $questions = 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...
|
|||
| 119 | 1 | $contents[] = $answer->getContent(); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$contents was never initialized. Although not strictly required by PHP, it is generally a good practice to add $contents = 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...
|
|||
| 120 | } |
||
| 121 | 1 | $questionAnswer = array_combine($questions, $contents); |
|
|
0 ignored issues
–
show
The variable
$questions does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
The variable
$contents does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 122 | } |
||
| 123 | 1 | if (!$answers) { |
|
| 124 | $questionAnswer = null; |
||
| 125 | } |
||
| 126 | 1 | $form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
|
| 127 | 1 | $form->handleRequest($request); |
|
| 128 | |||
| 129 | 1 | View Code Duplication | if ($form->isSubmitted() && $form->isValid()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 130 | 1 | $em = $this->getDoctrine()->getManager(); |
|
| 131 | 1 | $em->remove($survey); |
|
| 132 | 1 | $em->flush(); |
|
| 133 | |||
| 134 | 1 | return $this->redirectToRoute('surveys'); |
|
| 135 | } |
||
| 136 | |||
| 137 | 1 | return $this->render('@App/survey.html.twig', array( |
|
| 138 | 1 | 'form' => $form->createView(), 'survey' => $survey, 'question_answers' => $questionAnswer, |
|
|
0 ignored issues
–
show
The variable
$questionAnswer does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 139 | )); |
||
| 140 | } |
||
| 141 | } |
||
| 142 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.