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 namespace Comodojo\Dispatcher\Service; |
||
34 | abstract class AbstractService extends DispatcherClassModel { |
||
35 | |||
36 | 1 | View Code Duplication | public function __construct( |
|
|||
37 | Configuration $configuration, |
||
38 | 1 | LoggerInterface $logger, |
|
39 | Request $request, |
||
40 | Router $router, |
||
41 | Response $response, |
||
42 | Extra $extra |
||
43 | ) { |
||
44 | |||
45 | 1 | parent::__construct($configuration, $logger); |
|
46 | |||
47 | 1 | $this->request = $request; |
|
48 | |||
49 | 1 | $this->router = $router; |
|
50 | |||
51 | 1 | $this->response = $response; |
|
52 | |||
53 | 1 | $this->extra = $extra; |
|
54 | |||
55 | 1 | } |
|
56 | |||
57 | /** |
||
58 | * Get service-implemented HTTP methods |
||
59 | * |
||
60 | * @return array Service implemented methods, in uppercase |
||
61 | * @throw Exception |
||
62 | */ |
||
63 | 2 | public function getImplementedMethods() { |
|
86 | |||
87 | /** |
||
88 | * Return the callable class method that reflect the requested one |
||
89 | * |
||
90 | */ |
||
91 | 2 | public function getMethod($method) { |
|
108 | |||
109 | } |
||
110 |
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.