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 |
||
22 | class GitterRoomListenCommand extends AbstractCommand |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $signature = 'gitter:listen {room}'; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $description = 'Listen gitter room'; |
||
33 | |||
34 | /** |
||
35 | * Execute the console command. |
||
36 | * |
||
37 | * @param Repository $config |
||
38 | * @param Container $container |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | View Code Duplication | public function handle(Repository $config, Container $container) |
|
60 | |||
61 | /** |
||
62 | * @param GitterRoom $gitter |
||
63 | */ |
||
64 | protected function listen(GitterRoom $gitter) |
||
81 | |||
82 | /** |
||
83 | * Message stream throw http api |
||
84 | * |
||
85 | * @param LoopInterface $loop |
||
86 | * @param GitterRoom $gitter |
||
87 | */ |
||
88 | protected function onMessageFallback(LoopInterface $loop, GitterRoom $gitter) |
||
106 | |||
107 | protected function onMessage(GitterMessage $gitter) |
||
111 | } |
||
112 | |||
117 |
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.