1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ZodiacSign (https://github.com/whatsma/ZodiacSign) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/whatsma/ZodiacSign |
6
|
|
|
* @license MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace Whatsma\ZodiacSign; |
9
|
|
|
|
10
|
|
|
class Calculator |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @access public |
14
|
|
|
* @param int $day day of the month, a number between 1 and 31 |
15
|
|
|
* @param int $month month of the year, a number between 1 and 12 |
16
|
|
|
* @return string the zodiac sign, in lower case. |
17
|
|
|
* @throws InvalidDayException input day is invalid |
18
|
|
|
* @throws InvalidMonthException input month is invalid |
19
|
|
|
*/ |
20
|
|
|
public function calculate($day, $month) |
21
|
|
|
{ |
22
|
|
|
// check month is valid |
23
|
|
|
if (!isset($this->MONTHS[$month])) { |
24
|
|
|
throw new InvalidMonthException; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// check day is valid |
28
|
|
|
if (($day < 1) || ($day > $this->MONTHS[$month]['days_in_month'])) { |
29
|
|
|
throw new InvalidDayException; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// return first or second sign |
33
|
|
|
if ($day <= $this->MONTHS[$month]['split_day']) { |
34
|
|
|
return $this->MONTHS[$month]['first_sign'] ; |
35
|
|
|
} else { |
36
|
|
|
return $this->MONTHS[$month]['second_sign']; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
private $MONTHS = array( |
43
|
|
|
1 => array('name' => 'january', |
44
|
|
|
'split_day' => 20, |
45
|
|
|
'first_sign' => 'capricorn', |
46
|
|
|
'second_sign' => 'aquarius', |
47
|
|
|
'days_in_month' => 31), |
48
|
|
|
2 => array('name' => 'february', |
49
|
|
|
'split_day' => 19, |
50
|
|
|
'first_sign' => 'aquarius', |
51
|
|
|
'second_sign' => 'pisces', |
52
|
|
|
'days_in_month' => 29), |
53
|
|
|
3 => array('name' => 'march', |
54
|
|
|
'split_day' => 20, |
55
|
|
|
'first_sign' => 'pisces', |
56
|
|
|
'second_sign' => 'aries', |
57
|
|
|
'days_in_month' => 31), |
58
|
|
|
4 => array('name' => 'april', |
59
|
|
|
'split_day' => 20, |
60
|
|
|
'first_sign' => 'aries', |
61
|
|
|
'second_sign' => 'taurus', |
62
|
|
|
'days_in_month' => 30), |
63
|
|
|
5 => array('name' => 'may', |
64
|
|
|
'split_day' => 21, |
65
|
|
|
'first_sign' => 'taurus', |
66
|
|
|
'second_sign' => 'gemini', |
67
|
|
|
'days_in_month' => 31), |
68
|
|
|
6 => array('name' => 'june', |
69
|
|
|
'split_day' => 21, |
70
|
|
|
'first_sign' => 'gemini', |
71
|
|
|
'second_sign' => 'cancer', |
72
|
|
|
'days_in_month' => 30), |
73
|
|
|
7 => array('name' => 'july', |
74
|
|
|
'split_day' => 22, |
75
|
|
|
'first_sign' => 'cancer', |
76
|
|
|
'second_sign' => 'leo', |
77
|
|
|
'days_in_month' => 31), |
78
|
|
|
8 => array('name' => 'august', |
79
|
|
|
'split_day' => 22, |
80
|
|
|
'first_sign' => 'leo', |
81
|
|
|
'second_sign' => 'virgo', |
82
|
|
|
'days_in_month' => 31), |
83
|
|
|
9 => array('name' => 'september', |
84
|
|
|
'split_day' => 23, |
85
|
|
|
'first_sign' => 'virgo', |
86
|
|
|
'second_sign' => 'libra', |
87
|
|
|
'days_in_month' => 30), |
88
|
|
|
10 => array('name' => 'october', |
89
|
|
|
'split_day' => 23, |
90
|
|
|
'first_sign' => 'libra', |
91
|
|
|
'second_sign' => 'scorpio', |
92
|
|
|
'days_in_month' => 31), |
93
|
|
|
11 => array('name' => 'november', |
94
|
|
|
'split_day' => 22, |
95
|
|
|
'first_sign' => 'scorpio', |
96
|
|
|
'second_sign' => 'sagittarius', |
97
|
|
|
'days_in_month' => 30), |
98
|
|
|
12 => array('name' => 'december', |
99
|
|
|
'split_day' => 21, |
100
|
|
|
'first_sign' => 'sagittarius', |
101
|
|
|
'second_sign' => 'capricorn', |
102
|
|
|
'days_in_month' => 31)); |
103
|
|
|
} |
104
|
|
|
|