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 |
||
| 11 | class CustomField implements EntityInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var integer Уникальный идентификатор заполняемого дополнительного поля |
||
| 15 | */ |
||
| 16 | public $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | public $name; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | public $code; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var bool Является ли дополнительное поле системным |
||
| 30 | */ |
||
| 31 | public $is_system; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var Value[] |
||
| 35 | */ |
||
| 36 | protected $values = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | protected $fieldList = [ |
||
| 42 | 'id', 'name', 'code', 'is_system', |
||
| 43 | ]; |
||
| 44 | |||
| 45 | use FieldList; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * CustomField constructor. |
||
| 49 | * @param $id |
||
| 50 | * @param null $name |
||
| 51 | * @param null $code |
||
| 52 | */ |
||
| 53 | 32 | public function __construct($id, $name = null, $code = null) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param Value $value |
||
| 62 | */ |
||
| 63 | 31 | public function addValue(Value $value) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * @return array |
||
| 70 | */ |
||
| 71 | 29 | View Code Duplication | public function get() |
| 86 | |||
| 87 | /** |
||
| 88 | * @param $array |
||
| 89 | */ |
||
| 90 | 4 | public function set($array) |
|
| 94 | } |