diff options
author | MaurĂcio Meneghini Fauth <mauricio@fauth.dev> | 2022-11-09 04:28:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 04:28:12 +0300 |
commit | 1be99c9e3104bb458498405b134429096939ea44 (patch) | |
tree | 0d4b52136a184965ce192fad34f3a232fbb80a7a | |
parent | 2cc3bf4778b2e6d6200cccaf89b852839cf9004f (diff) | |
parent | 81bc60f7e0f3a28b04ecb15bcb55c20239d1cde0 (diff) |
Merge pull request #17882 from kamil-tekiela/Refactor-index-controllers
Refactor index controllers
-rw-r--r-- | libraries/classes/Index.php | 10 | ||||
-rw-r--r-- | libraries/classes/Table.php | 23 | ||||
-rw-r--r-- | psalm-baseline.xml | 12 | ||||
-rw-r--r-- | test/classes/TableTest.php | 4 |
4 files changed, 19 insertions, 30 deletions
diff --git a/libraries/classes/Index.php b/libraries/classes/Index.php index 94cb50b641..03f1b20d67 100644 --- a/libraries/classes/Index.php +++ b/libraries/classes/Index.php @@ -88,14 +88,14 @@ class Index * * @var int */ - private $keyBlockSize = null; + private $keyBlockSize = 0; /** * Parser option for the index * * @var string */ - private $parser = null; + private $parser = ''; /** * @param array $params parameters @@ -341,7 +341,7 @@ class Index } if (isset($params['Key_block_size'])) { - $this->keyBlockSize = $params['Key_block_size']; + $this->keyBlockSize = (int) $params['Key_block_size']; } if (! isset($params['Parser'])) { @@ -383,10 +383,8 @@ class Index /** * Return the key block size - * - * @return int */ - public function getKeyBlockSize() + public function getKeyBlockSize(): int { return $this->keyBlockSize; } diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index a7f6e19f39..00fd96b6e1 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -2098,11 +2098,11 @@ class Table implements Stringable } $sqlQuery .= sprintf( - ' ADD %s ', + ' ADD %s', $index->getChoice() ); if ($index->getName()) { - $sqlQuery .= Util::backquote($index->getName()); + $sqlQuery .= ' ' . Util::backquote($index->getName()); } break; @@ -2118,18 +2118,15 @@ class Table implements Stringable $indexFields[$key] .= '(' . $column->getSubPart() . ')'; } - if (empty($indexFields)) { + if ($indexFields === []) { $error = Message::error(__('No index parts defined!')); } else { $sqlQuery .= ' (' . implode(', ', $indexFields) . ')'; } $keyBlockSizes = $index->getKeyBlockSize(); - if (! empty($keyBlockSizes)) { - $sqlQuery .= sprintf( - ' KEY_BLOCK_SIZE = %s', - $this->dbi->escapeString((string) $keyBlockSizes) - ); + if ($keyBlockSizes !== 0) { + $sqlQuery .= ' KEY_BLOCK_SIZE = ' . $keyBlockSizes; } // specifying index type is allowed only for primary, unique and index only @@ -2146,15 +2143,15 @@ class Table implements Stringable } $parser = $index->getParser(); - if ($index->getChoice() === 'FULLTEXT' && ! empty($parser)) { - $sqlQuery .= ' WITH PARSER ' . $this->dbi->escapeString($parser); + if ($index->getChoice() === 'FULLTEXT' && $parser !== '') { + $sqlQuery .= ' WITH PARSER ' . $parser; } $comment = $index->getComment(); - if (! empty($comment)) { + if ($comment !== '') { $sqlQuery .= sprintf( - " COMMENT '%s'", - $this->dbi->escapeString($comment) + ' COMMENT %s', + $this->dbi->quoteString($comment) ); } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 26b70f9a7a..6fc90734b9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -8012,14 +8012,13 @@ <MixedArrayOffset occurrences="1"> <code>$columns['sub_parts'][$key]</code> </MixedArrayOffset> - <MixedAssignment occurrences="15"> + <MixedAssignment occurrences="14"> <code>$column</code> <code>$key</code> <code>$name</code> <code>$sub_part</code> <code>$this->choice</code> <code>$this->comment</code> - <code>$this->keyBlockSize</code> <code>$this->name</code> <code>$this->nonUnique</code> <code>$this->packed</code> @@ -8032,9 +8031,7 @@ <PossiblyNullOperand occurrences="1"> <code>$params['Seq_in_index']</code> </PossiblyNullOperand> - <PossiblyNullPropertyAssignmentValue occurrences="3"> - <code>null</code> - <code>null</code> + <PossiblyNullPropertyAssignmentValue occurrences="1"> <code>null</code> </PossiblyNullPropertyAssignmentValue> <RedundantCastGivenDocblockType occurrences="1"> @@ -13416,10 +13413,7 @@ </PossiblyNullArgument> </file> <file src="libraries/classes/Table.php"> - <DeprecatedMethod occurrences="52"> - <code>escapeString</code> - <code>escapeString</code> - <code>escapeString</code> + <DeprecatedMethod occurrences="49"> <code>escapeString</code> <code>escapeString</code> <code>escapeString</code> diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php index bfb642cf57..434b66f8f0 100644 --- a/test/classes/TableTest.php +++ b/test/classes/TableTest.php @@ -1308,7 +1308,7 @@ class TableTest extends AbstractTestCase $table = new Table($table, $db, $GLOBALS['dbi']); $sql = $table->getSqlQueryForIndexCreateOrEdit($index, $error); - $this->assertEquals('ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE ;', $sql); + $this->assertEquals('ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE;', $sql); } /** @@ -1326,7 +1326,7 @@ class TableTest extends AbstractTestCase $table = new Table($table, $db, $GLOBALS['dbi']); $sql = $table->getSqlQueryForIndexCreateOrEdit($index, $error); - $this->assertEquals('ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE ;', $sql); + $this->assertEquals('ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE;', $sql); } /** |