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 AlterOperation extends Component |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * All database options. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | public static $DB_OPTIONS = array( |
||
| 29 | 'CHARACTER SET' => array(1, 'var'), |
||
| 30 | 'CHARSET' => array(1, 'var'), |
||
| 31 | 'DEFAULT CHARACTER SET' => array(1, 'var'), |
||
| 32 | 'DEFAULT CHARSET' => array(1, 'var'), |
||
| 33 | 'UPGRADE' => array(1, 'var'), |
||
| 34 | 'COLLATE' => array(2, 'var'), |
||
| 35 | 'DEFAULT COLLATE' => array(2, 'var'), |
||
| 36 | ); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * All table options. |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | public static $TABLE_OPTIONS = array( |
||
| 44 | 'ENGINE' => array(1, 'var='), |
||
| 45 | 'AUTO_INCREMENT' => array(1, 'var='), |
||
| 46 | 'AVG_ROW_LENGTH' => array(1, 'var'), |
||
| 47 | 'MAX_ROWS' => array(1, 'var'), |
||
| 48 | 'ROW_FORMAT' => array(1, 'var'), |
||
| 49 | 'COMMENT' => array(1, 'var'), |
||
| 50 | 'ADD' => 1, |
||
| 51 | 'ALTER' => 1, |
||
| 52 | 'ANALYZE' => 1, |
||
| 53 | 'CHANGE' => 1, |
||
| 54 | 'CHECK' => 1, |
||
| 55 | 'COALESCE' => 1, |
||
| 56 | 'CONVERT' => 1, |
||
| 57 | 'DISABLE' => 1, |
||
| 58 | 'DISCARD' => 1, |
||
| 59 | 'DROP' => 1, |
||
| 60 | 'ENABLE' => 1, |
||
| 61 | 'IMPORT' => 1, |
||
| 62 | 'MODIFY' => 1, |
||
| 63 | 'OPTIMIZE' => 1, |
||
| 64 | 'ORDER' => 1, |
||
| 65 | 'PARTITION' => 1, |
||
| 66 | 'REBUILD' => 1, |
||
| 67 | 'REMOVE' => 1, |
||
| 68 | 'RENAME' => 1, |
||
| 69 | 'REORGANIZE' => 1, |
||
| 70 | 'REPAIR' => 1, |
||
| 71 | 'UPGRADE' => 1, |
||
| 72 | |||
| 73 | 'COLUMN' => 2, |
||
| 74 | 'CONSTRAINT' => 2, |
||
| 75 | 'DEFAULT' => 2, |
||
| 76 | 'TO' => 2, |
||
| 77 | 'BY' => 2, |
||
| 78 | 'FOREIGN' => 2, |
||
| 79 | 'FULLTEXT' => 2, |
||
| 80 | 'KEY' => 2, |
||
| 81 | 'KEYS' => 2, |
||
| 82 | 'PARTITIONING' => 2, |
||
| 83 | 'PRIMARY KEY' => 2, |
||
| 84 | 'SPATIAL' => 2, |
||
| 85 | 'TABLESPACE' => 2, |
||
| 86 | 'INDEX' => 2, |
||
| 87 | ); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * All view options. |
||
| 91 | * |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | public static $VIEW_OPTIONS = array( |
||
| 95 | 'AS' => 1, |
||
| 96 | ); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Options of this operation. |
||
| 100 | * |
||
| 101 | * @var OptionsArray |
||
| 102 | */ |
||
| 103 | public $options; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The altered field. |
||
| 107 | * |
||
| 108 | * @var Expression |
||
| 109 | */ |
||
| 110 | public $field; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Unparsed tokens. |
||
| 114 | * |
||
| 115 | * @var Token[]|string |
||
| 116 | */ |
||
| 117 | public $unknown = array(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Constructor. |
||
| 121 | * |
||
| 122 | * @param OptionsArray $options options of alter operation |
||
|
|
|||
| 123 | * @param Expression $field altered field |
||
| 124 | * @param array $unknown unparsed tokens found at the end of operation |
||
| 125 | */ |
||
| 126 | 9 | public function __construct( |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param Parser $parser the parser that serves as context |
||
| 138 | * @param TokensList $list the list of tokens that are being parsed |
||
| 139 | * @param array $options parameters for parsing |
||
| 140 | * |
||
| 141 | * @return AlterOperation |
||
| 142 | */ |
||
| 143 | 9 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * @param AlterOperation $component the component to be built |
||
| 265 | * @param array $options parameters for building |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | 1 | public static function build($component, array $options = array()) |
|
| 279 | } |
||
| 280 |
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.