Issues (156)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/abstract/CalendarAbstractWeekView.php (19 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
abstract class CalendarAbstractWeekView extends CalendarAbstractView
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    // Attributes
7
8
    private $dayStart = 1;
9
    private $daysRemoved = array();
10
11
    protected $showWeekLeft;
12
    protected $weekLeftTitle;
13
    protected $weekLeft;
14
    protected $showWeekRight;
15
    protected $weekRightTitle;
16
    protected $weekRight;
17
    protected $dayTitleClass;
18
    protected $dayTitle;
19
    protected $weekClass;
20
    protected $dayClass;
21
22
    private $weekLinkView;
23
    private $weekLinkCalendar;
24
    private $weekLinkController;
25
26
    private $dayLinkView;
27
    private $dayLinkCalendar;
28
    private $dayLinkController;
29
30
    // Abstract Functions Implemented
31
32
    public function init()
33
    {
34
        $this->weekLeft = $this->weekRight = 'return $week[\'week\'];';
35
        $this->dayTitleClass = 'return strtolower(date(\'l\', $day));';
36
        $this->dayTitle = 'return date(\'l\', $day);';
37
        $this->weekClass = 'return \'week\' . $week[\'week\'] . \' year\' . $week[\'yearOfWeek\'];';
38
        $this->dayClass = 'return strtolower(date(\'l\', $date));';
39
    }
40
41
    public function Calendars(Calendar $calendar)
42
    {
43
        $weeksGroups = $this->Weeks($calendar);
44
45
        foreach ($weeksGroups as $weeksGroup) {
46
            list($weeksGroup, $values) = $weeksGroup;
47
            $calendars[] = $this->Calendar($weeksGroup, $values, $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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key 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.

Loading history...
48
        }
49
50
        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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
51
    }
52
53
    // Functions
54
55
    public function startByMonday()
56
    {
57
        $this->dayStart = 1;
58
    }
59
    public function startByTuesday()
60
    {
61
        $this->dayStart = 2;
62
    }
63
    public function startByWednesday()
64
    {
65
        $this->dayStart = 3;
66
    }
67
    public function startByThursday()
68
    {
69
        $this->dayStart = 4;
70
    }
71
    public function startByFriday()
72
    {
73
        $this->dayStart = 5;
74
    }
75
    public function startBySaturday()
76
    {
77
        $this->dayStart = 6;
78
    }
79
    public function startBySunday()
80
    {
81
        $this->dayStart = 7;
82
    }
83
84
    public function removeMonday()
85
    {
86
        $this->removeDay(1);
87
    }
88
    public function removeTuesday()
89
    {
90
        $this->removeDay(2);
91
    }
92
    public function removeWednesday()
93
    {
94
        $this->removeDay(3);
95
    }
96
    public function removeThursday()
97
    {
98
        $this->removeDay(4);
99
    }
100
    public function removeFriday()
101
    {
102
        $this->removeDay(5);
103
    }
104
    public function removeSaturday()
105
    {
106
        $this->removeDay(6);
107
    }
108
    public function removeSunday()
109
    {
110
        $this->removeDay(7);
111
    }
112
113
    public function showWeekLeft()
114
    {
115
        $this->showWeekLeft = true;
116
    }
117
    public function hideWeekLeft()
118
    {
119
        $this->showWeekLeft = false;
120
    }
121
    public function setWeekLeftTitle($weekLeftTitle)
122
    {
123
        $this->weekLeftTitle = $weekLeftTitle;
124
    }
125
    public function setWeekLeft($weekLeft)
126
    {
127
        $this->weekLeft = $weekLeft;
128
    }
129
    public function showWeekRight()
130
    {
131
        $this->showWeekRight = true;
132
    }
133
    public function hideWeekRight()
134
    {
135
        $this->showWeekRight = false;
136
    }
137
    public function setWeekRightTitle($weekRightTitle)
138
    {
139
        $this->weekRightTitle = $weekRightTitle;
140
    }
141
    public function setWeekRight($weekRight)
142
    {
143
        $this->weekRight = $weekRight;
144
    }
145
    public function setDayTitleClass($dayTitleClass)
146
    {
147
        $this->dayTitleClass = $dayTitleClass;
148
    }
149
    public function setDayTitle($dayTitle)
150
    {
151
        $this->dayTitle = $dayTitle;
152
    }
153
    public function setWeekClass($weekClass)
154
    {
155
        $this->weekClass = $weekClass;
156
    }
157
    public function setDayClass($dayClass)
158
    {
159
        $this->dayClass = $dayClass;
160
    }
161
162
    // Private Functions
163
164
    private function removeDay($day)
165
    {
166
        if (! in_array($day, $this->daysRemoved)) {
167
            $this->daysRemoved[] = $day;
168
        }
169
    }
170
171
    // Abstract Functions
172
173
    abstract public function Weeks(Calendar $calendar);
0 ignored issues
show
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
174
175
    // Template Functions
176
177
    protected function Calendar($weeks, $values, Calendar $currentCalendar)
178
    {
179
        // 1) Single Values
180
181
        $calendar = $values;
182
        $calendar['InnerClass'] = $this->innerClass;
183
        $calendar['ShowWeekLeft'] = $this->showWeekLeft;
184
        $calendar['WeekLeftTitle'] = $this->weekLeftTitle;
185
        $calendar['ShowWeekRight'] = $this->showWeekRight;
186
        $calendar['WeekRightTitle'] = $this->weekRightTitle;
187
        //Hack
188
        $week = $weeks[1]['week'];
189
        $year = $weeks[1]['yearOfWeek'];
190
        $monthTitleDate = $this->getWeekStartDay($week, $year);
191
        $calendar['MonthTitle'] = date('F Y', $monthTitleDate);
192
193
        // 2) Days Values
194
195
        $daysByDateFormat = $this->DaysByDateFormat();
196
197
        if (count($daysByDateFormat) == 0) {
198
            return new ArrayData($calendar);
199
        }
200
201 View Code Duplication
        foreach ($daysByDateFormat as $day) {
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...
202
            $dayTitleClass = eval($this->dayTitleClass);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
203
            $dayTitle = eval($this->dayTitle);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
204
            $days[] = new ArrayData(array('DayTitleClass' => $dayTitleClass, 'DayTitle' => $dayTitle));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$days was never initialized. Although not strictly required by PHP, it is generally a good practice to add $days = 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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key 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.

Loading history...
205
        }
206
207
        $calendar['Days'] = new ArrayList($days);
0 ignored issues
show
The variable $days 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
208
209
        // 3) Weeks Values
210
211
        $today = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
212
213
        foreach ($weeks as $week) {
214
            $period = array();
215
216
            // 1) Single Values
217
218
            $period['WeekClass'] = eval($this->weekClass);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
219
            $period['ShowWeekLeft'] = $this->showWeekLeft;
220
            $period['WeekLeft'] = eval($this->weekLeft);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
221
            $period['ShowWeekRight'] = $this->showWeekRight;
222
            $period['WeekRight'] = eval($this->weekRight);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
223
224
            if ($this->weekLinkView) {
225
                $date = $this->getWeekStartDay($week['week'], $week['yearOfWeek']);
226
                $linkController = $currentCalendar->getController();
227
                if ($this->weekLinkController) {
228
                    $linkController = $this->weekLinkController;
229
                }
230
                $linkCalendar = $currentCalendar;
231
                if ($this->weekLinkCalendar) {
232
                    $linkCalendar = $this->weekLinkCalendar;
233
                }
234
                $params = $this->weekLinkView->getLinkParams($date);
235
                $period['WeekLink'] = $linkCalendar->Link($linkController, $this->weekLinkView, $params);
236
            }
237
238
            // 2) Days Values
239
240
            $days = array();
241
242
            $dates = $this->WeekDates($daysByDateFormat, $week['week'], $week['yearOfWeek']);
243
244
            foreach ($dates as $date) {
245
                $day = date('j', $date);
246
                $month = date('n', $date);
247
                $year = date('Y', $date);
248
249
                $dateParams = array();
250
251
                $dateParams['IsToday'] = $date == $today;
252
                $dateParams['IsPast'] = $date < $today;
253
                if ($month == $week['month']) {
254
                    $dateParams['CurrentMonth'] = true;
255
                } elseif (($year == $week['yearOfMonth'] && $month < $week['month']) || ($year == $week['yearOfMonth'] - 1 && $month == 12)) {
256
                    $dateParams['PrevMonth'] = true;
257
                    if ($year == $week['yearOfMonth'] - 1) {
258
                        $dateParams['PrevYear'] = true;
259
                    }
260
                } else {
261
                    $dateParams['NextMonth'] = true;
262
                    if ($year == $week['yearOfMonth'] + 1) {
263
                        $dateParams['NextYear'] = true;
264
                    }
265
                }
266
267
                $dateParams['DayClass'] = eval($this->dayClass);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
268
                $dateParams['Day'] = $day;
269
270
                if ($this->dayLinkView) {
271
                    $linkController = $currentCalendar->getController();
272
                    if ($this->dayLinkController) {
273
                        $linkController = $this->dayLinkController;
274
                    }
275
                    $linkCalendar = $currentCalendar;
276
                    if ($this->dayLinkCalendar) {
277
                        $linkCalendar = $this->dayLinkCalendar;
278
                    }
279
                    $params = $this->dayLinkView->getLinkParams($date);
280
                    $dateParams['Link'] = $linkCalendar->Link($linkController, $this->dayLinkView, $params);
281
                }
282
283
284
285
                $this->extend('updateDateParams', $date, $dateParams, $currentCalendar);
286
287
                $days[] = new ArrayData($dateParams);
288
            }
289
290
            $period['Days'] = new ArrayList($days);
291
292
            $periods[] = new ArrayData($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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key 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.

Loading history...
293
        }
294
295
        $calendar['Weeks'] = 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
296
297
        return new ArrayData($calendar);
298
    }
299
300
    public function WeekDates($days, $week, $year)
301
    {
302
        $firstDate = $this->getWeekStartDay($week, $year);
303
304
        $beforeMonday = true;
305
306
        foreach ($days as $day) {
307
            $date = $firstDate;
308
309
            if (date('N', $day) == 1) {
310
                $beforeMonday = false;
311
            }
312
313
            while (date('N', $date) != date('N', $day)) {
314
                $date = mktime(0, 0, 0, date('n', $date), date('j', $date) + ($beforeMonday ? -1 : 1), date('Y', $date));
315
            }
316
317
            $dates[] = $date;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dates was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dates = 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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key 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.

Loading history...
318
        }
319
320
        return $dates;
0 ignored issues
show
The variable $dates 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
321
    }
322
323
    private function DaysByDateFormat()
324
    {
325
        $day = $this->dayStart;
326
327
        $days = array();
328
        for ($i = 1; $i <= 7; $i++) {
329
            if (! in_array($day, $this->daysRemoved)) {
330
                $days[] = mktime(0, 0, 0, 1, $day, 1);
331
            }
332
            $day = $day < 7 ? $day + 1 : 1;
333
        }
334
335
        return $days;
336
    }
337
338
    protected function getWeekStartDay($week, $year, $fromStartDay = false)
339
    {
340
341
        // 1) Research of the week
342
343
        $firstDate = mktime(0, 0, 0, 1, 1, $year);
344 View Code Duplication
        while (date('W', $firstDate) != 1) {
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...
345
            $firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) + 1, date('Y', $firstDate));
346
        }
347 View Code Duplication
        while (date('W', $firstDate) < $week) {
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...
348
            $firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) + 7, date('Y', $firstDate));
349
        }
350
351
        // 2) Research of the first day of the week
352
353
        $diff = date('N', $firstDate) - 1;
354
        if ($fromStartDay && $this->dayStart != 1) {
355
            $diff += 8 - $this->dayStart;
356
        }
357
        $firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) - $diff, date('Y', $firstDate));
358
359
        return $firstDate;
360
    }
361
362
    // Link Functions
363
364
    public function linkWeekTo(CalendarWeekView $view, Calendar $calendar = null, $controller = null)
365
    {
366
        $this->weekLinkView = $view;
367
        $this->weekLinkCalendar = $calendar;
368
        $this->weekLinkController = $controller;
369
    }
370
371
    public function linkDayTo(CalendarDayView $view, Calendar $calendar = null, $controller = null)
372
    {
373
        $this->dayLinkView = $view;
374
        $this->dayLinkCalendar = $calendar;
375
        $this->dayLinkController = $controller;
376
    }
377
}
378