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 |
||
18 | class EventClassDispatcher extends \PEIP\Dispatcher\ObjectMapDispatcher |
||
19 | { |
||
20 | /** |
||
21 | * Notifies all listeners of a given event-object. |
||
22 | * |
||
23 | * @param string $name name of the event |
||
24 | * @param \PEIP\INF\Event\Event $object an event object |
||
25 | * |
||
26 | * @return bool|null |
||
27 | */ |
||
28 | View Code Duplication | public function notify($name, $object) |
|
46 | |||
47 | //put your code here |
||
48 | |||
49 | /** |
||
50 | * Creates an event-object with given object as content/subject and notifies |
||
51 | * all registers listeners of the event. |
||
52 | * |
||
53 | * @param string $name name of the event |
||
54 | * @param object $object the subject of the event |
||
55 | * @param array $headers headers of the event-object as key/value pairs |
||
56 | * @param string $eventClass event-class to create instances from |
||
57 | * |
||
58 | * @return |
||
59 | */ |
||
60 | View Code Duplication | public function buildAndNotify($name, $object, array $headers = [], $eventClass = false, $type = false) |
|
76 | |||
77 | /** |
||
78 | * Checks wether an object has a listener for an event. |
||
79 | * |
||
80 | * @param string $name the event-name |
||
81 | * @param object $object object to check for listeners |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function hasListeners($name, $object) |
||
92 | } |
||
93 |
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.