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 |
||
9 | class ExperienceSubscriber |
||
10 | { |
||
11 | /** |
||
12 | * The events mapping to the listener function. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $events = [ |
||
17 | PostWasCreatedEvent::class => 'postWasCreated', |
||
18 | ]; |
||
19 | |||
20 | /** |
||
21 | * Register the listeners for the subscriber. |
||
22 | * |
||
23 | * @param Illuminate\Events\Dispatcher $events |
||
24 | * |
||
25 | * @return void |
||
26 | */ |
||
27 | public function subscribe($events) |
||
33 | |||
34 | /** |
||
35 | * Handle a PostWasCreated event. |
||
36 | * |
||
37 | * @param \Xetaravel\Events\Discuss\PostWasCreatedEvent $event The event that was fired. |
||
38 | * |
||
39 | * @return bool |
||
40 | */ |
||
41 | public function postWasCreated(PostWasCreatedEvent $event) |
||
55 | |||
56 | /** |
||
57 | * Create the log. |
||
58 | * |
||
59 | * @param array $data The data used to create the log. |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | View Code Duplication | protected function create(array $data) : bool |
|
72 | } |
||
73 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.