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 |
||
28 | final class ScenarioStateHookDispatcher |
||
29 | { |
||
30 | /** |
||
31 | * @var HookRepository |
||
32 | */ |
||
33 | private $repository; |
||
34 | |||
35 | /** |
||
36 | * @var CallCenter |
||
37 | */ |
||
38 | private $callCenter; |
||
39 | |||
40 | /** |
||
41 | * @var Reader |
||
42 | */ |
||
43 | private $reader; |
||
44 | |||
45 | /** |
||
46 | * @var ScenarioStateInitializer |
||
47 | */ |
||
48 | private $store; |
||
49 | |||
50 | /** |
||
51 | * Initializes scenario state hook dispatcher. |
||
52 | * |
||
53 | * @param HookRepository $repository |
||
54 | * @param CallCenter $callCenter |
||
55 | * @param ScenarioStateInitializer $store |
||
56 | * @param Reader $reader |
||
57 | */ |
||
58 | public function __construct(HookRepository $repository, CallCenter $callCenter, ScenarioStateInitializer $store, Reader $reader) |
||
65 | |||
66 | /** |
||
67 | * Dispatches hooks for a specified event. |
||
68 | * |
||
69 | * @param HookScope $scope |
||
70 | * |
||
71 | * @return CallResults |
||
72 | */ |
||
73 | public function dispatchScopeHooks(HookScope $scope) |
||
110 | |||
111 | /** |
||
112 | * Dispatches single event hook. |
||
113 | * |
||
114 | * @param HookScope $scope |
||
115 | * @param Hook $hook |
||
116 | * |
||
117 | * @return CallResult |
||
118 | */ |
||
119 | private function dispatchHook(HookScope $scope, Hook $hook) |
||
123 | } |
||
124 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.