opencafe /
datium
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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; |
||
| 26 | |||
| 27 | private static $date_end; |
||
| 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; |
||
| 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" ) { |
||
| 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
|
|||
| 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 |
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.