GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CCalendar::generateCalenderData()   C
last analyzed

Complexity

Conditions 7
Paths 32

Size

Total Lines 47
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 38.7025

Importance

Changes 0
Metric Value
cc 7
eloc 33
c 0
b 0
f 0
nc 32
nop 0
dl 0
loc 47
rs 6.7272
ccs 5
cts 37
cp 0.1351
crap 38.7025
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
4
include 'CWeek.php';
5
include 'CDay.php';
6
7
class CCalendar {
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...
8
    private $weeks = array();
9
    private $month;
10
    private $year;
11
    private $events = array();
12
13
    public function setEvents($values = []){
14
        $this->events = $values;
15
    }
16
17 1
    public function getValues($year = null, $month = null){
0 ignored issues
show
Coding Style introduced by
getValues uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18 1
        if($year && $month){
19
            $this->setYear($year)->setMonth($month);
20
        }
21
        else if(isset($_GET['year']) && isset($_GET['month'])){
22
            $this->setYear($_GET['year'])->setMonth($_GET['month']);
23
        }
24
        else {
25
            $this->setYear(date('Y'))->setMonth(date('m'));
26 1
        }
27 1
    }
28
29
    public function getWeeks()
30
    {
31
        return $this->weeks;
32
    }
33
34 View Code Duplication
    public function prev(){
0 ignored issues
show
Duplication introduced by
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.

Loading history...
35
      $year = $this->year;
36
      $month = $this->month;
37
38
        if($month == 1){
39
            $month = 12;
40
          	$year--;
41
        } else {
42
            $month--;
43
        }
44
45
      return ["year" => $year, "month"=>$month];
46
    }
47 View Code Duplication
    public function next(){
0 ignored issues
show
Duplication introduced by
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.

Loading history...
48
      $year = $this->year;
49
        $month = $this->month;
50
          if($month == 12){
51
              $month = 1;
52
              $year++;
53
          } else {
54
              $month++;
55
          }
56
        return ["year" => $year, "month"=>$month];
57
    }
58
    public function addWeek($week)
59
    {
60
        $this->weeks[] = $week;
61
    }
62
63 1
    public function setMonth($month)
64
    {
65 1
        $this->month = (int)$month;
66 1
        return $this;
67
    }
68
69
    public function getMonthNumber(){
70
        $dateString = strtotime(sprintf('%s-%s-01', $this->year, $this->month));
71
        return $month = date('m', $dateString);
0 ignored issues
show
Unused Code introduced by
$month 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
    }
73
    public function getMonthName(){
74
        $dateString = strtotime(sprintf('%s-%s-01', $this->year, $this->month));
75
        return $month = date('F', $dateString);
0 ignored issues
show
Unused Code introduced by
$month 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
    }
77
78 1
    public function setYear($year){
79 1
        $this->year = $year;
80 1
        return $this;
81
    }
82
    public function getMonth(){
83
        return $this->month;
84
    }
85
    public function getYear(){
86
        return $this->year;
87
    }
88
89 1
    public function generateCalenderData(){
90 1
        $daysUsed = 0;
91
        $dateString = strtotime(sprintf('%s-%s-01', $this->year, $this->month));
92
        $monthDays = date('t', $dateString);
93
        $dayOfWeek = date('w', $dateString);
94
        $firstWeek = new CWeek();
95
        $emptyDays = $this->getAmountOfEmptyDays($dayOfWeek);
96
        for($i = 1; $i<=$emptyDays; $i++){
97
            $firstWeek->addWeekday(new CDay());
98
        }
99
100
        for($i = 1; $i<=7-$emptyDays;$i++){
101
            $dateString = strtotime(sprintf('%s-%s-%s', $this->year, $this->month, $i));
102
            $day = new CDay();
103
            $day->setName(date('l', $dateString));
104
            $day->setDayOfMonthNumber($i);
105
            $firstWeek->addWeekday($day);
106
            $daysUsed ++;
107
        }
108
109
        $this->addWeek($firstWeek);
110 1
        $week = null;
111
112
        for($date = $daysUsed+1;$date<=$monthDays;$date++){
113
            $dateString = strtotime(sprintf('%s-%s-%s', $this->year, $this->month, $date));
114
            $dayOfWeek = date('w', $dateString);
115
            if($dayOfWeek == 1){
116
                if($week){
117
                    $this->addWeek($week);
118
                }
119
                $week = new CWeek();
120
            }
121
122
            $day = new CDay();
123
            $day->setName(date('l', $dateString));
124
            $day->setDayOfMonthNumber($date);
125
            $week->addWeekday($day);
126
127
        }
128
        $extraDays = 7-$week->getLengthOfDayArray();
129
130
        for($i = 0;$i<$extraDays;$i++){
131
            $week->addWeekday(new CDay());
132 1
        }
133
        $this->addWeek($week);
134
135 1
    }
136
137
138 1
    private function getAmountOfEmptyDays($firstDayOfMonth){
139 1
        $number = 0;
0 ignored issues
show
Unused Code introduced by
$number 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140 1
        if($firstDayOfMonth == 0){
141
            $number = 6;
142
        } else {
143 1
            $number = $firstDayOfMonth -1;
144
        }
145 1
        return $number;
146
    }
147
148
    public function printCalendar(){
149
        $prevData = $this->prev();
0 ignored issues
show
Unused Code introduced by
$prevData 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
150
        $nextData = $this->next();
0 ignored issues
show
Unused Code introduced by
$nextData 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
151
        $html = "<div class='headerCalendar'>
152
                    <p class='year'> $this->year</p><p class='month'>" . $this->getMonthName() . "</p>
153
                 </div>
154
                 <div>
155
                 <table class='bordered'>";
156
157
        foreach($this->getWeeks() as $week){
158
            $html .= "<tr>";
159
            foreach($week -> getWeekdays() as $day){
160
                $currentDay = $day->getName();
161
                $todaysDay = date('j');
162
                $currentMonth = date('m');
163
                $html .= "<td>";
164
165
                if($currentDay == "Sunday"){
166
                    $html .= "<div class='redNumber'>" . $day->getDayOfMonthNumber() . "</div>";
167
                    $html .= "<div class='redName'>" . $day->getName() . "</div>";
168
                } else {
169
                    if($day->getDayOfMonthNumber() == $todaysDay && $this->month == $currentMonth) {
170
                        $html .= "<div class='current'><div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
171
                        $html .= "<div class='monthName'>" . $day->getName() . "</div></div>";
172
                    } else {
173
                        if($this->month == 12 && $day->getDayOfMonthNumber() == 24){
174
                            $html .= "<div class='christmas'><div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
175
                            $html .= "<div class='monthName'>" . $day->getName() . "</div></div>";
176
                        } else {
177
                            $html .= "<div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
178
                            $html .= "<div class='monthName'>" . $day->getName() . "</div>";
179
                        }
180
                    }
181
                }
182
                $html .= "</td>";
183
            }
184
            $html .= "</tr>";
185
        }
186
187
        $html .= "</table></div>";
188
        return $html;
189
    }
190
191
    public function printMiniCalendar(){
192
        $img = $this->month;
0 ignored issues
show
Unused Code introduced by
$img 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
193
        $prevData = $this->prev();
194
        $nextData = $this->next();
195
        $html = "
196
                 <div class='leftArrow'> <a href='?month=". $prevData["month"] ."&year=" . $prevData["year"] . "'><img src='./img/orangeArrow.png'></a></div>
197
                 <div class='rightArrow'> <a href='?month=". $nextData["month"] ."&year=" . $nextData["year"] . "'><img src='./img/orangeArrow.png'></a></div>
198
                 <div class='bordered'>
199
                 <table>";
200
201
202
203
204
        foreach($this -> getWeeks() as $week){
205
            $html .= "<tr>";
206
            foreach($week -> getWeekdays() as $day){
207
                $currentDay = $day->getName();
208
                $todaysDay = date('j');
209
                $currentMonth = date('m');
210
                $html .= "<td>";
211
212
                if($currentDay == "Sunday"){
213
                    $html .= "<div class='redNumber'>" . $day->getDayOfMonthNumber() . "</div>";
214
                } else {
215
                    if($day->getDayOfMonthNumber() == $todaysDay && $this->month == $currentMonth) {
216
                        $html .= "<div class='current'><div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
217
                    } else {
218
                        if($this->month == 12 && $day->getDayOfMonthNumber() == 24){
219
                            $html .= "<div class='christmas'><div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
220
                        } else {
221
                            $html .= "<div class='monthNumber'>" . $day->getDayOfMonthNumber() . "</div>";
222
                        }
223
                    }
224
                }
225
                $html .= "</td>";
226
            }
227
            $html .= "</tr>";
228
        }
229
230
        $html .= "</table></div>";
231
        return $html;
232
    }
233
234
    public function printResponsiveCalendar($count){
235
        $prevData = $this->prev();
236
        $nextData = $this->next();
237
238
        $html = "
239
                    <div class='page-header'>
240
                        <h1 class='text-center'>" . $this->getMonthName() ." ". $this->year ."</h1>
241
                            <button type=\"button\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\".bd-example-modal-sm\">Add Event</button>
242
                            <div class='btn-group '>
243
244
                            <a href='?month=". $prevData["month"] ."&year=" . $prevData["year"] . "' class='btn btn-primary btn-md'>Previus</a>
245
                            <a href='?month=". $nextData["month"] ."&year=" . $nextData["year"] . "' class='btn btn-primary btn-md'>Next</a>
246
                        </div>
247
                    </div>
248
                    <div class='col-md-8'>
249
                    <div class='calendar'>
250
        ";
251
252
        $html .= "<ul class='weekdays'>
253
            <li>Mon</li>
254
            <li>Tue</li>
255
            <li>Wed</li>
256
            <li>Thu</li>
257
            <li>Fri</li>
258
            <li>Sat</li>
259
            <li>Sun</li>
260
        </ul>";
261
262
263
264
        foreach($this->getWeeks() as $week){
265
            $html .= "<ul class='days'>";
266
            foreach($week -> getWeekdays() as $day){
267
                if($day->getDayOfMonthNumber() == null){
268
                    $id = 0;
269
270
                } else {
271
                    if($count[$day->getDayOfMonthNumber()] == null){
272
                        $id = 0;
273
                    }
274
                    else{
275
                    $id = $day->getDayOfMonthNumber();
276
                    }
277
278
                }
279
                if($day->getDayOfMonthNumber() == null){
280
                        $html .= "<li class='day-empty'></li>";
281
                } else {
282
283
                    $html .= "
284
                    <a href='calendar?month=".$this->month."&year=".$this->year."&date=". $day->getDayOfMonthNumber() ."'><li class='days'>";
285
                        if($id == 0){
286
                            $html .= "<span class='label label-danger label-pill pull-xs-left'></span>";
287
                        } else {
288
                            $html .= "<span class='label label-danger label-pill pull-right '>$count[$id]</span>";
289
                        }
290
291
                    $html .="<div class='date'>". $day->getDayOfMonthNumber() ."</div>
292
                    </li>
293
                    </a>
294
                    ";
295
                }
296
            }
297
            $html .= "</ul>";
298
        }
299
300
        $html .= "</div></div>";
301
302
        return $html;
303
    }
304
305
}
306