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 |
||
| 17 | class AssignmentController extends Controller |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var \yii\web\IdentityInterface the class name of the [[identity]] object |
||
| 21 | */ |
||
| 22 | public $userIdentityClass; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string search class name for assignments search |
||
| 26 | */ |
||
| 27 | public $searchClass = [ |
||
| 28 | 'class' => AssignmentSearch::class, |
||
| 29 | ]; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string id column name |
||
| 33 | */ |
||
| 34 | public $idField = 'id'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string username column name |
||
| 38 | */ |
||
| 39 | public $usernameField = 'username'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var array assignments GridView columns |
||
| 43 | */ |
||
| 44 | public $gridViewColumns = []; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @inheritdoc |
||
| 48 | */ |
||
| 49 | public function init() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritdoc |
||
| 67 | */ |
||
| 68 | public function behaviors(): array |
||
| 89 | |||
| 90 | /** |
||
| 91 | * List of all assignments |
||
| 92 | * |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public function actionIndex() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Displays a single Assignment model. |
||
| 115 | * |
||
| 116 | * @param int $id |
||
| 117 | * |
||
| 118 | * @return mixed |
||
| 119 | */ |
||
| 120 | public function actionView(int $id) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Assign items |
||
| 132 | * |
||
| 133 | * @param int $id |
||
| 134 | * |
||
| 135 | * @return array |
||
| 136 | */ |
||
| 137 | View Code Duplication | public function actionAssign(int $id) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Remove items |
||
| 148 | * |
||
| 149 | * @param int $id |
||
| 150 | * |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function actionRemove(int $id) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Finds the Assignment model based on its primary key value. |
||
| 164 | * If the model is not found, a 404 HTTP exception will be thrown. |
||
| 165 | * |
||
| 166 | * @param int $id |
||
| 167 | * |
||
| 168 | * @return AssignmentModel the loaded model |
||
| 169 | * |
||
| 170 | * @throws NotFoundHttpException if the model cannot be found |
||
| 171 | */ |
||
| 172 | protected function findModel(int $id) |
||
| 182 | } |
||
| 183 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: