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 |
||
| 19 | class BFrontendMenu extends BAbstractMenuEntry |
||
| 20 | {
|
||
| 21 | /** |
||
| 22 | * Массив с доступными для меню классами |
||
| 23 | * 'class' - название модели |
||
| 24 | * 'key' - ключ, определяющий участие записи в меню |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected $availableClasses = array( |
||
| 29 | array('class' => 'BFrontendMenu', 'key' => 'visible'),
|
||
| 30 | array('class' => 'BInfo', 'key' => 'menu'),
|
||
| 31 | array('class' => 'BFrontendCustomMenuItem', 'key' => 'visible'),
|
||
| 32 | ); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var BFrontendCustomMenuItem[] |
||
| 36 | */ |
||
| 37 | protected $availableEntries = array(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Загрузка дополнительных классов для работы с меню |
||
| 41 | * @HINT: По большей части нужны классы, доступные как элементы меню |
||
| 42 | */ |
||
| 43 | 5 | public static function loadExtraModels() |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $scenario |
||
| 50 | */ |
||
| 51 | 5 | public function __construct($scenario = 'insert') |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @return int |
||
| 59 | */ |
||
| 60 | public function getId() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function getName() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | public function getUrl() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getFrontendModelName() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | 6 | public function tableName() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @return array |
||
| 99 | */ |
||
| 100 | 4 | View Code Duplication | public function rules() |
| 109 | |||
| 110 | /** |
||
| 111 | * @return array |
||
| 112 | */ |
||
| 113 | 1 | public function relations() |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Добавление записи меню |
||
| 122 | * |
||
| 123 | * @param IBFrontendMenuEntry $e |
||
| 124 | * |
||
| 125 | * @return bool |
||
| 126 | */ |
||
| 127 | 2 | public function addEntry(IBFrontendMenuEntry $e) |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Удаление записи меню |
||
| 145 | * |
||
| 146 | * @param IBFrontendMenuEntry $e |
||
| 147 | * |
||
| 148 | * @return bool |
||
| 149 | */ |
||
| 150 | public function removeEntry(IBFrontendMenuEntry $e) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Переключение отношения записи к меню |
||
| 167 | * |
||
| 168 | * @param IBFrontendMenuEntry $e |
||
| 169 | */ |
||
| 170 | public function switchMenuEntryStatus(IBFrontendMenuEntry $e) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Является ли запись CustomMenuItem элементом меню |
||
| 180 | * |
||
| 181 | * @param BFrontendCustomMenuItem $c |
||
| 182 | * |
||
| 183 | * @return bool |
||
| 184 | */ |
||
| 185 | 1 | public function hasCustomMenuItem(BFrontendCustomMenuItem $c) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Является ли $e записью меню |
||
| 192 | * |
||
| 193 | * @param IBFrontendMenuEntry $e |
||
| 194 | * |
||
| 195 | * @return bool |
||
| 196 | */ |
||
| 197 | 1 | public function hasMenuEntry(IBFrontendMenuEntry $e) |
|
| 206 | |||
| 207 | /** |
||
| 208 | * @return CArrayDataProvider |
||
| 209 | */ |
||
| 210 | public function getDataProvider() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return BAbstractMenuEntry[] |
||
| 232 | * @throws BFrontendMenuException |
||
| 233 | */ |
||
| 234 | public function getAvailableEntries() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param CDbCriteria $criteria |
||
| 261 | * |
||
| 262 | * @return CDbCriteria |
||
| 263 | */ |
||
| 264 | View Code Duplication | protected function getSearchCriteria(CDbCriteria $criteria) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * Удаление из доступных элементов для добавления уже добавленных |
||
| 275 | */ |
||
| 276 | protected function clearEntries() |
||
| 290 | } |