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 |
||
20 | /*final*/ class RetryPlugin implements Plugin |
||
21 | { |
||
22 | /** |
||
23 | * Number of retry before sending an exception. |
||
24 | * |
||
25 | * @var int |
||
26 | */ |
||
27 | private $retry; |
||
28 | |||
29 | /** |
||
30 | * Store the retry counter for each request. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | private $retryStorage = []; |
||
35 | |||
36 | /** |
||
37 | * @param array $config { |
||
38 | * |
||
39 | * @var int $retries Number of retries to attempt if an exception occurs before letting the exception bubble up. |
||
40 | * } |
||
41 | */ |
||
42 | 6 | View Code Duplication | public function __construct(array $config = []) |
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 4 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
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.