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 CalendarWeekView extends CalendarAbstractTimeView |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | |||
6 | // Attributes |
||
7 | |||
8 | private $dayStart = 1; |
||
9 | private $daysRemoved = array(); |
||
10 | |||
11 | // Abstract Functions Implemented |
||
12 | |||
13 | public function init() |
||
14 | { |
||
15 | parent::init(); |
||
16 | $this->containerClass = 'weekView'; |
||
17 | $this->innerClass = 'week'; |
||
18 | $this->viewTitle = 'return \'Week Of \' . date(\'l jS F Y\', $date);'; |
||
19 | } |
||
20 | |||
21 | View Code Duplication | public function prevLinkParams(Calendar $calendar) |
|
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. ![]() |
|||
22 | { |
||
23 | $date = $this->getWeekStartDay($calendar->getDay(), $calendar->getMonth(), $calendar->getYear()); |
||
24 | $dayValue = date('j', $date) - ($this->number * 7); |
||
25 | $monthValue = date('n', $date); |
||
26 | $yearValue = date('Y', $date); |
||
27 | $date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
||
28 | return $this->getLinkParams($date); |
||
29 | } |
||
30 | |||
31 | View Code Duplication | public function nextLinkParams(Calendar $calendar) |
|
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. ![]() |
|||
32 | { |
||
33 | $date = $this->getWeekStartDay($calendar->getDay(), $calendar->getMonth(), $calendar->getYear()); |
||
34 | $dayValue = date('j', $date) + ($this->number * 7); |
||
35 | $monthValue = date('n', $date); |
||
36 | $yearValue = date('Y', $date); |
||
37 | $date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
||
38 | return $this->getLinkParams($date); |
||
39 | } |
||
40 | |||
41 | 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 ![]() |
|||
42 | { |
||
43 | return $this->number == 1 ? 'week' : "$this->number weeks"; |
||
44 | } |
||
45 | |||
46 | public function Dates(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 ![]() |
|||
47 | { |
||
48 | $year = $calendar->getYear(); |
||
49 | $month = $calendar->getMonth(); |
||
50 | $day = $calendar->getDay(); |
||
51 | |||
52 | if (count($this->daysRemoved) == 7) { |
||
53 | return $datesGroups; |
||
0 ignored issues
–
show
The variable
$datesGroups seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case, ![]() |
|||
54 | } |
||
55 | |||
56 | $lastDate = $this->getWeekStartDay($day, $month, $year); |
||
57 | |||
58 | View Code Duplication | while (date('N', $lastDate) != $this->dayStart) { |
|
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. ![]() |
|||
59 | $lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) - 1, date('Y', $lastDate)); |
||
60 | } |
||
61 | View Code Duplication | while (in_array(date('N', $lastDate), $this->daysRemoved)) { |
|
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. ![]() |
|||
62 | $lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) + 1, date('Y', $lastDate)); |
||
63 | } |
||
64 | |||
65 | for ($i = 0; $i < $this->number; $i++) { |
||
66 | $datesGroup = array(); |
||
67 | for ($j = 0; $j < 7; $j++) { |
||
68 | if (! in_array(date('N', $lastDate), $this->daysRemoved)) { |
||
69 | $datesGroup[] = $lastDate; |
||
70 | } |
||
71 | $lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) + 1, date('Y', $lastDate)); |
||
72 | } |
||
73 | $datesGroups[] = $datesGroup; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$datesGroups was never initialized. Although not strictly required by PHP, it is generally a good practice to add $datesGroups = 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. ![]() |
|||
74 | } |
||
75 | |||
76 | return $datesGroups; |
||
0 ignored issues
–
show
The variable
$datesGroups 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
![]() |
|||
77 | } |
||
78 | |||
79 | public function getCustomisedTitle($day, $month, $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 ![]() |
|||
80 | { |
||
81 | $date = $this->getWeekStartDay($day, $month, $year); |
||
82 | $result = eval($this->viewTitle); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
83 | if ($this->number > 1) { |
||
84 | $dayValue = date('j', $date) + (($this->number - 1) * 7); |
||
85 | $monthValue = date('n', $date); |
||
86 | $yearValue = date('Y', $date); |
||
87 | $date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
||
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 ![]() |
|||
88 | $result .= $this->viewTitleDelimiter . eval($this->viewTitle); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
89 | } |
||
90 | return $result; |
||
91 | } |
||
92 | |||
93 | // Functions |
||
94 | |||
95 | public function startByMonday() |
||
96 | { |
||
97 | $this->dayStart = 1; |
||
98 | } |
||
99 | public function startByTuesday() |
||
100 | { |
||
101 | $this->dayStart = 2; |
||
102 | } |
||
103 | public function startByWednesday() |
||
104 | { |
||
105 | $this->dayStart = 3; |
||
106 | } |
||
107 | public function startByThursday() |
||
108 | { |
||
109 | $this->dayStart = 4; |
||
110 | } |
||
111 | public function startByFriday() |
||
112 | { |
||
113 | $this->dayStart = 5; |
||
114 | } |
||
115 | public function startBySaturday() |
||
116 | { |
||
117 | $this->dayStart = 6; |
||
118 | } |
||
119 | public function startBySunday() |
||
120 | { |
||
121 | $this->dayStart = 7; |
||
122 | } |
||
123 | |||
124 | public function removeMonday() |
||
125 | { |
||
126 | $this->removeDay(1); |
||
127 | } |
||
128 | public function removeTuesday() |
||
129 | { |
||
130 | $this->removeDay(2); |
||
131 | } |
||
132 | public function removeWednesday() |
||
133 | { |
||
134 | $this->removeDay(3); |
||
135 | } |
||
136 | public function removeThursday() |
||
137 | { |
||
138 | $this->removeDay(4); |
||
139 | } |
||
140 | public function removeFriday() |
||
141 | { |
||
142 | $this->removeDay(5); |
||
143 | } |
||
144 | public function removeSaturday() |
||
145 | { |
||
146 | $this->removeDay(6); |
||
147 | } |
||
148 | public function removeSunday() |
||
149 | { |
||
150 | $this->removeDay(7); |
||
151 | } |
||
152 | |||
153 | // Private Functions |
||
154 | |||
155 | private function getWeekStartDay($day, $month, $year) |
||
156 | { |
||
157 | $date = mktime(0, 0, 0, $month, $day, $year); |
||
158 | |||
159 | View Code Duplication | while (date('N', $date) > 1) { // It means that the 1st day of this week is not Monday |
|
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. ![]() |
|||
160 | $date = mktime(0, 0, 0, date('n', $date), date('j', $date) - 1, date('Y', $date)); |
||
161 | } |
||
162 | |||
163 | return $date; |
||
164 | } |
||
165 | |||
166 | private function getWeekEndDay($day, $month, $year) |
||
167 | { |
||
168 | $date = $this->getWeekStartDay($day, $month, $year); |
||
169 | $date = mktime(0, 0, 0, date('n', $date), date('j', $date) + 6, date('Y', $date)); |
||
170 | return $date; |
||
171 | } |
||
172 | |||
173 | private function removeDay($day) |
||
174 | { |
||
175 | if (! in_array($day, $this->daysRemoved)) { |
||
176 | $this->daysRemoved[] = $day; |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 |
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.