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 |
||
9 | class Event extends Model |
||
10 | { |
||
11 | /***************************************************************************/ |
||
12 | /** |
||
13 | * The table associated with the model. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $table = 'events'; |
||
18 | |||
19 | /***************************************************************************/ |
||
20 | |||
21 | protected $fillable = [ |
||
22 | 'title', 'description', 'organized_by', 'category_id', 'venue_id', 'image', 'facebook_event_link', 'website_event_link', 'status', 'repeat_type', 'repeat_until', 'repeat_weekly_on', 'repeat_monthly_on', 'on_monthly_kind', |
||
23 | ]; |
||
24 | |||
25 | /***************************************************************************/ |
||
26 | |||
27 | /** |
||
28 | * Get the teachers for the event. |
||
29 | */ |
||
30 | public function teachers() |
||
34 | |||
35 | /***************************************************************************/ |
||
36 | |||
37 | /** |
||
38 | * Get the organizers for the event. |
||
39 | */ |
||
40 | public function organizers() |
||
44 | |||
45 | /***************************************************************************/ |
||
46 | |||
47 | /** |
||
48 | * Get the organizers for the event. |
||
49 | */ |
||
50 | public function eventRepetitions() |
||
54 | |||
55 | /***************************************************************************/ |
||
56 | |||
57 | /** |
||
58 | * Delete all the previous repetitions from the event_repetitions table. |
||
59 | * |
||
60 | * @param int $eventId |
||
61 | * @return void |
||
62 | */ |
||
63 | public static function deletePreviousRepetitions($eventId) |
||
67 | |||
68 | /***************************************************************************/ |
||
69 | |||
70 | /** |
||
71 | * Return Start and End dates of the first repetition of an event - By Event ID. |
||
72 | * |
||
73 | * @param int $eventId |
||
74 | * @return \App\EventRepetition |
||
75 | */ |
||
76 | public static function getFirstEventRpDatesByEventId($eventId) |
||
85 | |||
86 | /***************************************************************************/ |
||
87 | |||
88 | /** |
||
89 | * Return Start and End dates of the first repetition of an event - By Repetition ID. |
||
90 | * |
||
91 | * @param int $repetitionId |
||
92 | * @return \App\EventRepetition |
||
93 | */ |
||
94 | public static function getFirstEventRpDatesByRepetitionId($repetitionId) |
||
103 | |||
104 | /***************************************************************************/ |
||
105 | |||
106 | /** |
||
107 | * Return the all the active events. |
||
108 | * |
||
109 | * @return \App\Event |
||
110 | */ |
||
111 | public static function getActiveEvents() |
||
132 | |||
133 | /***************************************************************************/ |
||
134 | |||
135 | /** |
||
136 | * Return the active events based on the search keys provided. |
||
137 | * |
||
138 | * @param array $filters |
||
139 | * @param int $itemPerPage |
||
140 | * @return \App\Event |
||
141 | */ |
||
142 | //$keywords, $category, $city, $country, $continent, $teacher, $venue, $startDate, $endDate, |
||
143 | public static function getEvents($filters, $itemPerPage) |
||
203 | |||
204 | /***************************************************************************/ |
||
205 | |||
206 | /** |
||
207 | * Format the start date to be used in the search query. |
||
208 | * If the start date is null return today's date. |
||
209 | * |
||
210 | * @param string $DatePickerStartDate |
||
211 | * @return string |
||
212 | */ |
||
213 | View Code Duplication | public static function prepareStartDate($DatePickerStartDate) |
|
226 | |||
227 | /***************************************************************************/ |
||
228 | |||
229 | /** |
||
230 | * Format the end date to be used in the search query. |
||
231 | * |
||
232 | * @param string $DatePickerEndDate |
||
233 | * @return string |
||
234 | */ |
||
235 | public static function prepareEndDate($DatePickerEndDate) |
||
246 | } |
||
247 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: