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 OrderKeyword extends Component |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * The expression that is used for ordering. |
||
| 25 | * |
||
| 26 | * @var Expression |
||
| 27 | */ |
||
| 28 | public $expr; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The order type. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | public $type; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Constructor. |
||
| 39 | * |
||
| 40 | * @param Expression $expr the expression that we are sorting by |
||
|
|
|||
| 41 | * @param string $type the sorting type |
||
| 42 | */ |
||
| 43 | 19 | public function __construct($expr = null, $type = 'ASC') |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @param Parser $parser the parser that serves as context |
||
| 51 | * @param TokensList $list the list of tokens that are being parsed |
||
| 52 | * @param array $options parameters for parsing |
||
| 53 | * |
||
| 54 | * @return OrderKeyword[] |
||
| 55 | */ |
||
| 56 | 18 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * @param OrderKeyword|OrderKeyword[] $component the component to be built |
||
| 128 | * @param array $options parameters for building |
||
| 129 | * |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | 3 | View Code Duplication | public static function build($component, array $options = array()) |
| 140 | } |
||
| 141 |
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.