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 |
||
23 | class Dispatcher implements EventDispatcherInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var Provider[] |
||
27 | */ |
||
28 | protected $providers = []; |
||
29 | |||
30 | /** |
||
31 | * Dispatcher constructor. |
||
32 | * |
||
33 | * @param Provider ...$providers |
||
34 | */ |
||
35 | public function __construct(Provider ...$providers) |
||
41 | |||
42 | /** |
||
43 | * Provide all relevant listeners with an event to process. |
||
44 | * |
||
45 | * @param object $event |
||
46 | * The object to process. |
||
47 | * |
||
48 | * @return object |
||
49 | * The Event that was passed, now modified by listeners. |
||
50 | */ |
||
51 | public function dispatch(object $event) |
||
61 | |||
62 | /** |
||
63 | * Add a provider to the dispatcher |
||
64 | * |
||
65 | * @param Provider $provider |
||
66 | * @return void |
||
67 | * @throws \RuntimeException if provider duplicated |
||
68 | */ |
||
69 | protected function addProvider(Provider $provider) |
||
78 | |||
79 | /** |
||
80 | * @param object $event |
||
81 | * @return iterable |
||
82 | */ |
||
83 | View Code Duplication | protected function getListeners(object $event): iterable |
|
95 | } |