Complex classes like MysqlAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MysqlAdapter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class MysqlAdapter extends PdoAdapter |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var string[] |
||
| 31 | */ |
||
| 32 | protected static $specificColumnTypes = [ |
||
| 33 | self::PHINX_TYPE_ENUM, |
||
| 34 | self::PHINX_TYPE_SET, |
||
| 35 | self::PHINX_TYPE_YEAR, |
||
| 36 | self::PHINX_TYPE_JSON, |
||
| 37 | self::PHINX_TYPE_BINARYUUID, |
||
| 38 | self::PHINX_TYPE_TINYBLOB, |
||
| 39 | self::PHINX_TYPE_MEDIUMBLOB, |
||
| 40 | self::PHINX_TYPE_LONGBLOB, |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var bool[] |
||
| 45 | */ |
||
| 46 | protected $signedColumnTypes = [ |
||
| 47 | self::PHINX_TYPE_INTEGER => true, |
||
| 48 | self::PHINX_TYPE_TINY_INTEGER => true, |
||
| 49 | self::PHINX_TYPE_SMALL_INTEGER => true, |
||
| 50 | self::PHINX_TYPE_BIG_INTEGER => true, |
||
| 51 | self::PHINX_TYPE_FLOAT => true, |
||
| 52 | self::PHINX_TYPE_DECIMAL => true, |
||
| 53 | self::PHINX_TYPE_DOUBLE => true, |
||
| 54 | self::PHINX_TYPE_BOOLEAN => true, |
||
| 55 | ]; |
||
| 56 | |||
| 57 | public const TEXT_TINY = 255; |
||
| 58 | public const TEXT_SMALL = 255; /* deprecated, alias of TEXT_TINY */ |
||
| 59 | public const TEXT_REGULAR = 65535; |
||
| 60 | public const TEXT_MEDIUM = 16777215; |
||
| 61 | public const TEXT_LONG = 4294967295; |
||
| 62 | |||
| 63 | // According to https://dev.mysql.com/doc/refman/5.0/en/blob.html BLOB sizes are the same as TEXT |
||
| 64 | public const BLOB_TINY = 255; |
||
| 65 | public const BLOB_SMALL = 255; /* deprecated, alias of BLOB_TINY */ |
||
| 66 | public const BLOB_REGULAR = 65535; |
||
| 67 | public const BLOB_MEDIUM = 16777215; |
||
| 68 | public const BLOB_LONG = 4294967295; |
||
| 69 | |||
| 70 | 80 | public const INT_TINY = 255; |
|
| 71 | public const INT_SMALL = 65535; |
||
| 72 | 80 | public const INT_MEDIUM = 16777215; |
|
| 73 | 80 | public const INT_REGULAR = 4294967295; |
|
| 74 | public const INT_BIG = 18446744073709551615; |
||
| 75 | |||
| 76 | public const BIT = 64; |
||
| 77 | |||
| 78 | public const TYPE_YEAR = 'year'; |
||
| 79 | 80 | ||
| 80 | 80 | public const FIRST = 'FIRST'; |
|
| 81 | |||
| 82 | 80 | /** |
|
| 83 | * {@inheritDoc} |
||
| 84 | 80 | * |
|
| 85 | * @throws \RuntimeException |
||
| 86 | * @throws \InvalidArgumentException |
||
| 87 | * |
||
| 88 | * @return void |
||
| 89 | 80 | */ |
|
| 90 | 80 | public function connect() |
|
| 91 | 80 | { |
|
| 92 | 80 | if ($this->connection === null) { |
|
| 93 | if (!class_exists('PDO') || !in_array('mysql', PDO::getAvailableDrivers(), true)) { |
||
| 94 | // @codeCoverageIgnoreStart |
||
| 95 | 80 | throw new RuntimeException('You need to enable the PDO_Mysql extension for Phinx to run properly.'); |
|
| 96 | // @codeCoverageIgnoreEnd |
||
| 97 | } |
||
| 98 | 80 | ||
| 99 | $options = $this->getOptions(); |
||
| 100 | |||
| 101 | $dsn = 'mysql:'; |
||
| 102 | 80 | ||
| 103 | if (!empty($options['unix_socket'])) { |
||
| 104 | // use socket connection |
||
| 105 | $dsn .= 'unix_socket=' . $options['unix_socket']; |
||
| 106 | 80 | } else { |
|
| 107 | 80 | // use network connection |
|
| 108 | $dsn .= 'host=' . $options['host']; |
||
| 109 | if (!empty($options['port'])) { |
||
| 110 | 80 | $dsn .= ';port=' . $options['port']; |
|
| 111 | } |
||
| 112 | } |
||
| 113 | 80 | ||
| 114 | 80 | $dsn .= ';dbname=' . $options['name']; |
|
| 115 | 1 | ||
| 116 | 1 | // charset support |
|
| 117 | 1 | if (!empty($options['charset'])) { |
|
| 118 | 1 | $dsn .= ';charset=' . $options['charset']; |
|
| 119 | } |
||
| 120 | |||
| 121 | 80 | $driverOptions = []; |
|
| 122 | 80 | ||
| 123 | 80 | // use custom data fetch mode |
|
| 124 | if (!empty($options['fetch_mode'])) { |
||
| 125 | $driverOptions[PDO::ATTR_DEFAULT_FETCH_MODE] = constant('\PDO::FETCH_' . strtoupper($options['fetch_mode'])); |
||
| 126 | } |
||
| 127 | |||
| 128 | 81 | // support arbitrary \PDO::MYSQL_ATTR_* driver options and pass them to PDO |
|
| 129 | // http://php.net/manual/en/ref.pdo-mysql.php#pdo-mysql.constants |
||
| 130 | 81 | foreach ($options as $key => $option) { |
|
| 131 | 81 | if (strpos($key, 'mysql_attr_') === 0) { |
|
| 132 | $pdoConstant = '\PDO::' . strtoupper($key); |
||
| 133 | if (!defined($pdoConstant)) { |
||
| 134 | throw new \UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); |
||
| 135 | } |
||
| 136 | 6 | $driverOptions[constant($pdoConstant)] = $option; |
|
| 137 | } |
||
| 138 | 6 | } |
|
| 139 | |||
| 140 | $db = $this->createPdoConnection($dsn, $options['user'] ?? null, $options['pass'] ?? null, $driverOptions); |
||
| 141 | |||
| 142 | $this->setConnection($db); |
||
| 143 | } |
||
| 144 | 6 | } |
|
| 145 | |||
| 146 | 6 | /** |
|
| 147 | 6 | * @inheritDoc |
|
| 148 | */ |
||
| 149 | public function disconnect() |
||
| 150 | { |
||
| 151 | $this->connection = null; |
||
| 152 | 6 | } |
|
| 153 | |||
| 154 | 6 | /** |
|
| 155 | 6 | * @inheritDoc |
|
| 156 | */ |
||
| 157 | public function hasTransactions() |
||
| 158 | { |
||
| 159 | return true; |
||
| 160 | 1 | } |
|
| 161 | |||
| 162 | 1 | /** |
|
| 163 | 1 | * @inheritDoc |
|
| 164 | */ |
||
| 165 | public function beginTransaction() |
||
| 166 | { |
||
| 167 | $this->execute('START TRANSACTION'); |
||
| 168 | 112 | } |
|
| 169 | |||
| 170 | 112 | /** |
|
| 171 | * @inheritDoc |
||
| 172 | */ |
||
| 173 | public function commitTransaction() |
||
| 174 | { |
||
| 175 | $this->execute('COMMIT'); |
||
| 176 | 112 | } |
|
| 177 | |||
| 178 | 112 | /** |
|
| 179 | * @inheritDoc |
||
| 180 | */ |
||
| 181 | public function rollbackTransaction() |
||
| 182 | { |
||
| 183 | $this->execute('ROLLBACK'); |
||
| 184 | 82 | } |
|
| 185 | |||
| 186 | 82 | /** |
|
| 187 | * @inheritDoc |
||
| 188 | 82 | */ |
|
| 189 | public function quoteTableName($tableName) |
||
| 190 | { |
||
| 191 | 82 | return str_replace('.', '`.`', $this->quoteColumnName($tableName)); |
|
| 192 | 82 | } |
|
| 193 | |||
| 194 | 82 | /** |
|
| 195 | * @inheritDoc |
||
| 196 | 82 | */ |
|
| 197 | public function quoteColumnName($columnName) |
||
| 198 | { |
||
| 199 | return '`' . str_replace('`', '``', $columnName) . '`'; |
||
| 200 | } |
||
| 201 | |||
| 202 | 82 | /** |
|
| 203 | * @inheritDoc |
||
| 204 | */ |
||
| 205 | public function hasTable($tableName) |
||
| 206 | 82 | { |
|
| 207 | if ($this->hasCreatedTable($tableName)) { |
||
| 208 | 82 | return true; |
|
| 209 | 82 | } |
|
| 210 | |||
| 211 | if (strpos($tableName, '.') !== false) { |
||
| 212 | 82 | [$schema, $table] = explode('.', $tableName); |
|
| 213 | 82 | $exists = $this->hasTableWithSchema($schema, $table); |
|
| 214 | 68 | // Only break here on success, because it is possible for table names to contain a dot. |
|
| 215 | 68 | if ($exists) { |
|
| 216 | 68 | return true; |
|
| 217 | 68 | } |
|
| 218 | 68 | } |
|
| 219 | |||
| 220 | 68 | $options = $this->getOptions(); |
|
| 221 | 68 | ||
| 222 | 82 | return $this->hasTableWithSchema($options['name'], $tableName); |
|
| 223 | } |
||
| 224 | 2 | ||
| 225 | 2 | /** |
|
| 226 | 2 | * @param string $schema The table schema |
|
| 227 | 2 | * @param string $tableName The table name |
|
| 228 | * |
||
| 229 | 2 | * @return bool |
|
| 230 | 2 | */ |
|
| 231 | 2 | protected function hasTableWithSchema($schema, $tableName) |
|
| 232 | { |
||
| 233 | $result = $this->fetchRow(sprintf( |
||
| 234 | "SELECT TABLE_NAME |
||
| 235 | FROM INFORMATION_SCHEMA.TABLES |
||
| 236 | 82 | WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", |
|
| 237 | 82 | $schema, |
|
| 238 | 82 | $tableName |
|
| 239 | 82 | )); |
|
| 240 | |||
| 241 | return !empty($result); |
||
| 242 | 82 | } |
|
| 243 | 82 | ||
| 244 | 82 | /** |
|
| 245 | 82 | * @inheritDoc |
|
| 246 | 82 | */ |
|
| 247 | public function createTable(Table $table, array $columns = [], array $indexes = []) |
||
| 248 | { |
||
| 249 | 82 | // This method is based on the MySQL docs here: http://dev.mysql.com/doc/refman/5.1/en/create-index.html |
|
| 250 | 2 | $defaultOptions = [ |
|
| 251 | 2 | 'engine' => 'InnoDB', |
|
| 252 | 'collation' => 'utf8_general_ci', |
||
| 253 | 82 | ]; |
|
| 254 | 82 | ||
| 255 | 82 | $options = array_merge( |
|
| 256 | 82 | $defaultOptions, |
|
| 257 | 82 | array_intersect_key($this->getOptions(), $defaultOptions), |
|
| 258 | $table->getOptions() |
||
| 259 | ); |
||
| 260 | 82 | ||
| 261 | 82 | // Add the default primary key |
|
| 262 | 82 | if (!isset($options['id']) || (isset($options['id']) && $options['id'] === true)) { |
|
| 263 | 82 | $options['id'] = 'id'; |
|
| 264 | 81 | } |
|
| 265 | 82 | ||
| 266 | if (isset($options['id']) && is_string($options['id'])) { |
||
| 267 | // Handle id => "field_name" to support AUTO_INCREMENT |
||
| 268 | 2 | $column = new Column(); |
|
| 269 | 2 | $column->setName($options['id']) |
|
| 270 | 2 | ->setType('integer') |
|
| 271 | 2 | ->setSigned(isset($options['signed']) ? $options['signed'] : true) |
|
| 272 | 2 | ->setIdentity(true); |
|
| 273 | 2 | ||
| 274 | 2 | array_unshift($columns, $column); |
|
| 275 | 2 | if (isset($options['primary_key']) && (array)$options['id'] !== (array)$options['primary_key']) { |
|
| 276 | 2 | throw new InvalidArgumentException('You cannot enable an auto incrementing ID field and a primary key'); |
|
| 277 | 2 | } |
|
| 278 | 82 | $options['primary_key'] = $options['id']; |
|
| 279 | 82 | } |
|
| 280 | 1 | ||
| 281 | // open: process table options like collation etc |
||
| 282 | |||
| 283 | // process table engine (default to InnoDB) |
||
| 284 | 82 | $optionsStr = 'ENGINE = InnoDB'; |
|
| 285 | 82 | if (isset($options['engine'])) { |
|
| 286 | 10 | $optionsStr = sprintf('ENGINE = %s', $options['engine']); |
|
| 287 | 82 | } |
|
| 288 | |||
| 289 | // process table collation |
||
| 290 | 82 | if (isset($options['collation'])) { |
|
| 291 | 82 | $charset = explode('_', $options['collation']); |
|
| 292 | 2 | $optionsStr .= sprintf(' CHARACTER SET %s', $charset[0]); |
|
| 293 | 82 | $optionsStr .= sprintf(' COLLATE %s', $options['collation']); |
|
| 294 | } |
||
| 295 | 82 | ||
| 296 | 82 | // set the table comment |
|
| 297 | if (isset($options['comment'])) { |
||
| 298 | $optionsStr .= sprintf(' COMMENT=%s ', $this->getConnection()->quote($options['comment'])); |
||
| 299 | 82 | } |
|
| 300 | 82 | ||
| 301 | // set the table row format |
||
| 302 | if (isset($options['row_format'])) { |
||
| 303 | $optionsStr .= sprintf(' ROW_FORMAT=%s ', $options['row_format']); |
||
| 304 | } |
||
| 305 | 5 | ||
| 306 | $sql = 'CREATE TABLE '; |
||
| 307 | 5 | $sql .= $this->quoteTableName($table->getName()) . ' ('; |
|
| 308 | 5 | foreach ($columns as $column) { |
|
| 309 | $sql .= $this->quoteColumnName($column->getName()) . ' ' . $this->getColumnSqlDefinition($column) . ', '; |
||
| 310 | } |
||
| 311 | |||
| 312 | // set the primary key(s) |
||
| 313 | 5 | if (isset($options['primary_key'])) { |
|
| 314 | $sql = rtrim($sql); |
||
| 315 | 5 | $sql .= ' PRIMARY KEY ('; |
|
| 316 | 5 | if (is_string($options['primary_key'])) { // handle primary_key => 'id' |
|
| 317 | $sql .= $this->quoteColumnName($options['primary_key']); |
||
| 318 | } elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id') |
||
| 319 | $sql .= implode(',', array_map([$this, 'quoteColumnName'], $options['primary_key'])); |
||
| 320 | } |
||
| 321 | 1 | $sql .= ')'; |
|
| 322 | } else { |
||
| 323 | 1 | $sql = substr(rtrim($sql), 0, -1); // no primary keys |
|
| 324 | 1 | } |
|
| 325 | 1 | ||
| 326 | 1 | // set the indexes |
|
| 327 | foreach ($indexes as $index) { |
||
| 328 | 1 | $sql .= ', ' . $this->getIndexSqlDefinition($index); |
|
| 329 | 1 | } |
|
| 330 | |||
| 331 | $sql .= ') ' . $optionsStr; |
||
| 332 | $sql = rtrim($sql); |
||
| 333 | |||
| 334 | 12 | // execute the sql |
|
| 335 | $this->execute($sql); |
||
| 336 | 12 | ||
| 337 | 12 | $this->addCreatedTable($table->getName()); |
|
| 338 | 12 | } |
|
| 339 | 12 | ||
| 340 | /** |
||
| 341 | 12 | * {@inheritDoc} |
|
| 342 | 12 | * |
|
| 343 | 12 | * @throws \InvalidArgumentException |
|
| 344 | 12 | */ |
|
| 345 | 12 | protected function getChangePrimaryKeyInstructions(Table $table, $newColumns) |
|
| 346 | 12 | { |
|
| 347 | $instructions = new AlterInstructions(); |
||
| 348 | 12 | ||
| 349 | 12 | // Drop the existing primary key |
|
| 350 | 12 | $primaryKey = $this->getPrimaryKey($table->getName()); |
|
| 351 | if (!empty($primaryKey['columns'])) { |
||
| 352 | 12 | $instructions->addAlter('DROP PRIMARY KEY'); |
|
| 353 | 3 | } |
|
| 354 | 3 | ||
| 355 | // Add the primary key(s) |
||
| 356 | 12 | if (!empty($newColumns)) { |
|
| 357 | 12 | $sql = 'ADD PRIMARY KEY ('; |
|
| 358 | if (is_string($newColumns)) { // handle primary_key => 'id' |
||
| 359 | 12 | $sql .= $this->quoteColumnName($newColumns); |
|
| 360 | } elseif (is_array($newColumns)) { // handle primary_key => array('tag_id', 'resource_id') |
||
| 361 | $sql .= implode(',', array_map([$this, 'quoteColumnName'], $newColumns)); |
||
| 362 | } else { |
||
| 363 | throw new InvalidArgumentException(sprintf( |
||
| 364 | 'Invalid value for primary key: %s', |
||
| 365 | 79 | json_encode($newColumns) |
|
| 366 | )); |
||
| 367 | 79 | } |
|
| 368 | 79 | $sql .= ')'; |
|
| 369 | 79 | $instructions->addAlter($sql); |
|
| 370 | 77 | } |
|
| 371 | |||
| 372 | 77 | return $instructions; |
|
| 373 | } |
||
| 374 | 21 | ||
| 375 | /** |
||
| 376 | * @inheritDoc |
||
| 377 | */ |
||
| 378 | protected function getChangeCommentInstructions(Table $table, $newComment) |
||
| 379 | { |
||
| 380 | $instructions = new AlterInstructions(); |
||
| 381 | |||
| 382 | // passing 'null' is to remove table comment |
||
| 383 | 95 | $newComment = ($newComment !== null) |
|
| 384 | ? $newComment |
||
| 385 | 95 | : ''; |
|
| 386 | 10 | $sql = sprintf(' COMMENT=%s ', $this->getConnection()->quote($newComment)); |
|
| 387 | 95 | $instructions->addAlter($sql); |
|
| 388 | 79 | ||
| 389 | 79 | return $instructions; |
|
| 390 | 95 | } |
|
| 391 | |||
| 392 | /** |
||
| 393 | * @inheritDoc |
||
| 394 | */ |
||
| 395 | protected function getRenameTableInstructions($tableName, $newTableName) |
||
| 396 | 18 | { |
|
| 397 | $this->updateCreatedTableName($tableName, $newTableName); |
||
| 398 | 18 | $sql = sprintf( |
|
| 399 | 18 | 'RENAME TABLE %s TO %s', |
|
| 400 | 18 | $this->quoteTableName($tableName), |
|
| 401 | 18 | $this->quoteTableName($newTableName) |
|
| 402 | 18 | ); |
|
| 403 | 18 | ||
| 404 | return new AlterInstructions([], [$sql]); |
||
| 405 | 18 | } |
|
| 406 | 2 | ||
| 407 | 2 | /** |
|
| 408 | * @inheritDoc |
||
| 409 | 18 | */ |
|
| 410 | 18 | protected function getDropTableInstructions($tableName) |
|
| 411 | { |
||
| 412 | $this->removeCreatedTable($tableName); |
||
| 413 | $sql = sprintf('DROP TABLE %s', $this->quoteTableName($tableName)); |
||
| 414 | |||
| 415 | 7 | return new AlterInstructions([], [$sql]); |
|
| 416 | } |
||
| 417 | 7 | ||
| 418 | 7 | /** |
|
| 419 | 7 | * @inheritDoc |
|
| 420 | 5 | */ |
|
| 421 | 5 | public function truncateTable($tableName) |
|
| 422 | 5 | { |
|
| 423 | 1 | $sql = sprintf( |
|
| 424 | 1 | 'TRUNCATE TABLE %s', |
|
| 425 | 5 | $this->quoteTableName($tableName) |
|
| 426 | ); |
||
| 427 | 5 | ||
| 428 | 5 | $this->execute($sql); |
|
| 429 | 5 | } |
|
| 430 | 5 | ||
| 431 | 5 | /** |
|
| 432 | 5 | * @inheritDoc |
|
| 433 | */ |
||
| 434 | 5 | public function getColumns($tableName) |
|
| 463 | |||
| 464 | /** |
||
| 465 | * @inheritDoc |
||
| 466 | */ |
||
| 467 | 5 | public function hasColumn($tableName, $columnName) |
|
| 478 | |||
| 479 | /** |
||
| 480 | * @inheritDoc |
||
| 481 | */ |
||
| 482 | protected function getAddColumnInstructions(Table $table, Column $column) |
||
| 483 | { |
||
| 484 | 19 | $alter = sprintf( |
|
| 485 | 'ADD %s %s', |
||
| 486 | 19 | $this->quoteColumnName($column->getName()), |
|
| 487 | 19 | $this->getColumnSqlDefinition($column) |
|
| 488 | 19 | ); |
|
| 489 | 18 | ||
| 490 | 18 | $alter .= $this->afterClause($column); |
|
| 491 | 18 | ||
| 492 | 18 | return new AlterInstructions([$alter]); |
|
| 493 | 19 | } |
|
| 494 | 19 | ||
| 495 | /** |
||
| 496 | * Exposes the MySQL syntax to arrange a column `FIRST`. |
||
| 497 | * |
||
| 498 | * @param Column $column The column being altered. |
||
| 499 | * |
||
| 500 | 14 | * @return string The appropriate SQL fragment. |
|
| 501 | */ |
||
| 502 | 14 | protected function afterClause(Column $column) |
|
| 515 | 11 | ||
| 516 | /** |
||
| 517 | * {@inheritDoc} |
||
| 518 | * |
||
| 519 | * @throws \InvalidArgumentException |
||
| 520 | */ |
||
| 521 | 1 | protected function getRenameColumnInstructions($tableName, $columnName, $newColumnName) |
|
| 551 | 3 | ||
| 552 | /** |
||
| 553 | 3 | * @inheritDoc |
|
| 554 | 2 | */ |
|
| 555 | 2 | protected function getChangeColumnInstructions($tableName, $columnName, Column $newColumn) |
|
| 567 | 3 | ||
| 568 | 3 | /** |
|
| 569 | 3 | * @inheritDoc |
|
| 570 | */ |
||
| 571 | 3 | protected function getDropColumnInstructions($tableName, $columnName) |
|
| 577 | 2 | ||
| 578 | /** |
||
| 579 | 2 | * Get an array of indexes from a particular table. |
|
| 580 | * |
||
| 581 | 2 | * @param string $tableName Table name |
|
| 582 | * |
||
| 583 | 2 | * @return array |
|
| 584 | 2 | */ |
|
| 585 | 2 | protected function getIndexes($tableName) |
|
| 598 | |||
| 599 | 21 | /** |
|
| 600 | * @inheritDoc |
||
| 601 | 21 | */ |
|
| 602 | 5 | public function hasIndex($tableName, $columns) |
|
| 619 | |||
| 620 | /** |
||
| 621 | * @inheritDoc |
||
| 622 | */ |
||
| 623 | public function hasIndexByName($tableName, $indexName) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * @inheritDoc |
||
| 638 | */ |
||
| 639 | protected function getAddIndexInstructions(Table $table, Index $index) |
||
| 664 | 15 | ||
| 665 | /** |
||
| 666 | * {@inheritDoc} |
||
| 667 | * |
||
| 668 | * @throws \InvalidArgumentException |
||
| 669 | 8 | */ |
|
| 670 | protected function getDropIndexByColumnsInstructions($tableName, $columns) |
||
| 693 | |||
| 694 | /** |
||
| 695 | 7 | * {@inheritDoc} |
|
| 696 | 7 | * |
|
| 697 | * @throws \InvalidArgumentException |
||
| 698 | 7 | */ |
|
| 699 | 7 | protected function getDropIndexByNameInstructions($tableName, $indexName) |
|
| 717 | |||
| 718 | 96 | /** |
|
| 719 | 9 | * @inheritDoc |
|
| 720 | */ |
||
| 721 | public function hasPrimaryKey($tableName, $columns, $constraint = null) |
||
| 740 | |||
| 741 | 95 | /** |
|
| 742 | 1 | * Get the primary key from a particular table. |
|
| 743 | * |
||
| 744 | * @param string $tableName Table name |
||
| 745 | 1 | * |
|
| 746 | 1 | * @return array |
|
| 747 | 1 | */ |
|
| 748 | 1 | public function getPrimaryKey($tableName) |
|
| 775 | 6 | ||
| 776 | 2 | /** |
|
| 777 | 2 | * @inheritDoc |
|
| 778 | 6 | */ |
|
| 779 | public function hasForeignKey($tableName, $columns, $constraint = null) |
||
| 801 | 83 | ||
| 802 | 4 | /** |
|
| 803 | * Get an array of foreign keys from a particular table. |
||
| 804 | 83 | * |
|
| 805 | 4 | * @param string $tableName Table name |
|
| 806 | * |
||
| 807 | 83 | * @return array |
|
| 808 | 80 | */ |
|
| 809 | protected function getForeignKeys($tableName) |
||
| 840 | |||
| 841 | /** |
||
| 842 | * @inheritDoc |
||
| 843 | */ |
||
| 844 | protected function getAddForeignKeyInstructions(Table $table, ForeignKey $foreignKey) |
||
| 853 | 16 | ||
| 854 | 16 | /** |
|
| 855 | 16 | * @inheritDoc |
|
| 856 | 14 | */ |
|
| 857 | 14 | protected function getDropForeignKeyInstructions($tableName, $constraint) |
|
| 866 | 16 | ||
| 867 | 6 | /** |
|
| 868 | 6 | * {@inheritDoc} |
|
| 869 | 3 | * |
|
| 870 | 3 | * @throws \InvalidArgumentException |
|
| 871 | 6 | */ |
|
| 872 | 16 | protected function getDropForeignKeyByColumnsInstructions($tableName, $columns) |
|
| 904 | 6 | ||
| 905 | 10 | /** |
|
| 906 | 2 | * {@inheritDoc} |
|
| 907 | 2 | * |
|
| 908 | 10 | * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException |
|
| 909 | 1 | */ |
|
| 910 | 1 | public function getSqlType($type, $limit = null) |
|
| 1056 | 16 | ||
| 1057 | 5 | /** |
|
| 1058 | 5 | * Returns Phinx type by SQL type |
|
| 1059 | * |
||
| 1060 | 16 | * @internal param string $sqlType SQL type |
|
| 1061 | * |
||
| 1062 | 16 | * @param string $sqlTypeDef SQL Type definition |
|
| 1063 | * |
||
| 1064 | * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException |
||
| 1065 | * |
||
| 1066 | * @return array Phinx type |
||
| 1067 | */ |
||
| 1068 | public function getPhinxType($sqlTypeDef) |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * @inheritDoc |
||
| 1244 | */ |
||
| 1245 | public function createDatabase($name, $options = []) |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * @inheritDoc |
||
| 1263 | */ |
||
| 1264 | public function hasDatabase($name) |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * @inheritDoc |
||
| 1284 | */ |
||
| 1285 | public function dropDatabase($name) |
||
| 1290 | |||
| 1291 | /** |
||
| 1292 | * Gets the MySQL Column Definition for a Column object. |
||
| 1293 | * |
||
| 1294 | * @param \Phinx\Db\Table\Column $column Column |
||
| 1295 | * |
||
| 1296 | * @return string |
||
| 1297 | */ |
||
| 1298 | protected function getColumnSqlDefinition(Column $column) |
||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * Gets the MySQL Index Definition for an Index object. |
||
| 1354 | * |
||
| 1355 | * @param \Phinx\Db\Table\Index $index Index |
||
| 1356 | * |
||
| 1357 | * @return string |
||
| 1358 | */ |
||
| 1359 | protected function getIndexSqlDefinition(Index $index) |
||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Gets the MySQL Foreign Key Definition for an ForeignKey object. |
||
| 1412 | * |
||
| 1413 | * @param \Phinx\Db\Table\ForeignKey $foreignKey Foreign key |
||
| 1414 | * |
||
| 1415 | * @return string |
||
| 1416 | */ |
||
| 1417 | protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) |
||
| 1442 | |||
| 1443 | /** |
||
| 1444 | * Describes a database table. This is a MySQL adapter specific method. |
||
| 1445 | * |
||
| 1446 | * @param string $tableName Table name |
||
| 1447 | * |
||
| 1448 | * @return array |
||
| 1449 | */ |
||
| 1450 | public function describeTable($tableName) |
||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Returns MySQL column types (inherited and MySQL specified). |
||
| 1469 | * |
||
| 1470 | * @return string[] |
||
| 1471 | */ |
||
| 1472 | public function getColumnTypes() |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * @inheritDoc |
||
| 1479 | */ |
||
| 1480 | public function getDecoratedConnection() |
||
| 1495 | } |
||
| 1496 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.