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 |
||
20 | View Code Duplication | class FoodEstablishmentReservation extends BaseType implements FoodEstablishmentReservationContract, IntangibleContract, ReservationContract, ThingContract |
|
|
|||
21 | { |
||
22 | /** |
||
23 | * An additional type for the item, typically used for adding more specific |
||
24 | * types from external vocabularies in microdata syntax. This is a |
||
25 | * relationship between something and a class that the thing is in. In RDFa |
||
26 | * syntax, it is better to use the native RDFa syntax - the 'typeof' |
||
27 | * attribute - for multiple types. Schema.org tools may have only weaker |
||
28 | * understanding of extra types, in particular those defined externally. |
||
29 | * |
||
30 | * @param string|string[] $additionalType |
||
31 | * |
||
32 | * @return static |
||
33 | * |
||
34 | * @see http://schema.org/additionalType |
||
35 | */ |
||
36 | public function additionalType($additionalType) |
||
40 | |||
41 | /** |
||
42 | * An alias for the item. |
||
43 | * |
||
44 | * @param string|string[] $alternateName |
||
45 | * |
||
46 | * @return static |
||
47 | * |
||
48 | * @see http://schema.org/alternateName |
||
49 | */ |
||
50 | public function alternateName($alternateName) |
||
54 | |||
55 | /** |
||
56 | * 'bookingAgent' is an out-dated term indicating a 'broker' that serves as |
||
57 | * a booking agent. |
||
58 | * |
||
59 | * @param \Spatie\SchemaOrg\Contracts\OrganizationContract|\Spatie\SchemaOrg\Contracts\OrganizationContract[]|\Spatie\SchemaOrg\Contracts\PersonContract|\Spatie\SchemaOrg\Contracts\PersonContract[] $bookingAgent |
||
60 | * |
||
61 | * @return static |
||
62 | * |
||
63 | * @see http://schema.org/bookingAgent |
||
64 | */ |
||
65 | public function bookingAgent($bookingAgent) |
||
69 | |||
70 | /** |
||
71 | * The date and time the reservation was booked. |
||
72 | * |
||
73 | * @param \DateTimeInterface|\DateTimeInterface[] $bookingTime |
||
74 | * |
||
75 | * @return static |
||
76 | * |
||
77 | * @see http://schema.org/bookingTime |
||
78 | */ |
||
79 | public function bookingTime($bookingTime) |
||
83 | |||
84 | /** |
||
85 | * An entity that arranges for an exchange between a buyer and a seller. In |
||
86 | * most cases a broker never acquires or releases ownership of a product or |
||
87 | * service involved in an exchange. If it is not clear whether an entity is |
||
88 | * a broker, seller, or buyer, the latter two terms are preferred. |
||
89 | * |
||
90 | * @param \Spatie\SchemaOrg\Contracts\OrganizationContract|\Spatie\SchemaOrg\Contracts\OrganizationContract[]|\Spatie\SchemaOrg\Contracts\PersonContract|\Spatie\SchemaOrg\Contracts\PersonContract[] $broker |
||
91 | * |
||
92 | * @return static |
||
93 | * |
||
94 | * @see http://schema.org/broker |
||
95 | */ |
||
96 | public function broker($broker) |
||
100 | |||
101 | /** |
||
102 | * A description of the item. |
||
103 | * |
||
104 | * @param string|string[] $description |
||
105 | * |
||
106 | * @return static |
||
107 | * |
||
108 | * @see http://schema.org/description |
||
109 | */ |
||
110 | public function description($description) |
||
114 | |||
115 | /** |
||
116 | * A sub property of description. A short description of the item used to |
||
117 | * disambiguate from other, similar items. Information from other properties |
||
118 | * (in particular, name) may be necessary for the description to be useful |
||
119 | * for disambiguation. |
||
120 | * |
||
121 | * @param string|string[] $disambiguatingDescription |
||
122 | * |
||
123 | * @return static |
||
124 | * |
||
125 | * @see http://schema.org/disambiguatingDescription |
||
126 | */ |
||
127 | public function disambiguatingDescription($disambiguatingDescription) |
||
131 | |||
132 | /** |
||
133 | * The endTime of something. For a reserved event or service (e.g. |
||
134 | * FoodEstablishmentReservation), the time that it is expected to end. For |
||
135 | * actions that span a period of time, when the action was performed. e.g. |
||
136 | * John wrote a book from January to *December*. For media, including audio |
||
137 | * and video, it's the time offset of the end of a clip within a larger |
||
138 | * file. |
||
139 | * |
||
140 | * Note that Event uses startDate/endDate instead of startTime/endTime, even |
||
141 | * when describing dates with times. This situation may be clarified in |
||
142 | * future revisions. |
||
143 | * |
||
144 | * @param \DateTimeInterface|\DateTimeInterface[] $endTime |
||
145 | * |
||
146 | * @return static |
||
147 | * |
||
148 | * @see http://schema.org/endTime |
||
149 | */ |
||
150 | public function endTime($endTime) |
||
154 | |||
155 | /** |
||
156 | * The identifier property represents any kind of identifier for any kind of |
||
157 | * [[Thing]], such as ISBNs, GTIN codes, UUIDs etc. Schema.org provides |
||
158 | * dedicated properties for representing many of these, either as textual |
||
159 | * strings or as URL (URI) links. See [background |
||
160 | * notes](/docs/datamodel.html#identifierBg) for more details. |
||
161 | * |
||
162 | * @param \Spatie\SchemaOrg\Contracts\PropertyValueContract|\Spatie\SchemaOrg\Contracts\PropertyValueContract[]|string|string[] $identifier |
||
163 | * |
||
164 | * @return static |
||
165 | * |
||
166 | * @see http://schema.org/identifier |
||
167 | */ |
||
168 | public function identifier($identifier) |
||
172 | |||
173 | /** |
||
174 | * An image of the item. This can be a [[URL]] or a fully described |
||
175 | * [[ImageObject]]. |
||
176 | * |
||
177 | * @param \Spatie\SchemaOrg\Contracts\ImageObjectContract|\Spatie\SchemaOrg\Contracts\ImageObjectContract[]|string|string[] $image |
||
178 | * |
||
179 | * @return static |
||
180 | * |
||
181 | * @see http://schema.org/image |
||
182 | */ |
||
183 | public function image($image) |
||
187 | |||
188 | /** |
||
189 | * Indicates a page (or other CreativeWork) for which this thing is the main |
||
190 | * entity being described. See [background |
||
191 | * notes](/docs/datamodel.html#mainEntityBackground) for details. |
||
192 | * |
||
193 | * @param \Spatie\SchemaOrg\Contracts\CreativeWorkContract|\Spatie\SchemaOrg\Contracts\CreativeWorkContract[]|string|string[] $mainEntityOfPage |
||
194 | * |
||
195 | * @return static |
||
196 | * |
||
197 | * @see http://schema.org/mainEntityOfPage |
||
198 | */ |
||
199 | public function mainEntityOfPage($mainEntityOfPage) |
||
203 | |||
204 | /** |
||
205 | * The date and time the reservation was modified. |
||
206 | * |
||
207 | * @param \DateTimeInterface|\DateTimeInterface[] $modifiedTime |
||
208 | * |
||
209 | * @return static |
||
210 | * |
||
211 | * @see http://schema.org/modifiedTime |
||
212 | */ |
||
213 | public function modifiedTime($modifiedTime) |
||
217 | |||
218 | /** |
||
219 | * The name of the item. |
||
220 | * |
||
221 | * @param string|string[] $name |
||
222 | * |
||
223 | * @return static |
||
224 | * |
||
225 | * @see http://schema.org/name |
||
226 | */ |
||
227 | public function name($name) |
||
231 | |||
232 | /** |
||
233 | * Number of people the reservation should accommodate. |
||
234 | * |
||
235 | * @param \Spatie\SchemaOrg\Contracts\QuantitativeValueContract|\Spatie\SchemaOrg\Contracts\QuantitativeValueContract[]|int|int[] $partySize |
||
236 | * |
||
237 | * @return static |
||
238 | * |
||
239 | * @see http://schema.org/partySize |
||
240 | */ |
||
241 | public function partySize($partySize) |
||
245 | |||
246 | /** |
||
247 | * Indicates a potential Action, which describes an idealized action in |
||
248 | * which this thing would play an 'object' role. |
||
249 | * |
||
250 | * @param \Spatie\SchemaOrg\Contracts\ActionContract|\Spatie\SchemaOrg\Contracts\ActionContract[] $potentialAction |
||
251 | * |
||
252 | * @return static |
||
253 | * |
||
254 | * @see http://schema.org/potentialAction |
||
255 | */ |
||
256 | public function potentialAction($potentialAction) |
||
260 | |||
261 | /** |
||
262 | * The currency of the price, or a price component when attached to |
||
263 | * [[PriceSpecification]] and its subtypes. |
||
264 | * |
||
265 | * Use standard formats: [ISO 4217 currency |
||
266 | * format](http://en.wikipedia.org/wiki/ISO_4217) e.g. "USD"; [Ticker |
||
267 | * symbol](https://en.wikipedia.org/wiki/List_of_cryptocurrencies) for |
||
268 | * cryptocurrencies e.g. "BTC"; well known names for [Local Exchange |
||
269 | * Tradings |
||
270 | * Systems](https://en.wikipedia.org/wiki/Local_exchange_trading_system) |
||
271 | * (LETS) and other currency types e.g. "Ithaca HOUR". |
||
272 | * |
||
273 | * @param string|string[] $priceCurrency |
||
274 | * |
||
275 | * @return static |
||
276 | * |
||
277 | * @see http://schema.org/priceCurrency |
||
278 | */ |
||
279 | public function priceCurrency($priceCurrency) |
||
283 | |||
284 | /** |
||
285 | * Any membership in a frequent flyer, hotel loyalty program, etc. being |
||
286 | * applied to the reservation. |
||
287 | * |
||
288 | * @param \Spatie\SchemaOrg\Contracts\ProgramMembershipContract|\Spatie\SchemaOrg\Contracts\ProgramMembershipContract[] $programMembershipUsed |
||
289 | * |
||
290 | * @return static |
||
291 | * |
||
292 | * @see http://schema.org/programMembershipUsed |
||
293 | */ |
||
294 | public function programMembershipUsed($programMembershipUsed) |
||
298 | |||
299 | /** |
||
300 | * The service provider, service operator, or service performer; the goods |
||
301 | * producer. Another party (a seller) may offer those services or goods on |
||
302 | * behalf of the provider. A provider may also serve as the seller. |
||
303 | * |
||
304 | * @param \Spatie\SchemaOrg\Contracts\OrganizationContract|\Spatie\SchemaOrg\Contracts\OrganizationContract[]|\Spatie\SchemaOrg\Contracts\PersonContract|\Spatie\SchemaOrg\Contracts\PersonContract[] $provider |
||
305 | * |
||
306 | * @return static |
||
307 | * |
||
308 | * @see http://schema.org/provider |
||
309 | */ |
||
310 | public function provider($provider) |
||
314 | |||
315 | /** |
||
316 | * The thing -- flight, event, restaurant,etc. being reserved. |
||
317 | * |
||
318 | * @param \Spatie\SchemaOrg\Contracts\ThingContract|\Spatie\SchemaOrg\Contracts\ThingContract[] $reservationFor |
||
319 | * |
||
320 | * @return static |
||
321 | * |
||
322 | * @see http://schema.org/reservationFor |
||
323 | */ |
||
324 | public function reservationFor($reservationFor) |
||
328 | |||
329 | /** |
||
330 | * A unique identifier for the reservation. |
||
331 | * |
||
332 | * @param string|string[] $reservationId |
||
333 | * |
||
334 | * @return static |
||
335 | * |
||
336 | * @see http://schema.org/reservationId |
||
337 | */ |
||
338 | public function reservationId($reservationId) |
||
342 | |||
343 | /** |
||
344 | * The current status of the reservation. |
||
345 | * |
||
346 | * @param \Spatie\SchemaOrg\Contracts\ReservationStatusTypeContract|\Spatie\SchemaOrg\Contracts\ReservationStatusTypeContract[] $reservationStatus |
||
347 | * |
||
348 | * @return static |
||
349 | * |
||
350 | * @see http://schema.org/reservationStatus |
||
351 | */ |
||
352 | public function reservationStatus($reservationStatus) |
||
356 | |||
357 | /** |
||
358 | * A ticket associated with the reservation. |
||
359 | * |
||
360 | * @param \Spatie\SchemaOrg\Contracts\TicketContract|\Spatie\SchemaOrg\Contracts\TicketContract[] $reservedTicket |
||
361 | * |
||
362 | * @return static |
||
363 | * |
||
364 | * @see http://schema.org/reservedTicket |
||
365 | */ |
||
366 | public function reservedTicket($reservedTicket) |
||
370 | |||
371 | /** |
||
372 | * URL of a reference Web page that unambiguously indicates the item's |
||
373 | * identity. E.g. the URL of the item's Wikipedia page, Wikidata entry, or |
||
374 | * official website. |
||
375 | * |
||
376 | * @param string|string[] $sameAs |
||
377 | * |
||
378 | * @return static |
||
379 | * |
||
380 | * @see http://schema.org/sameAs |
||
381 | */ |
||
382 | public function sameAs($sameAs) |
||
386 | |||
387 | /** |
||
388 | * The startTime of something. For a reserved event or service (e.g. |
||
389 | * FoodEstablishmentReservation), the time that it is expected to start. For |
||
390 | * actions that span a period of time, when the action was performed. e.g. |
||
391 | * John wrote a book from *January* to December. For media, including audio |
||
392 | * and video, it's the time offset of the start of a clip within a larger |
||
393 | * file. |
||
394 | * |
||
395 | * Note that Event uses startDate/endDate instead of startTime/endTime, even |
||
396 | * when describing dates with times. This situation may be clarified in |
||
397 | * future revisions. |
||
398 | * |
||
399 | * @param \DateTimeInterface|\DateTimeInterface[] $startTime |
||
400 | * |
||
401 | * @return static |
||
402 | * |
||
403 | * @see http://schema.org/startTime |
||
404 | */ |
||
405 | public function startTime($startTime) |
||
409 | |||
410 | /** |
||
411 | * A CreativeWork or Event about this Thing. |
||
412 | * |
||
413 | * @param \Spatie\SchemaOrg\Contracts\CreativeWorkContract|\Spatie\SchemaOrg\Contracts\CreativeWorkContract[]|\Spatie\SchemaOrg\Contracts\EventContract|\Spatie\SchemaOrg\Contracts\EventContract[] $subjectOf |
||
414 | * |
||
415 | * @return static |
||
416 | * |
||
417 | * @see http://schema.org/subjectOf |
||
418 | */ |
||
419 | public function subjectOf($subjectOf) |
||
423 | |||
424 | /** |
||
425 | * The total price for the reservation or ticket, including applicable |
||
426 | * taxes, shipping, etc. |
||
427 | * |
||
428 | * Usage guidelines: |
||
429 | * |
||
430 | * * Use values from 0123456789 (Unicode 'DIGIT ZERO' (U+0030) to 'DIGIT |
||
431 | * NINE' (U+0039)) rather than superficially similiar Unicode symbols. |
||
432 | * * Use '.' (Unicode 'FULL STOP' (U+002E)) rather than ',' to indicate a |
||
433 | * decimal point. Avoid using these symbols as a readability separator. |
||
434 | * |
||
435 | * @param \Spatie\SchemaOrg\Contracts\PriceSpecificationContract|\Spatie\SchemaOrg\Contracts\PriceSpecificationContract[]|float|float[]|int|int[]|string|string[] $totalPrice |
||
436 | * |
||
437 | * @return static |
||
438 | * |
||
439 | * @see http://schema.org/totalPrice |
||
440 | */ |
||
441 | public function totalPrice($totalPrice) |
||
445 | |||
446 | /** |
||
447 | * The person or organization the reservation or ticket is for. |
||
448 | * |
||
449 | * @param \Spatie\SchemaOrg\Contracts\OrganizationContract|\Spatie\SchemaOrg\Contracts\OrganizationContract[]|\Spatie\SchemaOrg\Contracts\PersonContract|\Spatie\SchemaOrg\Contracts\PersonContract[] $underName |
||
450 | * |
||
451 | * @return static |
||
452 | * |
||
453 | * @see http://schema.org/underName |
||
454 | */ |
||
455 | public function underName($underName) |
||
459 | |||
460 | /** |
||
461 | * URL of the item. |
||
462 | * |
||
463 | * @param string|string[] $url |
||
464 | * |
||
465 | * @return static |
||
466 | * |
||
467 | * @see http://schema.org/url |
||
468 | */ |
||
469 | public function url($url) |
||
473 | |||
474 | } |
||
475 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.