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 |
||
18 | class ProfilePlugin implements Plugin |
||
19 | { |
||
20 | /** |
||
21 | * @var Plugin |
||
22 | */ |
||
23 | private $plugin; |
||
24 | |||
25 | /** |
||
26 | * @var Collector |
||
27 | */ |
||
28 | private $collector; |
||
29 | |||
30 | /** |
||
31 | * @var Formatter |
||
32 | */ |
||
33 | private $formatter; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $pluginName; |
||
39 | |||
40 | /** |
||
41 | * @param Plugin $plugin |
||
42 | * @param Collector $collector |
||
43 | * @param Formatter $formatter |
||
44 | * @param string $pluginName |
||
45 | */ |
||
46 | 5 | public function __construct(Plugin $plugin, Collector $collector, Formatter $formatter, $pluginName) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 4 | View Code Duplication | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
74 | } |
||
75 |
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.