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 |
||
11 | class GoogleCalendar |
||
12 | { |
||
13 | /** @var \Spatie\GoogleCalendar\Google_Service_Calendar */ |
||
14 | protected $calendarService; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $calendarId; |
||
18 | |||
19 | public function __construct(Google_Service_Calendar $calendarService, $calendarId) |
||
25 | |||
26 | public function getCalendarId() : string |
||
30 | |||
31 | /** |
||
32 | * List events. |
||
33 | * |
||
34 | * @param Carbon $startDateTime |
||
35 | * @param Carbon $endDateTime |
||
36 | * @param array $queryParameters |
||
37 | * |
||
38 | * @link https://developers.google.com/google-apps/calendar/v3/reference/events/list |
||
39 | * |
||
40 | * @return Collection |
||
41 | */ |
||
42 | public function listEvents(Carbon $startDateTime = null, Carbon $endDateTime = null, $queryParameters = []) : Collection |
||
81 | |||
82 | /** |
||
83 | * @param string $eventId |
||
84 | * |
||
85 | * @return static |
||
86 | */ |
||
87 | public function getEvent($eventId) |
||
93 | |||
94 | /** |
||
95 | * Insert an event. |
||
96 | * |
||
97 | * @param \Spatie\GoogleCalendar\Event|Google_Service_Calendar_Event $event |
||
98 | * |
||
99 | * @link https://developers.google.com/google-apps/calendar/v3/reference/events/insert |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | View Code Duplication | public function insertEvent($event) |
|
111 | |||
112 | /** |
||
113 | * @param \Spatie\GoogleCalendar\Event|Google_Service_Calendar_Event $event |
||
114 | * |
||
115 | * @return \Google_Service_Calendar_Event |
||
116 | */ |
||
117 | View Code Duplication | public function updateEvent($event) |
|
125 | |||
126 | /** |
||
127 | * @param string|\Spatie\GoogleCalendar\Event $eventId |
||
128 | */ |
||
129 | public function deleteEvent($eventId) |
||
137 | |||
138 | public function getService() : Google_Service_Calendar |
||
142 | } |
||
143 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..