Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php namespace OpenCafe; |
||
16 | class Datium { |
||
17 | |||
18 | /** |
||
19 | * Store DateTime object |
||
20 | */ |
||
21 | protected $date_time; |
||
22 | |||
23 | protected static $static_date_time; |
||
24 | |||
25 | /** |
||
26 | * Store config file statements |
||
27 | * @param array |
||
28 | */ |
||
29 | protected $config; |
||
30 | |||
31 | protected $date_interval_expression; |
||
32 | |||
33 | protected static $date_start; |
||
34 | |||
35 | protected static $date_end; |
||
36 | |||
37 | protected $translate_from; |
||
38 | |||
39 | protected $translate_to; |
||
40 | |||
41 | protected $toConfig; |
||
42 | |||
43 | protected $fromConfig; |
||
44 | |||
45 | /** |
||
46 | * return store day number |
||
47 | * @param integer |
||
48 | */ |
||
49 | protected $day_of; |
||
50 | |||
51 | protected $leap; |
||
52 | |||
53 | protected $events; |
||
54 | |||
55 | protected $translate; |
||
56 | |||
57 | protected $geregorian_DayofWeek; |
||
58 | |||
59 | protected $convert_calendar; |
||
60 | |||
61 | protected $calendar_type; |
||
62 | |||
63 | protected static $array_date; |
||
64 | |||
65 | protected static $call_type; |
||
66 | |||
67 | protected $translate_from_file; |
||
68 | |||
69 | protected $translate_to_file; |
||
70 | |||
71 | protected $language; |
||
72 | |||
73 | public function __construct() { |
||
122 | |||
123 | /************************************************************ |
||
124 | * return all datetime parts as an object |
||
125 | ************************************************************ |
||
126 | * |
||
127 | * @return object |
||
128 | * |
||
129 | */ |
||
130 | public function all() { |
||
149 | |||
150 | /** |
||
151 | * Get current datetime |
||
152 | * @since Aug 17 2015 |
||
153 | * @return object |
||
154 | */ |
||
155 | public static function now() { |
||
162 | |||
163 | /** |
||
164 | * Create new date time |
||
165 | * @param $year integer |
||
166 | * @param $month integer |
||
167 | * @param $day integer |
||
168 | * @param $hour integer |
||
169 | * @param $minute integer |
||
170 | * @param $second integer |
||
171 | * @return object |
||
172 | */ |
||
173 | public static function create( $year = 2000, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0 ) { |
||
195 | |||
196 | public static function between( $date_start, $date_end ) { |
||
207 | |||
208 | /** |
||
209 | * Convert from current calendar, what type is current calendar? |
||
210 | */ |
||
211 | View Code Duplication | public function from( $calendar ) { |
|
228 | |||
229 | View Code Duplication | public function to( $calendar ) { |
|
245 | |||
246 | |||
247 | /** |
||
248 | * Difference between two time |
||
249 | * @param $start datetime |
||
250 | * @param $end datetime |
||
251 | */ |
||
252 | public static function diff( $start, $end ) { |
||
257 | |||
258 | /** |
||
259 | * Add new date value to current date |
||
260 | * @param $value string |
||
261 | * @return object |
||
262 | */ |
||
263 | View Code Duplication | public function add( $value ) { |
|
274 | |||
275 | /** |
||
276 | * Sub date from current date |
||
277 | * @param $value |
||
278 | * @return obejct |
||
279 | */ |
||
280 | View Code Duplication | public function sub( $value ) { |
|
291 | |||
292 | /** |
||
293 | * Check if current year is leap or not |
||
294 | * @return boolean |
||
295 | */ |
||
296 | public function leap( $type = 'gregorian') { |
||
303 | |||
304 | /** |
||
305 | * @since Aug, 22 2015 |
||
306 | */ |
||
307 | public function dayOf() { |
||
314 | |||
315 | /** |
||
316 | * @since Sept, 7 2015 |
||
317 | */ |
||
318 | public function events() { |
||
333 | |||
334 | /************************************************************ |
||
335 | * Return Datetime as a original object |
||
336 | ************************************************************ |
||
337 | * |
||
338 | * @since Oct 22, 2015 |
||
339 | * @return object |
||
340 | * |
||
341 | *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |
||
342 | */ |
||
343 | public function object(){ |
||
348 | |||
349 | public function lang( $language = 'fa' ){ |
||
362 | |||
363 | /** |
||
364 | * Get output |
||
365 | * @since Aug 17 2015 |
||
366 | * @param $calendar string |
||
367 | * @param $format string |
||
368 | */ |
||
369 | public function get( $format = 'Y-m-d H:i:s' ) { |
||
415 | |||
416 | } |
||
417 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.