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 IntoKeyword extends Component |
||
| 25 | { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * FIELDS/COLUMNS Options for `SELECT...INTO` statements. |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | public static $FIELDS_OPTIONS = array( |
||
| 33 | |||
| 34 | 'TERMINATED BY' => array(1, 'expr'), |
||
| 35 | 'OPTIONALLY' => 2, |
||
| 36 | 'ENCLOSED BY' => array(3, 'expr'), |
||
| 37 | 'ESCAPED BY' => array(4, 'expr'), |
||
| 38 | ); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * LINES Options for `SELECT...INTO` statements. |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | */ |
||
| 45 | public static $LINES_OPTIONS = array( |
||
| 46 | |||
| 47 | 'STARTING BY' => array(1, 'expr'), |
||
| 48 | 'TERMINATED BY' => array(2, 'expr'), |
||
| 49 | ); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Type of target (OUTFILE or SYMBOL). |
||
| 53 | * |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | 15 | public $type; |
|
| 57 | |||
| 58 | 15 | /** |
|
| 59 | * The destination, which can be a table or a file. |
||
| 60 | * |
||
| 61 | * @var string|Expression |
||
| 62 | */ |
||
| 63 | public $dest; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The name of the columns. |
||
| 67 | * |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | public $columns; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The values to be selected into (SELECT .. INTO @var1) |
||
| 74 | 15 | * |
|
| 75 | * @var ExpressionArray |
||
| 76 | 15 | */ |
|
| 77 | public $values; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Options for FIELDS/COLUMNS keyword |
||
| 81 | * |
||
| 82 | 15 | * @var OptionsArray |
|
| 83 | * @see static::$FIELDS_OPTIONS |
||
| 84 | */ |
||
| 85 | 15 | public $fields_options; |
|
| 86 | 1 | ||
| 87 | /** |
||
| 88 | * Whether to use `FIELDS` or `COLUMNS` while building |
||
| 89 | * |
||
| 90 | 15 | * @var boolean |
|
| 91 | 13 | */ |
|
| 92 | public $fields_keyword; |
||
| 93 | |||
| 94 | 15 | /** |
|
| 95 | 9 | * Options for OPTIONS keyword |
|
| 96 | 6 | * |
|
| 97 | 6 | * @var OptionsArray |
|
| 98 | 6 | * @see static::$LINES_OPTIONS |
|
| 99 | */ |
||
| 100 | public $lines_options; |
||
| 101 | |||
| 102 | 3 | /** |
|
| 103 | * @param Parser $parser The parser that serves as context. |
||
| 104 | * @param TokensList $list The list of tokens that are being parsed. |
||
| 105 | 14 | * @param array $options Parameters for parsing. |
|
| 106 | 9 | * |
|
| 107 | 9 | * @return IntoKeyword |
|
| 108 | 9 | */ |
|
| 109 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
||
| 208 | |||
| 209 | private function _parseFileOptions(Parser $parser, TokensList $list, $keyword='FIELDS') { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param IntoKeyword $component The component to be built. |
||
| 237 | * @param array $options Parameters for building. |
||
| 238 | * |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | public static function build($component, array $options = array()) |
||
| 266 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..