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 |
||
| 17 | View Code Duplication | class HeaderDefaultsPlugin implements Plugin |
|
| 18 | { |
||
| 19 | private $headers = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param array $headers headers to set to the request |
||
| 23 | */ |
||
| 24 | 3 | public function __construct(array $headers) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | 1 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
| 42 | } |
||
| 43 |
If you suppress an error, we recommend checking for the error condition explicitly: