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 |
||
29 | class GitterRoomListenCommand extends AbstractCommand |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $signature = 'gitter:listen {room}'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $description = 'Listen gitter room'; |
||
40 | |||
41 | /** |
||
42 | * @var array|ExtensionInterface[] |
||
43 | */ |
||
44 | protected $extensions = []; |
||
45 | |||
46 | /** |
||
47 | * Execute the console command. |
||
48 | * |
||
49 | * @param Repository $config |
||
50 | * @param Container $container |
||
51 | * |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function handle(Repository $config, Container $container) |
||
55 | { |
||
56 | /** @var Client $client */ |
||
57 | $client = $this->createClient($container, $config->get('gitter.token')); |
||
58 | |||
59 | $this->auth($client, function (User $user) use ($client) { |
||
|
|||
60 | |||
61 | $this->findRoom($client, $this->argument('room'), function (GitterRoom $room) { |
||
62 | try { |
||
63 | $this->listen($room, true); |
||
64 | |||
65 | } catch (\Throwable $e) { |
||
66 | |||
67 | $this->error($e->getMessage()); |
||
68 | } |
||
69 | }); |
||
70 | |||
71 | }); |
||
72 | |||
73 | /** @var LoopInterface $loop */ |
||
74 | $loop = $container->make(LoopInterface::class); |
||
75 | $loop->run(); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param Client $client |
||
80 | * @param \Closure $callback |
||
81 | */ |
||
82 | protected function auth(Client $client, \Closure $callback) |
||
92 | |||
93 | /** |
||
94 | * @param GitterRoom $room |
||
95 | * @return array |
||
96 | */ |
||
97 | protected function getExtensions(GitterRoom $room) |
||
115 | |||
116 | /** |
||
117 | * @param GitterRoom $gitter |
||
118 | * @param bool $startup |
||
119 | * @return $this |
||
120 | */ |
||
121 | protected function listen(GitterRoom $gitter, $startup = false) |
||
165 | |||
166 | /** |
||
167 | * @param LoopInterface $loop |
||
168 | * @param GitterRoom $gitter |
||
169 | * @param int $timeout |
||
170 | */ |
||
171 | protected function onMessageFallback(LoopInterface $loop, GitterRoom $gitter, $timeout = 10) |
||
194 | |||
195 | /** |
||
196 | * @param GitterMessage $gitter |
||
197 | */ |
||
198 | protected function onMessage(GitterMessage $gitter) |
||
207 | } |
||
208 | |||
213 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.