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 |
||
| 27 | class AnsiFormatter implements Formatter |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var OutputFormatter |
||
| 31 | */ |
||
| 32 | private $innerFormatter; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Creates the formatter. |
||
| 36 | * |
||
| 37 | * @param StyleSet $styleSet The style set to use. |
||
|
|
|||
| 38 | */ |
||
| 39 | 146 | View Code Duplication | public function __construct(StyleSet $styleSet = null) |
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 2 | public function format($string, Style $style = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | 1 | public function removeFormat($string) |
|
| 81 | } |
||
| 82 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.