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 |
||
| 7 | class GridColumn extends AbstractGridColumn |
||
| 8 | { |
||
| 9 | protected $formatter; |
||
| 10 | protected $field; |
||
| 11 | protected $label; |
||
| 12 | protected $searchable; |
||
| 13 | protected $order; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * GridColumn constructor. |
||
| 17 | * |
||
| 18 | * @param $field |
||
| 19 | * @param string|null $label |
||
| 20 | * @param mixed $formatter |
||
| 21 | * @param array|null $options |
||
| 22 | * @param bool $searchable |
||
| 23 | * @param int|null $order If there are columns that have an order mixed with columns of 'null' order, the null ones will appear last |
||
| 24 | */ |
||
| 25 | public function __construct($field, |
||
| 52 | |||
| 53 | public function isSearchable() |
||
| 57 | |||
| 58 | public function format($object, GridSourceInterface $gridsource) |
||
| 66 | |||
| 67 | protected function _format($object) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return $formatter |
||
| 105 | */ |
||
| 106 | public function getFormatter() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param $formatter |
||
| 113 | */ |
||
| 114 | public function setFormatter($formatter) |
||
| 118 | |||
| 119 | public function toArray() |
||
| 126 | } |
||
| 127 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: