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