Completed
Push — master ( d5f8b0...0fe70c )
by mehdi
02:20
created

Events::weekend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 2 Features 1
Metric Value
c 4
b 2
f 1
dl 0
loc 5
rs 9.4286
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Datium;
2
3
use Datium\Tools\Convert;
4
use Datium\Tools\DayOf;
5
use DateTime;
6
use DateInterval;
7
use DatePeriod;
8
9
class Events {
10
11
	private $local;
12
13
	private $events;
14
15
	private $date_time;
16
17
	private $convert;
18
19
	private $result;
20
21
	private $period;
22
23
	private $interval;
24
25
	private static $date_start;
0 ignored issues
show
Unused Code introduced by
The property $date_start is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
27
	private static $date_end;
0 ignored issues
show
Unused Code introduced by
The property $date_end is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
28
29
	public function __construct( $date_time, $date_end = NULL ) {
30
31
		if( $date_end !== NULL ) {
32
33
			Events::$date_start = $date_time;
34
35
			Events::$date_end = $date_end;
36
37
		} else {
38
39
			Events::$date_start = $date_time;
40
41
		}
42
43
		$this->convert = new Convert;
44
45
		$this->date_time = new DateTime();
46
47
		return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
48
49
	}
50
51
	/************************************************************
52
	 * Fetch Events array from own array file
53
	 ************************************************************
54
	 *
55
	 * @since Oct 25, 2015
56
	 *
57
	 *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
58
	 */
59
	private function fetch( $path ) {
60
61
		$this->events = include( $path );
62
63
		$this->interval = DateInterval::createFromDateString('1 day');
64
65
		$this->period = new DatePeriod( Events::$date_start, $this->interval, Events::$date_end );
66
67
		foreach ( $this->period as $dt ) {
68
69
			if ( isset( $this->events[ 'events' ][ intval( $dt->format('m') ) ][ intval( $dt->format('d') ) ] ) ) {
70
71
				$this->result[ $dt->format( 'Y-m-d' ) ][] = $this->events[ 'events' ][ intval( $dt->format('m') ) ][ intval( $dt->format('d') ) ];
72
73
			}
74
75
		}
76
77
	}
78
79
	/************************************************************
80
	 * Return Array of Events
81
	 ************************************************************
82
	 *
83
	 * @since Oct 18, 2015
84
	 * @return array
85
	 *
86
	 *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
87
	 */
88
	public function get() {
89
90
		if( ! empty( $this->result ) ) {
91
92
			foreach( $this->result as $key => $day ) {
93
94
				if ( ! ( $key > Events::$date_start->format( 'Y-m-d' ) && $key < Events::$date_end->format( 'Y-m-d' ) ) ) {
95
96
					unset( $this->result[ $key ] );
97
98
				}
99
100
			}
101
102
		} else {
103
104
			$this->result = array();
105
106
		}
107
108
		return $this->result;
109
110
	}
111
112
		/************************************************************
113
		 * Return local events - with day start and end as an array
114
		 ************************************************************
115
		 *
116
		 * @since Oct 10, 2015
117
		 * @param string $country_code
118
		 *
119
		 *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
120
		 */
121
		public function local( $country_code = "ir" ) {
0 ignored issues
show
Unused Code introduced by
The parameter $country_code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
123
				/*
124
				 * Capitalize the first character of $country_code according the file
125
				 * structure.
126
				 */
127
				$country_code = strtolower( $country_code = 'ir' ) ;
128
129
				$this->local = include( 'Localization/' . $country_code . '.php' );
130
131
				foreach( $this->local[ 'events' ] as $month => $events ) {
132
133
					foreach( $events as $day => $event ){
134
135
						$this->date_time = new DateTime();
136
137
						$this->date_time->setDate( Events::$date_start->format( 'Y' ), $month, $day );
138
139
						switch ( $this->local[ 'default_calendar' ] ) {
140
141
							case 'shamsi':
142
143
							$this->date_time->setDate( 1394, $month, $day );
144
145
							$this->date_time = Datium::create( $this->date_time )->from( 'shamsi' )->to( 'gregorian' )->object(); //$this->convert->shamsiToGregorian( $this->date_time );
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
147
							break;
148
149
							case 'ghamari':
150
151
								$this->date_time = Datium::create(  $this->date_time )->from( 'ghamari' )->to( 'gregorian' )->object(); // $this->convert->ghamariToGregorian( $this->date_time );
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
152
153
							break;
154
155
						}
156
157
						$this->result[ $this->date_time->format( 'Y-m-d' ) ][] =  $event;
158
159
					}
160
161
				}
162
163
				ksort( $this->result );
164
165
		return $this;
166
167
	}
168
169
	public function weekend() {
170
171
		return 0;
172
173
	}
174
175
	public function relagious() {
176
177
		return 0;
178
179
	}
180
181
	public function international() {
182
183
		$this->fetch( 'Global/global.php' );
184
185
		return $this;
186
187
	}
188
189
}
190