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 |
||
16 | class URLChooserLinkTypeSubscriber implements EventSubscriberInterface |
||
17 | { |
||
18 | /** |
||
19 | * @return array |
||
|
|||
20 | */ |
||
21 | public static function getSubscribedEvents() |
||
27 | |||
28 | /** |
||
29 | * When changing the link type, the form get's submitted with an ajax callback in the url_chooser.js; |
||
30 | * We add the URL field only as an URL Chooser if it's an external link. |
||
31 | * |
||
32 | * @param FormEvent $event |
||
33 | */ |
||
34 | public function postSubmit(FormEvent $event) |
||
73 | } |
||
74 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.