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 Redirect extends ActiveRecord |
||
| 20 | { |
||
| 21 | const TYPE_STATIC = 'STATIC'; |
||
| 22 | const TYPE_PREG = 'PREG'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return bool|string |
||
| 26 | */ |
||
| 27 | private static function getFilename() |
||
| 31 | |||
| 32 | public static function getTypes() |
||
| 33 | { |
||
| 34 | return [ |
||
| 35 | self::TYPE_STATIC => Yii::t('app', 'static'), |
||
| 36 | self::TYPE_PREG => Yii::t('app', 'regular'), |
||
| 37 | ]; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | public static function tableName() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @inheritdoc |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function rules() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritdoc |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function attributeLabels() |
|
| 73 | |||
| 74 | /** |
||
| 75 | * @inheritdoc |
||
| 76 | */ |
||
| 77 | public function scenarios() |
||
| 84 | |||
| 85 | |||
| 86 | /** |
||
| 87 | * Search redirects |
||
| 88 | * @param $params |
||
| 89 | * @return ActiveDataProvider |
||
| 90 | */ |
||
| 91 | public function search($params) |
||
| 114 | |||
| 115 | public static function generateRedirectFile() |
||
| 138 | |||
| 139 | public static function deleteRedirectFile() |
||
| 143 | } |
||
| 144 |