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 |
||
| 20 | class ContentBlock extends \yii\db\ActiveRecord |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var null|string |
||
| 24 | */ |
||
| 25 | public $newGroup = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @inheritdoc |
||
| 29 | */ |
||
| 30 | public static function tableName() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function rules() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @inheritdoc |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function attributeLabels() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @inheritdoc |
||
| 69 | */ |
||
| 70 | public function behaviors() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param $params |
||
| 81 | * @return ActiveDataProvider |
||
| 82 | */ |
||
| 83 | public function search($params) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @deprecated use ContentBlockHelper::getChunk($key, $params, $model) instead |
||
| 112 | * Get chunk model or value |
||
| 113 | * @param string $key |
||
| 114 | * @param bool $valueOnly |
||
| 115 | * @param mixed $defaultValue |
||
| 116 | * @return ContentBlock|string |
||
|
|
|||
| 117 | */ |
||
| 118 | public static function getChunk($key, $valueOnly = true, $defaultValue = null) |
||
| 122 | |||
| 123 | |||
| 124 | /** |
||
| 125 | * @return ContentBlockGroup[] |
||
| 126 | */ |
||
| 127 | public function getGroup() |
||
| 131 | } |
||
| 132 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.