Libur::populateHoliday()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
/* 
3
	Author: Irfa Ardiansyah <[email protected]>
4
    version: 1.1
5
    https://github.com/irfaardy/php-hari-libur
6
*/
7
namespace Irfa\HariLibur\Core;
8
9
use Irfa\HariLibur\Core\DateHelpers;
10
11
class Libur extends Localization
12
{
13
	private $holidays;
14
	
15
	protected function getNextHolidays($date)
16
	{
17
		$dt = new DateHelpers();
18
		$this->populateHoliday();
19
20
		return $dt->greaterThanDate($date, $this->holidays);
21
	}
22
23
	protected function getPrevHolidays($date)
24
	{
25
		$dt = new DateHelpers();
26
		$this->populateHoliday();
27
28
		return (object) $dt->lessThanDate($date, $this->holidays);
29
	}
30
31
	protected function checkHoliday($date)
32
	{
33
		$this->populateHoliday();
34
		if (array_key_exists($date, $this->holidays)) {
35
			return true;
36
		} 
37
38
		return false;
39
	}
40
41
	protected function checkWeekend($date)
42
	{
43
		$dt = new DateHelpers();
44
45
		$days = ['Saturday','Sunday'];
46
		$day = $dt->convertToDayName($date);
47
		if(in_array($day, $days))
48
		{
49
			return true;
50
		}
51
52
		return false;
53
54
	}
55
56
	protected function setRegion($region)
57
	{
58
		$this->regionSet($region);
59
	}
60
61
	protected function checkOffDay($date)
62
	{
63
		if($this->checkHoliday($date) || $this->checkWeekend($date))
64
		{
65
			return true;
66
		} 
67
68
		return false;
69
	}
70
	protected function gettingInfo($date)
71
	{
72
		$this->populateHoliday();
73
		if(array_key_exists($date, $this->holidays))
74
		{
75
			return $this->holidays[$date];
76
		} 
77
78
		return null;
79
	}
80
	private function populateHoliday()
81
	{
82
		$get_holidays = $this->fetchHolidays();
83
		foreach($get_holidays as $h)
84
		{
85
			$this->holidays[$h->date] = $h->description;
86
		}
87
	}
88
89
	protected function fetchHolidays()
90
	{
91
		return $this->holidayData(false)->holidays;
0 ignored issues
show
Bug introduced by
The property holidays does not exist on boolean.
Loading history...
92
	}
93
94
}
95