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 Victoire\Bundle\WidgetBundle\Resolver; |
||
4 | |||
5 | use Doctrine\ORM\EntityManager; |
||
6 | use Symfony\Component\PropertyAccess\PropertyAccess; |
||
7 | use Symfony\Component\PropertyAccess\PropertyAccessor; |
||
8 | use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity; |
||
9 | use Victoire\Bundle\APIBusinessEntityBundle\Resolver\APIBusinessEntityResolver; |
||
10 | use Victoire\Bundle\QueryBundle\Helper\QueryHelper; |
||
11 | use Victoire\Bundle\WidgetBundle\Model\Widget; |
||
12 | |||
13 | class BaseWidgetContentResolver |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
14 | { |
||
15 | /** |
||
16 | * @var QueryHelper |
||
17 | */ |
||
18 | protected $queryHelper; |
||
19 | |||
20 | /** |
||
21 | * @var EntityManager |
||
22 | */ |
||
23 | protected $entityManager; |
||
24 | |||
25 | /** |
||
26 | * @var APIBusinessEntityResolver |
||
27 | */ |
||
28 | protected $apiResolver; |
||
29 | |||
30 | /** |
||
31 | * Get the static content of the widget. |
||
32 | * |
||
33 | * @param Widget $widget |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getWidgetStaticContent(Widget $widget) |
||
38 | { |
||
39 | $reflect = new \ReflectionClass($widget); |
||
40 | $widgetProperties = $reflect->getProperties(); |
||
41 | $parameters = ['widget' => $widget]; |
||
42 | $accessor = PropertyAccess::createPropertyAccessor(); |
||
43 | |||
44 | foreach ($widgetProperties as $property) { |
||
45 | if (!$property->isStatic()) { |
||
46 | $value = $accessor->getValue($widget, $property->getName()); |
||
47 | $parameters[$property->getName()] = $value; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | return $parameters; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get the business entity content. |
||
56 | * |
||
57 | * @param Widget $widget |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | View Code Duplication | public function getWidgetBusinessEntityContent(Widget $widget) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
62 | { |
||
63 | $entity = $widget->getEntity(); |
||
64 | $parameters = $this->getWidgetStaticContent($widget); |
||
65 | |||
66 | $this->populateParametersWithWidgetFields($widget, $entity, $parameters); |
||
67 | |||
68 | return $parameters; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get the content of the widget by the entity linked to it. |
||
73 | * |
||
74 | * @param Widget $widget |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | View Code Duplication | public function getWidgetEntityContent(Widget $widget) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
79 | { |
||
80 | $entity = $widget->getEntity(); |
||
81 | |||
82 | $parameters = $this->getWidgetStaticContent($widget); |
||
83 | |||
84 | $this->populateParametersWithWidgetFields($widget, $entity, $parameters); |
||
85 | |||
86 | return $parameters; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the content of the widget for the query mode. |
||
91 | * |
||
92 | * @param Widget $widget |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getWidgetQueryContent(Widget $widget) |
||
97 | { |
||
98 | $parameters = $this->getWidgetStaticContent($widget); |
||
99 | |||
100 | if (APIBusinessEntity::TYPE === $widget->getBusinessEntity()->getType()) { |
||
101 | $entity = $this->apiResolver->getBusinessEntities($widget->getBusinessEntity()); |
||
102 | } else { |
||
103 | $entity = $this->getWidgetQueryBuilder($widget) |
||
104 | ->setMaxResults(1) |
||
105 | ->getQuery() |
||
106 | ->getOneOrNullResult(); |
||
107 | } |
||
108 | |||
109 | $this->populateParametersWithWidgetFields($widget, $entity, $parameters); |
||
110 | |||
111 | return $parameters; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get the widget query result. |
||
116 | * |
||
117 | * @param Widget $widget The widget |
||
118 | * |
||
119 | * @return \Doctrine\ORM\QueryBuilder The list of entities |
||
120 | */ |
||
121 | public function getWidgetQueryBuilder(Widget $widget) |
||
122 | { |
||
123 | //get the base query |
||
124 | $itemsQueryBuilder = $this->queryHelper->getQueryBuilder($widget, $this->entityManager); |
||
0 ignored issues
–
show
$widget is of type object<Victoire\Bundle\WidgetBundle\Model\Widget> , but the function expects a object<Victoire\Bundle\Q...VictoireQueryInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
125 | |||
126 | // Filter only visibleOnFront |
||
127 | $itemsQueryBuilder->andWhere('main_item.visibleOnFront = true'); |
||
128 | |||
129 | //add the query of the widget |
||
130 | return $this->queryHelper->buildWithSubQuery($widget, $itemsQueryBuilder, $this->entityManager); |
||
0 ignored issues
–
show
$widget is of type object<Victoire\Bundle\WidgetBundle\Model\Widget> , but the function expects a object<Victoire\Bundle\Q...VictoireQueryInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
131 | } |
||
132 | |||
133 | protected function populateParametersWithWidgetFields(Widget $widget, $entity, &$parameters) |
||
134 | { |
||
135 | $fields = $widget->getFields(); |
||
136 | //parse the field |
||
137 | foreach ($fields as $widgetField => $field) { |
||
138 | //get the value of the field |
||
139 | if (null !== $entity) { |
||
140 | $attributeValue = null; |
||
141 | if (null !== $field) { |
||
142 | $accessor = new PropertyAccessor(); |
||
143 | $attributeValue = $accessor->getValue($entity, $field); |
||
144 | } |
||
145 | } else { |
||
146 | $attributeValue = $widget->getBusinessEntityName().' -> '.$field; |
||
147 | } |
||
148 | |||
149 | $parameters[$widgetField] = $attributeValue; |
||
150 | } |
||
151 | |||
152 | $widget->setEntity($entity); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param QueryHelper $queryHelper |
||
157 | */ |
||
158 | public function setQueryHelper(QueryHelper $queryHelper) |
||
0 ignored issues
–
show
|
|||
159 | { |
||
160 | $this->queryHelper = $queryHelper; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @param EntityManager $entityManager |
||
165 | */ |
||
166 | public function setEntityManager(EntityManager $entityManager) |
||
0 ignored issues
–
show
You have injected the EntityManager via parameter
$entityManager . This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.
The function someFunction(ManagerRegistry $registry) {
$em = $registry->getManager();
$em->getConnection()->beginTransaction();
try {
// Do something.
$em->getConnection()->commit();
} catch (\Exception $ex) {
$em->getConnection()->rollback();
$em->close();
throw $ex;
}
}
If that code throws an exception and the On the other hand, if you instead inject the ![]() |
|||
167 | { |
||
168 | $this->entityManager = $entityManager; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @param APIBusinessEntityResolver $resolver |
||
173 | */ |
||
174 | public function setApiBusinessEntityResolver(APIBusinessEntityResolver $resolver) |
||
175 | { |
||
176 | $this->apiResolver = $resolver; |
||
177 | } |
||
178 | } |
||
179 |