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 |
||
25 | class PartitionDefinition extends Component |
||
26 | { |
||
27 | /** |
||
28 | * All field options. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | public static $OPTIONS = array( |
||
33 | 'STORAGE ENGINE' => array(1, 'var'), |
||
34 | 'ENGINE' => array(1, 'var'), |
||
35 | 'COMMENT' => array(2, 'var'), |
||
36 | 'DATA DIRECTORY' => array(3, 'var'), |
||
37 | 'INDEX DIRECTORY' => array(4, 'var'), |
||
38 | 'MAX_ROWS' => array(5, 'var'), |
||
39 | 'MIN_ROWS' => array(6, 'var'), |
||
40 | 'TABLESPACE' => array(7, 'var'), |
||
41 | 'NODEGROUP' => array(8, 'var'), |
||
42 | ); |
||
43 | |||
44 | /** |
||
45 | * Whether this entry is a subpartition or a partition. |
||
46 | * |
||
47 | * @var bool |
||
48 | */ |
||
49 | public $isSubpartition; |
||
50 | |||
51 | /** |
||
52 | * The name of this partition. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | public $name; |
||
57 | |||
58 | /** |
||
59 | * The type of this partition (what follows the `VALUES` keyword). |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | public $type; |
||
64 | |||
65 | /** |
||
66 | * The expression used to defined this partition. |
||
67 | * |
||
68 | * @var Expression|string |
||
69 | */ |
||
70 | public $expr; |
||
71 | |||
72 | /** |
||
73 | * The subpartitions of this partition. |
||
74 | * |
||
75 | * @var PartitionDefinition[] |
||
76 | */ |
||
77 | public $subpartitions; |
||
78 | |||
79 | /** |
||
80 | * The options of this field. |
||
81 | * |
||
82 | * @var OptionsArray |
||
83 | */ |
||
84 | public $options; |
||
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 PartitionDefinition |
||
92 | */ |
||
93 | 1 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
195 | |||
196 | /** |
||
197 | * @param PartitionDefinition|PartitionDefinition[] $component the component to be built |
||
198 | * @param array $options parameters for building |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | public static function build($component, array $options = array()) |
||
220 | } |
||
221 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.