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 | class CalendarYearView extends CalendarMonthView |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | |||
6 | // Attributes |
||
7 | |||
8 | private $monthStart = 1; |
||
9 | private $monthsRemoved = array(); |
||
10 | |||
11 | protected $monthInnerClass; |
||
12 | protected $monthTitle; |
||
13 | |||
14 | private $monthLinkView; |
||
15 | private $monthLinkCalendar; |
||
16 | private $monthLinkController; |
||
17 | |||
18 | // Abstract Functions Implemented |
||
19 | |||
20 | public function init() |
||
21 | { |
||
22 | parent::init(); |
||
23 | $this->containerClass = 'yearView'; |
||
24 | $this->monthInnerClass = $this->innerClass; |
||
25 | $this->viewTitle = 'return date(\'Y\', $date);'; |
||
26 | $this->innerClass = 'year'; |
||
27 | $this->monthTitle = 'return date(\'F Y\', $monthDate);'; |
||
28 | } |
||
29 | |||
30 | public function needsMonth() |
||
31 | { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | public function Calendars(Calendar $calendar) |
||
36 | { |
||
37 | $years = $this->Years($calendar); |
||
38 | |||
39 | foreach ($years as $year) { |
||
40 | $calendars[] = $this->YearCalendar($year, $calendar); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$calendars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $calendars = 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. ![]() |
|||
41 | } |
||
42 | |||
43 | return new ArrayList($calendars); |
||
0 ignored issues
–
show
The variable
$calendars 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
![]() |
|||
44 | } |
||
45 | |||
46 | public function prevLinkParams(Calendar $calendar) |
||
47 | { |
||
48 | $date = mktime(0, 0, 0, 1, 1, $calendar->getYear() - $this->number); |
||
49 | return $this->getLinkParams($date); |
||
50 | } |
||
51 | |||
52 | public function nextLinkParams(Calendar $calendar) |
||
53 | { |
||
54 | $date = mktime(0, 0, 0, 1, 1, $calendar->getYear() + $this->number); |
||
55 | return $this->getLinkParams($date); |
||
56 | } |
||
57 | |||
58 | public function viewLinkParamsAndTitle(Calendar $calendar) |
||
59 | { |
||
60 | $year = $calendar->getYear(); |
||
61 | $date = mktime(0, 0, 0, 1, 1, $year); |
||
62 | $params = $this->getLinkParams($date); |
||
63 | $title = $this->getCustomisedTitle($year); |
||
64 | return array($params, $title); |
||
65 | } |
||
66 | |||
67 | public function getLinkParams($date) |
||
68 | { |
||
69 | return array( |
||
70 | 'year' => date('Y', $date) |
||
71 | ); |
||
72 | } |
||
73 | |||
74 | public function title() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
75 | { |
||
76 | return $this->number == 1 ? 'year' : "$this->number years"; |
||
77 | } |
||
78 | |||
79 | public function DateTitle(Calendar $calendar) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
80 | { |
||
81 | return $this->getCustomisedTitle($calendar->getYear()); |
||
82 | } |
||
83 | |||
84 | public function Years(Calendar $calendar) |
||
85 | { |
||
86 | $year = $calendar->getYear(); |
||
87 | |||
88 | for ($i = 0; $i < $this->number; $i++) { |
||
89 | $years[] = $year + $i; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$years was never initialized. Although not strictly required by PHP, it is generally a good practice to add $years = 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. ![]() |
|||
90 | } |
||
91 | |||
92 | return $years; |
||
0 ignored issues
–
show
The variable
$years 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
![]() |
|||
93 | } |
||
94 | |||
95 | // Functions |
||
96 | |||
97 | public function startByJanuary() |
||
98 | { |
||
99 | $this->monthStart = 1; |
||
100 | } |
||
101 | public function startByFebruary() |
||
102 | { |
||
103 | $this->monthStart = 2; |
||
104 | } |
||
105 | public function startByMarch() |
||
106 | { |
||
107 | $this->monthStart = 3; |
||
108 | } |
||
109 | public function startByApril() |
||
110 | { |
||
111 | $this->monthStart = 4; |
||
112 | } |
||
113 | public function startByMay() |
||
114 | { |
||
115 | $this->monthStart = 5; |
||
116 | } |
||
117 | public function startByJune() |
||
118 | { |
||
119 | $this->monthStart = 6; |
||
120 | } |
||
121 | public function startByJuly() |
||
122 | { |
||
123 | $this->monthStart = 7; |
||
124 | } |
||
125 | public function startByAugust() |
||
126 | { |
||
127 | $this->monthStart = 8; |
||
128 | } |
||
129 | public function startBySeptember() |
||
130 | { |
||
131 | $this->monthStart = 9; |
||
132 | } |
||
133 | public function startByOctober() |
||
134 | { |
||
135 | $this->monthStart = 10; |
||
136 | } |
||
137 | public function startByNovember() |
||
138 | { |
||
139 | $this->monthStart = 11; |
||
140 | } |
||
141 | public function startByDecember() |
||
142 | { |
||
143 | $this->monthStart = 12; |
||
144 | } |
||
145 | |||
146 | public function removeJanuary() |
||
147 | { |
||
148 | $this->removeMonth(1); |
||
149 | } |
||
150 | public function removeFebruary() |
||
151 | { |
||
152 | $this->removeMonth(2); |
||
153 | } |
||
154 | public function removeMarch() |
||
155 | { |
||
156 | $this->removeMonth(3); |
||
157 | } |
||
158 | public function removeApril() |
||
159 | { |
||
160 | $this->removeMonth(4); |
||
161 | } |
||
162 | public function removeMay() |
||
163 | { |
||
164 | $this->removeMonth(5); |
||
165 | } |
||
166 | public function removeJune() |
||
167 | { |
||
168 | $this->removeMonth(6); |
||
169 | } |
||
170 | public function removeJuly() |
||
171 | { |
||
172 | $this->removeMonth(7); |
||
173 | } |
||
174 | public function removeAugust() |
||
175 | { |
||
176 | $this->removeMonth(8); |
||
177 | } |
||
178 | public function removeSeptember() |
||
179 | { |
||
180 | $this->removeMonth(9); |
||
181 | } |
||
182 | public function removeOctober() |
||
183 | { |
||
184 | $this->removeMonth(10); |
||
185 | } |
||
186 | public function removeNovember() |
||
187 | { |
||
188 | $this->removeMonth(11); |
||
189 | } |
||
190 | public function removeDecember() |
||
191 | { |
||
192 | $this->removeMonth(12); |
||
193 | } |
||
194 | |||
195 | // Private Functions |
||
196 | |||
197 | private function removeMonth($month) |
||
198 | { |
||
199 | if (! in_array($month, $this->monthsRemoved)) { |
||
200 | $this->monthsRemoved[] = $month; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | private function YearCalendar($year, Calendar $currentCalendar) |
||
205 | { |
||
206 | |||
207 | // 1) Single Values |
||
208 | |||
209 | $nowYear = date('Y'); |
||
210 | $nowMonth = date('n'); |
||
211 | |||
212 | $calendar['InnerClass'] = $this->innerClass; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$calendar was never initialized. Although not strictly required by PHP, it is generally a good practice to add $calendar = 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. ![]() |
|||
213 | $calendar['ExtraInnerClass'] = "$this->innerClass$year"; |
||
214 | $calendar['IsNow'] = $year == $nowYear; |
||
215 | $calendar['IsPast'] = $year < $nowYear; |
||
216 | |||
217 | // 2) Months Values |
||
218 | |||
219 | $months = $this->Months(); |
||
220 | |||
221 | if (count($months) == 0) { |
||
222 | return new ArrayData($calendar); |
||
223 | } |
||
224 | |||
225 | foreach ($months as $month) { |
||
226 | $weeksGroups = $this->MonthWeeks($month, $year); |
||
227 | |||
228 | // 1) Single Values |
||
229 | |||
230 | $monthDate = mktime(0, 0, 0, $month, 1, $year); |
||
231 | $values['IsNow'] = $calendar['IsNow'] && $month == $nowMonth; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = 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. ![]() |
|||
232 | $values['IsPast'] = $calendar['IsPast'] || ($calendar['IsNow'] && $month < $nowMonth); |
||
0 ignored issues
–
show
The variable
$values 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
![]() |
|||
233 | $values['MonthClass'] = eval($this->monthClass); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
234 | $values['MonthTitle'] = eval($this->monthTitle); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
235 | |||
236 | $period = $this->Calendar($weeksGroups, $values, $currentCalendar); |
||
237 | $period->setField('InnerClass', $this->monthInnerClass); |
||
238 | |||
239 | if ($this->monthLinkView) { |
||
240 | $linkController = $currentCalendar->getController(); |
||
241 | if ($this->monthLinkController) { |
||
242 | $linkController = $this->monthLinkController; |
||
243 | } |
||
244 | $linkCalendar = $currentCalendar; |
||
245 | if ($this->monthLinkCalendar) { |
||
246 | $linkCalendar = $this->monthLinkCalendar; |
||
247 | } |
||
248 | $params = $this->monthLinkView->getLinkParams($monthDate); |
||
249 | $period->setField('Link', $linkCalendar->Link($linkController, $this->monthLinkView, $params)); |
||
250 | } |
||
251 | $periods[] = $period; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$periods was never initialized. Although not strictly required by PHP, it is generally a good practice to add $periods = 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. ![]() |
|||
252 | } |
||
253 | |||
254 | $calendar['Months'] = new ArrayList($periods); |
||
0 ignored issues
–
show
The variable
$periods 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
![]() |
|||
255 | |||
256 | return new ArrayData($calendar); |
||
257 | } |
||
258 | |||
259 | private function Months() |
||
260 | { |
||
261 | $month = $this->monthStart; |
||
262 | |||
263 | $months = array(); |
||
264 | while ($month <= 12) { |
||
265 | if (! in_array($month, $this->monthsRemoved)) { |
||
266 | $months[] = $month; |
||
267 | } |
||
268 | $month++; |
||
269 | } |
||
270 | |||
271 | return $months; |
||
272 | } |
||
273 | |||
274 | // Link Functions |
||
275 | |||
276 | public function linkMonthTo(CalendarMonthView $view, Calendar $calendar = null, $controller = null) |
||
277 | { |
||
278 | $this->monthLinkView = $view; |
||
279 | $this->monthLinkCalendar = $calendar; |
||
280 | $this->monthLinkController = $controller; |
||
281 | } |
||
282 | |||
283 | // Other Functions |
||
284 | |||
285 | View Code Duplication | public function getCustomisedTitle($year) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() 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. ![]() |
|||
286 | { |
||
287 | $date = mktime(0, 0, 0, 1, 1, $year); |
||
0 ignored issues
–
show
$date 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 ![]() |
|||
288 | $result = eval($this->viewTitle); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
289 | if ($this->number > 1) { |
||
290 | $date = mktime(0, 0, 0, 1, 1, $year + $this->number - 1); |
||
0 ignored issues
–
show
$date 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 ![]() |
|||
291 | $result .= $this->viewTitleDelimiter . eval($this->viewTitle); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
292 | } |
||
293 | return $result; |
||
294 | } |
||
295 | } |
||
296 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.