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 |
||
19 | class EventAction |
||
20 | { |
||
21 | /** @var Template */ |
||
22 | private $template; |
||
23 | |||
24 | /** @var EventService */ |
||
25 | private $eventService; |
||
26 | |||
27 | /** @var CategoryService */ |
||
28 | private $categoryService; |
||
29 | |||
30 | /** @var MeetupApiService */ |
||
31 | private $meetupService; |
||
32 | |||
33 | /** |
||
34 | * EventAction constructor. |
||
35 | * |
||
36 | * @param Template $template |
||
37 | * @param EventService $eventService |
||
38 | * @param CategoryService $categoryService |
||
39 | * @param MeetupApiService $meetupService |
||
40 | */ |
||
41 | public function __construct( |
||
52 | |||
53 | /** |
||
54 | * Executed when action is invoked. |
||
55 | * |
||
56 | * @param Request $request |
||
57 | * @param Response $response |
||
58 | * @param callable|null $next |
||
59 | * |
||
60 | * @throws \Exception |
||
61 | * |
||
62 | * @return HtmlResponse |
||
63 | */ |
||
64 | View Code Duplication | public function __invoke( |
|
86 | } |
||
87 |
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.