Conditions | 11 |
Paths | 6 |
Total Lines | 57 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
111 | public function get_events() { |
||
112 | |||
113 | $ids = $this->calendars_ids; |
||
114 | $events = get_transient( '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type ); |
||
115 | |||
116 | if ( empty( $events ) && ! empty( $ids ) && is_array( $ids ) ) { |
||
117 | |||
118 | $events = array(); |
||
119 | |||
120 | foreach ( $ids as $cal_id ) { |
||
121 | |||
122 | $calendar = simcal_get_calendar( intval( $cal_id ) ); |
||
123 | |||
124 | simcal_delete_feed_transients( $cal_id ); |
||
125 | |||
126 | if ( $calendar instanceof Calendar ) { |
||
127 | |||
128 | // Sometimes the calendars might have events at the same time from different calendars |
||
129 | // When merging the arrays together some of the events will be lost because the keys are the same and one will overwrite the other |
||
130 | // This snippet checks if the key already exists in the master events array and if it does it subtracts 1 from it to make the key unique and then unsets the original key. |
||
131 | foreach( $calendar->events as $k => $v ) { |
||
132 | $calendar->events[ $this->update_array_timestamp( $events, $k ) ] = $v; |
||
133 | } |
||
134 | |||
135 | $events = is_array( $calendar->events ) ? $events + $calendar->events : $events; |
||
136 | } |
||
137 | |||
138 | } |
||
139 | |||
140 | if ( ! empty( $events ) ) { |
||
141 | |||
142 | // Trim events to set the earliest one as specified in feed settings. |
||
143 | $earliest_event = intval( $this->time_min ); |
||
144 | if ( $earliest_event > 0 ) { |
||
145 | $events = $this->array_filter_key( $events, array( $this, 'filter_events_before' ) ); |
||
146 | } |
||
147 | |||
148 | // Trim events to set the latest one as specified in feed settings. |
||
149 | $latest_event = intval( $this->time_max ); |
||
150 | if ( $latest_event > 0 ) { |
||
151 | $events = $this->array_filter_key( $events, array( $this, 'filter_events_after' ) ); |
||
152 | } |
||
153 | |||
154 | set_transient( |
||
155 | '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type, |
||
156 | $events, |
||
157 | absint( $this->cache ) |
||
158 | ); |
||
159 | } |
||
160 | |||
161 | } |
||
162 | |||
163 | // Sort events by start time before returning |
||
164 | uasort( $events, array( $this, 'sort_by_start_time' ) ); |
||
165 | |||
166 | return $events; |
||
167 | } |
||
168 | |||
250 |