Completed
Push — master ( 7903bf...133ddc )
by Greg
01:37
created

shims.php ➔ cal_to_jd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 26 and the first side effect is on line 24.

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
 * If ext/calendar is not installed, then provide the necessary shims.
4
 *
5
 * @author    Greg Roach <[email protected]>
6
 * @copyright (c) 2014-2017 Greg Roach
7
 * @license   This program is free software: you can redistribute it and/or modify
8
 *            it under the terms of the GNU General Public License as published by
9
 *            the Free Software Foundation, either version 3 of the License, or
10
 *            (at your option) any later version.
11
 *
12
 *            This program is distributed in the hope that it will be useful,
13
 *            but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *            GNU General Public License for more details.
16
 *
17
 *            You should have received a copy of the GNU General Public License
18
 *            along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
use Fisharebest\ExtCalendar\Shim;
22
23
if (!defined('CAL_GREGORIAN')) {
24
	Shim::create();
25
26
	define('CAL_GREGORIAN', 0);
27
	define('CAL_JULIAN', 1);
28
	define('CAL_JEWISH', 2);
29
	define('CAL_FRENCH', 3);
30
	define('CAL_NUM_CALS', 4);
31
	define('CAL_DOW_DAYNO', 0);
32
	define('CAL_DOW_SHORT', Shim::shouldEmulateBug67960() ? 1 : 2);
33
	define('CAL_DOW_LONG', Shim::shouldEmulateBug67960() ? 2 : 1);
34
	define('CAL_MONTH_GREGORIAN_SHORT', 0);
35
	define('CAL_MONTH_GREGORIAN_LONG', 1);
36
	define('CAL_MONTH_JULIAN_SHORT', 2);
37
	define('CAL_MONTH_JULIAN_LONG', 3);
38
	define('CAL_MONTH_JEWISH', 4);
39
	define('CAL_MONTH_FRENCH', 5);
40
	define('CAL_EASTER_DEFAULT', 0);
41
	define('CAL_EASTER_ROMAN', 1);
42
	define('CAL_EASTER_ALWAYS_GREGORIAN', 2);
43
	define('CAL_EASTER_ALWAYS_JULIAN', 3);
44
	define('CAL_JEWISH_ADD_ALAFIM_GERESH', 2);
45
	define('CAL_JEWISH_ADD_ALAFIM', 4);
46
	define('CAL_JEWISH_ADD_GERESHAYIM', 8);
47
48
	/**
49
	 * @param integer $calendar_id
50
	 * @param integer $month
51
	 * @param integer $year
52
	 *
53
	 * @return integer|boolean
54
	 */
55
56
	function cal_days_in_month($calendar_id, $month, $year) {
0 ignored issues
show
Coding Style introduced by
function cal_days_in_month() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
57
		return Shim::calDaysInMonth($calendar_id, $month, $year);
58
	}
59
60
	/**
61
	 * @param integer $julian_day
62
	 * @param integer $calendar_id
63
	 *
64
	 * @return array|boolean
65
	 */
66
	function cal_from_jd($julian_day, $calendar_id) {
0 ignored issues
show
Coding Style introduced by
function cal_from_jd() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
67
		return Shim::calFromJd($julian_day, $calendar_id);
68
	}
69
70
	/**
71
	 * @param integer $calendar_id
72
	 *
73
	 * @return array|boolean
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string[]|in...olean>|boolean>|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
74
	 */
75
	function cal_info($calendar_id = -1) {
0 ignored issues
show
Coding Style introduced by
function cal_info() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
76
		return Shim::calInfo($calendar_id);
77
	}
78
79
	/**
80
	 * @param integer $calendar_id
81
	 * @param integer $month
82
	 * @param integer $day
83
	 * @param integer $year
84
	 *
85
	 * @return integer|boolean
86
	 */
87
	function cal_to_jd($calendar_id, $month, $day, $year) {
0 ignored issues
show
Coding Style introduced by
function cal_to_jd() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
88
		return Shim::calToJd($calendar_id, $month, $day, $year);
89
	}
90
91
	/**
92
	 * @param integer|null $year
93
	 *
94
	 * @return integer|boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
95
	 */
96
	function easter_date($year = null) {
0 ignored issues
show
Coding Style introduced by
function easter_date() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
97
		return Shim::easterDate($year ? $year : (int)date('Y'));
98
	}
99
100
	/**
101
	 * @param integer|null $year
102
	 * @param integer      $method
103
	 *
104
	 * @return integer
105
	 */
106
	function easter_days($year = null, $method = CAL_EASTER_DEFAULT) {
0 ignored issues
show
Coding Style introduced by
function easter_days() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
107
		return Shim::easterDays($year ? $year : (int)date('Y'), $method);
108
	}
109
110
	/**
111
	 * @param integer $month
112
	 * @param integer $day
113
	 * @param integer $year
114
	 *
115
	 * @return integer
116
	 */
117
	function FrenchToJD($month, $day, $year) {
0 ignored issues
show
Coding Style introduced by
function FrenchToJD() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
118
		return Shim::frenchToJd($month, $day, $year);
119
	}
120
121
	/**
122
	 * @param integer $month
123
	 * @param integer $day
124
	 * @param integer $year
125
	 *
126
	 * @return integer
127
	 */
128
	function GregorianToJD($month, $day, $year) {
0 ignored issues
show
Coding Style introduced by
function GregorianToJD() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
129
		return Shim::gregorianToJd($month, $day, $year);
130
	}
131
132
	/**
133
	 * @param integer $julian_day
134
	 * @param integer $mode
135
	 *
136
	 * @return integer|string
137
	 */
138
	function JDDayOfWeek($julian_day, $mode = CAL_DOW_DAYNO) {
0 ignored issues
show
Coding Style introduced by
function JDDayOfWeek() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
139
		return Shim::jdDayOfWeek($julian_day, $mode);
140
	}
141
142
	/**
143
	 * @param integer $julian_day
144
	 * @param integer $mode
145
	 *
146
	 * @return string
147
	 */
148
	function JDMonthName($julian_day, $mode) {
0 ignored issues
show
Coding Style introduced by
function JDMonthName() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
149
		return Shim::jdMonthName($julian_day, $mode);
150
	}
151
152
	/**
153
	 * @param integer $julian_day
154
	 *
155
	 * @return string
156
	 */
157
	function JDToFrench($julian_day) {
0 ignored issues
show
Coding Style introduced by
function JDToFrench() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
158
		return Shim::jdToFrench($julian_day);
159
	}
160
161
	/**
162
	 * @param integer $julian_day
163
	 *
164
	 * @return string
165
	 */
166
	function JDToGregorian($julian_day) {
0 ignored issues
show
Coding Style introduced by
function JDToGregorian() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
167
		return Shim::jdToGregorian($julian_day);
168
	}
169
170
	/**
171
	 * @param integer $julian_day
172
	 * @param boolean $hebrew
173
	 * @param integer $flags
174
	 *
175
	 * @return string|boolean
176
	 */
177
	function jdtojewish($julian_day, $hebrew = false, $flags = 0) {
178
		return Shim::jdToJewish($julian_day, $hebrew, $flags);
179
	}
180
181
	/**
182
	 * @param integer $julian_day
183
	 *
184
	 * @return string
185
	 */
186
	function JDToJulian($julian_day) {
0 ignored issues
show
Coding Style introduced by
function JDToJulian() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
187
		return Shim::jdToJulian($julian_day);
188
	}
189
190
	/**
191
	 * @param integer $julian_day
192
	 *
193
	 * @return integer|false
194
	 */
195
	function jdtounix($julian_day) {
196
		return Shim::jdToUnix($julian_day);
197
	}
198
199
	/**
200
	 * @param integer $month
201
	 * @param integer $day
202
	 * @param integer $year
203
	 *
204
	 * @return integer
205
	 */
206
	function JewishToJD($month, $day, $year) {
0 ignored issues
show
Coding Style introduced by
function JewishToJD() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
207
		return Shim::jewishToJd($month, $day, $year);
208
	}
209
210
	/**
211
	 * @param integer $month
212
	 * @param integer $day
213
	 * @param integer $year
214
	 *
215
	 * @return integer
216
	 */
217
	function JulianToJD($month, $day, $year) {
0 ignored issues
show
Coding Style introduced by
function JulianToJD() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
218
		return Shim::julianToJd($month, $day, $year);
219
	}
220
221
	/**
222
	 * @param integer|null $timestamp
223
	 *
224
	 * @return false|integer
225
	 */
226
	function unixtojd($timestamp = null) {
227
		return Shim::unixToJd($timestamp ? $timestamp : time());
228
	}
229
}
230