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 |
||
| 24 | class Key extends Component |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * All key options. |
||
| 28 | * |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | public static $KEY_OPTIONS = array( |
||
| 32 | 'KEY_BLOCK_SIZE' => array(1, 'var'), |
||
| 33 | 'USING' => array(2, 'var'), |
||
| 34 | 'WITH PARSER' => array(3, 'var'), |
||
| 35 | 'COMMENT' => array(4, 'var='), |
||
| 36 | ); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The name of this key. |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | public $name; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Columns. |
||
| 47 | * |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | public $columns; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The type of this key. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | public $type; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The options of this key. |
||
| 61 | * |
||
| 62 | * @var OptionsArray |
||
| 63 | */ |
||
| 64 | public $options; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Constructor. |
||
| 68 | * |
||
| 69 | * @param string $name the name of the key |
||
|
|
|||
| 70 | * @param array $columns the columns covered by this key |
||
| 71 | * @param string $type the type of this key |
||
| 72 | * @param OptionsArray $options the options of this key |
||
| 73 | */ |
||
| 74 | 13 | public function __construct( |
|
| 85 | |||
| 86 | /** |
||
| 87 | * @param Parser $parser the parser that serves as context |
||
| 88 | * @param TokensList $list the list of tokens that are being parsed |
||
| 89 | * @param array $options parameters for parsing |
||
| 90 | * |
||
| 91 | * @return Key |
||
| 92 | */ |
||
| 93 | 13 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
| 178 | |||
| 179 | /** |
||
| 180 | * @param Key $component the component to be built |
||
| 181 | * @param array $options parameters for building |
||
| 182 | * |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | 3 | public static function build($component, array $options = array()) |
|
| 205 | } |
||
| 206 |
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.