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 |
||
80 | |||
81 | /** |
||
82 | * @param string $eventId |
||
83 | * @return static |
||
84 | */ |
||
85 | public function getEvent($eventId) |
||
91 | |||
92 | /** |
||
93 | * Insert an event |
||
94 | * |
||
95 | * @param \Spatie\GoogleCalendar\Event|Google_Service_Calendar_Event $event |
||
96 | * |
||
97 | * @link https://developers.google.com/google-apps/calendar/v3/reference/events/insert |
||
98 | * |
||
99 | * @return mixed |
||
100 | */ |
||
101 | View Code Duplication | public function insertEvent($event) |
|
109 | |||
110 | /** |
||
111 | * @param \Spatie\GoogleCalendar\Event|Google_Service_Calendar_Event $event |
||
112 | * |
||
113 | * @return \Google_Service_Calendar_Event |
||
114 | */ |
||
115 | View Code Duplication | public function updateEvent($event) |
|
123 | |||
124 | /** |
||
125 | * @param string|\Spatie\GoogleCalendar\Event $eventId |
||
126 | */ |
||
127 | View Code Duplication | public function deleteEvent($eventId) |
|
135 | |||
136 | public function getService() : Google_Service_Calendar |
||
140 | } |
||
141 |
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..