MonthDecorator::prevMonth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
* Description: demonstrates a decorator to provide simple output formatting
4
* on the month while still allowing the days to be accessed via the decorator
5
* In practice you _wouldn't_ do this - each decorator comes with a performance
6
* hit for extra method calls. For this example some simple functions could help
7
* format the month while the days are accessed via the normal Month object
8
*/
9
if ( !@include 'Calendar/Calendar.php' ) {
10
    define('CALENDAR_ROOT','../../');
11
}
12
require_once CALENDAR_ROOT.'Month/Weekdays.php';
13
require_once CALENDAR_ROOT.'Decorator.php';
14
15
// Decorate a Month with methods to improve formatting
16
class MonthDecorator extends Calendar_Decorator {
0 ignored issues
show
Bug introduced by
The type Calendar_Decorator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
    /**
18
    * @param Calendar_Month
19
    */
20
    function MonthDecorator(& $Month) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
        parent::Calendar_Decorator($Month);
22
    }
23
    /**
24
    * Override the prevMonth method to format the output
25
    */
26
    function prevMonth() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
        $prevStamp = parent::prevMonth(TRUE);
28
        // Build the URL for the previous month
29
        return $_SERVER['PHP_SELF'].'?y='.date('Y',$prevStamp).
30
            '&m='.date('n',$prevStamp).'&d='.date('j',$prevStamp);
31
    }
32
    /**
33
    * Override the thisMonth method to format the output
34
    */
35
    function thisMonth() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
        $thisStamp = parent::thisMonth(TRUE);
37
        // A human readable string from this month
38
        return date('F Y',$thisStamp);
39
    }
40
    /**
41
    * Override the nextMonth method to format the output
42
    */
43
    function nextMonth() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44
        $nextStamp = parent::nextMonth(TRUE);
45
        // Build the URL for next month
46
        return $_SERVER['PHP_SELF'].'?y='.date('Y',$nextStamp).
47
            '&m='.date('n',$nextStamp).'&d='.date('j',$nextStamp);
48
    }
49
}
50
51
if (!isset($_GET['y'])) $_GET['y'] = date('Y');
52
if (!isset($_GET['m'])) $_GET['m'] = date('n');
53
54
// Creata a month as usual
55
$Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
0 ignored issues
show
Bug introduced by
The type Calendar_Month_Weekdays was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
57
// Pass it to the decorator and use the decorator from now on...
58
$MonthDecorator = new MonthDecorator($Month);
59
$MonthDecorator->build();
60
?>
61
62
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
63
<html>
64
<head>
65
<title> A Simple Decorator </title>
66
</head>
67
<body>
68
<h1>A Simple Decorator</h1>
69
<table>
70
<caption><?php echo ( $MonthDecorator->thisMonth() ); ?></caption>
71
<?php
72
while ( $Day = $MonthDecorator->fetch() ) {
73
    if ( $Day->isFirst() ) {
74
        echo ( "\n<tr>\n" );
75
    }
76
    if ( $Day->isEmpty() ) {
77
        echo ( "<td>&nbsp;</td>" );
78
    } else {
79
        echo ( "<td>".$Day->thisDay()."</td>" );
80
    }
81
    if ( $Day->isLast() ) {
82
        echo ( "\n</tr>\n" );
83
    }
84
}
85
?>
86
<tr>
87
<td><a href="<?php echo ($MonthDecorator->prevMonth()); ?>">Prev</a></td>
88
<td colspan="5">&nbsp;</td>
89
<td><a href="<?php echo ($MonthDecorator->nextMonth()); ?>">Next</a></td>
90
</tr>
91
</table>
92
</body>
93
</html>