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 Provider implements ListenerProviderInterface |
||
24 | { |
||
25 | use ParameterTrait; |
||
26 | |||
27 | /** |
||
28 | * event classes listened |
||
29 | * |
||
30 | * @var UniquePriorityQueue[] |
||
31 | */ |
||
32 | protected $listened = []; |
||
33 | |||
34 | /** |
||
35 | * @param object $event |
||
36 | * An event for which to return the relevant listeners. |
||
37 | * @return iterable |
||
38 | * An iterable (array, iterator, or generator) of callables. Each |
||
39 | * callable MUST be type-compatible with $event. |
||
40 | */ |
||
41 | View Code Duplication | public function getListenersForEvent(object $event): iterable |
|
51 | |||
52 | /** |
||
53 | * Attach a listener (with default priority 50) to the provider |
||
54 | * |
||
55 | * @param callable $callable MUST be type-compatible with $event. |
||
56 | * @param int $priority range 0 - 100, 0 means lower priority |
||
57 | * @return $this |
||
58 | * @throws \RuntimeException reflection problem found |
||
59 | * @throws \InvalidArgumentException unknown type of callable found |
||
60 | */ |
||
61 | public function attach(callable $callable, int $priority = 50) |
||
70 | |||
71 | /** |
||
72 | * Get callable's first argument EVENT class. |
||
73 | * |
||
74 | * @param callable $callable |
||
75 | * @return string classname or interface name |
||
76 | * @throws \RuntimeException reflection problem found |
||
77 | * @throws \InvalidArgumentException unknown type of callable found |
||
78 | */ |
||
79 | protected function getEventClass(callable $callable): string |
||
100 | } |