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 |
||
| 25 | class Schema implements SchemaInterface |
||
| 26 | { |
||
| 27 | const OPERATION_CREATE = 'create'; |
||
| 28 | const OPERATION_ALTER = 'alter'; |
||
| 29 | const OPERATION_DROP = 'drop'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Connection |
||
| 33 | */ |
||
| 34 | protected $connection; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var ModelBag |
||
| 38 | */ |
||
| 39 | protected $models; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var SchemaAsset; |
||
| 43 | */ |
||
| 44 | protected $schema; |
||
| 45 | |||
| 46 | protected $queries = []; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Constructor |
||
| 50 | * |
||
| 51 | * @param Connection $connection |
||
| 52 | * @param ModelBag $models |
||
| 53 | */ |
||
| 54 | public function __construct(Connection $connection, ModelBag $models) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Creates instance with current schema |
||
| 64 | */ |
||
| 65 | protected function createCurrentSchema() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Returns connection |
||
| 72 | * |
||
| 73 | * @return Connection |
||
| 74 | */ |
||
| 75 | public function connection() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Sets create operation |
||
| 82 | * |
||
| 83 | * @param array $entityName |
||
| 84 | * |
||
| 85 | * @return $this |
||
| 86 | */ |
||
| 87 | public function create(array $entityName = []) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Sets alter operation |
||
| 96 | * |
||
| 97 | * @param array $entityName |
||
| 98 | * |
||
| 99 | * @return $this |
||
| 100 | */ |
||
| 101 | public function alter(array $entityName = []) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Sets drop operation |
||
| 110 | * |
||
| 111 | * @param array $entityName |
||
| 112 | * |
||
| 113 | * @return $this |
||
| 114 | */ |
||
| 115 | public function drop(array $entityName = []) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns array with models for operation |
||
| 124 | * |
||
| 125 | * @param array $entity |
||
| 126 | * |
||
| 127 | * @return ModelInterface[] |
||
| 128 | */ |
||
| 129 | protected function retrieveModels(array $entity = []) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Builds create table queries |
||
| 145 | * |
||
| 146 | * @param ModelInterface[] $models |
||
| 147 | * |
||
| 148 | * @throws SchemaException |
||
| 149 | */ |
||
| 150 | protected function buildCreate(array $models) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Builds table alteration queries |
||
| 170 | * |
||
| 171 | * @param ModelInterface[] $models |
||
| 172 | */ |
||
| 173 | View Code Duplication | protected function buildAlter(array $models) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Creates table from model into schema |
||
| 193 | * |
||
| 194 | * @param SchemaAsset $schema |
||
| 195 | * @param ModelInterface $model |
||
| 196 | */ |
||
| 197 | protected function createTable(SchemaAsset $schema, ModelInterface $model) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Quotes SQL identifier or array of identifiers |
||
| 244 | * |
||
| 245 | * @param string|array $identifier |
||
| 246 | * |
||
| 247 | * @return string|array |
||
| 248 | */ |
||
| 249 | protected function quoteIdentifier($identifier) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Builds drop table query |
||
| 265 | * |
||
| 266 | * @param ModelInterface[] $models |
||
| 267 | */ |
||
| 268 | View Code Duplication | protected function buildDrop(array $models) |
|
| 285 | |||
| 286 | /** |
||
| 287 | * Executes query |
||
| 288 | * After execution query is reset |
||
| 289 | * |
||
| 290 | * @return mixed|null|void |
||
| 291 | */ |
||
| 292 | public function execute() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Returns array of queries that will be executed |
||
| 309 | * |
||
| 310 | * @return array |
||
| 311 | */ |
||
| 312 | public function queryString() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Resets adapter |
||
| 319 | * |
||
| 320 | * @return $this |
||
| 321 | */ |
||
| 322 | public function reset() |
||
| 329 | } |
||
| 330 |
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: