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 |
||
| 48 | class Plan |
||
| 49 | { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * List of tables to be created |
||
| 53 | * |
||
| 54 | * @var \Phinx\Db\Plan\NewTable[] |
||
| 55 | */ |
||
| 56 | protected $tableCreates = []; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * List of table updates |
||
| 60 | * |
||
| 61 | * @var \Phinx\Db\Plan\AlterTable[] |
||
| 62 | */ |
||
| 63 | protected $tableUpdates = []; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * List of table removals or renames |
||
| 67 | * |
||
| 68 | * @var \Phinx\Db\Plan\AlterTable[] |
||
| 69 | */ |
||
| 70 | protected $tableMoves = []; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * List of index additions or removals |
||
| 74 | * |
||
| 75 | * @var \Phinx\Db\Plan\AlterTable[] |
||
| 76 | */ |
||
| 77 | protected $indexes = []; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * List of constraint additions or removals |
||
| 81 | * |
||
| 82 | * @var \Phinx\Db\Plan\AlterTable[] |
||
| 83 | */ |
||
| 84 | protected $constraints = []; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Constructor |
||
| 88 | * |
||
| 89 | * @param Intent $intent All the actions that should be executed |
||
| 90 | */ |
||
| 91 | public function __construct(Intent $intent) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Parses the given Intent and creates the separate steps to execute |
||
| 98 | * |
||
| 99 | * @param Intent $actions The actions to use for the plan |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | protected function createPlan($actions) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Returns a nested list of all the steps to execute |
||
| 114 | * |
||
| 115 | * @return AlterTable[][] |
||
| 116 | */ |
||
| 117 | protected function updatesSequence() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Executes this plan using the given AdapterInterface |
||
| 129 | * |
||
| 130 | * @param AdapterInterface $executor The executor object for the plan |
||
| 131 | * @return void |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function execute(AdapterInterface $executor) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Executes the inverse plan (rollback the actions) with the given AdapterInterface:w |
||
| 148 | * |
||
| 149 | * @param AdapterInterface $executor The executor object for the plan |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function executeInverse(AdapterInterface $executor) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Deletes certain actions from the plan if they are found to be conflicting or redundant. |
||
| 167 | * |
||
| 168 | * @return void |
||
| 169 | */ |
||
| 170 | protected function resolveConflicts() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Deletes all actions related to the given table and keeps the |
||
| 188 | * rest |
||
| 189 | * |
||
| 190 | * @param Table $table The table to find in the list of actions |
||
| 191 | * @param AlterTable[] $actions The actions to transform |
||
| 192 | * @return AlterTable[] The list of actions without actions for the given table |
||
| 193 | */ |
||
| 194 | protected function forgetTable(Table $table, $actions) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Collects all table creation actions from the given intent |
||
| 209 | * |
||
| 210 | * @param \Phinx\Db\Action\Action[] $actions The actions to parse |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | protected function gatherCreates($actions) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Collects all alter table actions from the given intent |
||
| 249 | * |
||
| 250 | * @param \Phinx\Db\Action\Action[] $actions The actions to parse |
||
| 251 | * @return void |
||
| 252 | */ |
||
| 253 | protected function gatherUpdates($actions) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Collects all alter table drop and renames from the given intent |
||
| 280 | * |
||
| 281 | * @param \Phinx\Db\Action\Action[] $actions The actions to parse |
||
| 282 | * @return void |
||
| 283 | */ |
||
| 284 | View Code Duplication | protected function gatherTableMoves($actions) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Collects all index creation and drops from the given intent |
||
| 305 | * |
||
| 306 | * @param \Phinx\Db\Action\Action[] $actions The actions to parse |
||
| 307 | * @return void |
||
| 308 | */ |
||
| 309 | protected function gatherIndexes($actions) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Collects all foreign key creation and drops from the given intent |
||
| 335 | * |
||
| 336 | * @param \Phinx\Db\Action\Action[] $actions The actions to parse |
||
| 337 | * @return void |
||
| 338 | */ |
||
| 339 | View Code Duplication | protected function gatherConstraints($actions) |
|
| 357 | } |
||
| 358 |
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: