Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-08 05:25:20 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-08 05:25:20 +0300
commitd6b72de8aa4bc9e07869f75d4490d74deeb5b41a (patch)
tree08e8062ba90cb1371e6c60391aab659bccd4816a /libraries
parent9d2350d28c3617631bdf1b06ecb7211df82d646d (diff)
Improve return type of Index::getPrimary method
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/classes/Controllers/Table/RelationController.php3
-rw-r--r--libraries/classes/Controllers/Table/StructureController.php13
-rw-r--r--libraries/classes/Index.php15
-rw-r--r--libraries/classes/Normalization.php12
-rw-r--r--libraries/classes/Sql.php2
5 files changed, 17 insertions, 28 deletions
diff --git a/libraries/classes/Controllers/Table/RelationController.php b/libraries/classes/Controllers/Table/RelationController.php
index 3ecf4501cc..48d94bb7ad 100644
--- a/libraries/classes/Controllers/Table/RelationController.php
+++ b/libraries/classes/Controllers/Table/RelationController.php
@@ -358,9 +358,8 @@ final class RelationController extends AbstractController
$this->response->addJSON('columns', $columnList);
- // @todo should be: $server->db($db)->table($table)->primary()
$primary = Index::getPrimary($this->dbi, $foreignTable, $_POST['foreignDb']);
- if ($primary === false) {
+ if ($primary === null) {
return;
}
diff --git a/libraries/classes/Controllers/Table/StructureController.php b/libraries/classes/Controllers/Table/StructureController.php
index fd071eedc7..e9b7628d33 100644
--- a/libraries/classes/Controllers/Table/StructureController.php
+++ b/libraries/classes/Controllers/Table/StructureController.php
@@ -158,10 +158,9 @@ class StructureController extends AbstractController
/**
* Displays the table structure ('show table' works correct since 3.23.03)
*
- * @param array $columns_with_unique_index Columns with unique index
- * @param Index|false $primary_index primary index or false if no one exists
- * @param array $fields Fields
- * @param array $columns_with_index Columns with index
+ * @param array $columns_with_unique_index Columns with unique index
+ * @param array $fields Fields
+ * @param array $columns_with_index Columns with index
* @psalm-param non-empty-string $route
*
* @return string
@@ -169,7 +168,7 @@ class StructureController extends AbstractController
protected function displayStructure(
RelationParameters $relationParameters,
array $columns_with_unique_index,
- $primary_index,
+ ?Index $primaryIndex,
array $fields,
array $columns_with_index,
bool $isSystemSchema,
@@ -234,7 +233,7 @@ class StructureController extends AbstractController
$row_comments[$rownum] = $comments_map[$field['Field']];
}
- if ($primary_index && $primary_index->hasColumn($field['Field'])) {
+ if ($primaryIndex !== null && $primaryIndex->hasColumn($field['Field'])) {
$displayed_fields[$rownum]->icon .= Generator::getImage('b_primary', __('Primary'));
}
@@ -272,7 +271,7 @@ class StructureController extends AbstractController
'tbl_is_view' => $GLOBALS['tbl_is_view'],
'mime_map' => $mime_map,
'tbl_storage_engine' => $GLOBALS['tbl_storage_engine'],
- 'primary' => $primary_index,
+ 'primary' => $primaryIndex,
'columns_with_unique_index' => $columns_with_unique_index,
'columns_list' => $columns_list,
'table_stats' => $tablestats ?? null,
diff --git a/libraries/classes/Index.php b/libraries/classes/Index.php
index 5f9e037ba5..b664ee0d8c 100644
--- a/libraries/classes/Index.php
+++ b/libraries/classes/Index.php
@@ -185,20 +185,11 @@ class Index
return $indexes;
}
- /**
- * return primary if set, false otherwise
- *
- * @return Index|false primary index or false if no one exists
- */
- public static function getPrimary(DatabaseInterface $dbi, string $table, string $schema)
+ public static function getPrimary(DatabaseInterface $dbi, string $table, string $schema): ?Index
{
self::loadIndexes($dbi, $table, $schema);
- if (isset(self::$registry[$schema][$table]['PRIMARY'])) {
- return self::$registry[$schema][$table]['PRIMARY'];
- }
-
- return false;
+ return self::$registry[$schema][$table]['PRIMARY'] ?? null;
}
/**
@@ -462,7 +453,7 @@ class Index
public function hasPrimary(): bool
{
- return (bool) self::getPrimary($GLOBALS['dbi'], $this->table, $this->schema);
+ return self::getPrimary($GLOBALS['dbi'], $this->table, $this->schema) !== null;
}
/**
diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php
index 0ae9bffb85..319177c0b3 100644
--- a/libraries/classes/Normalization.php
+++ b/libraries/classes/Normalization.php
@@ -277,7 +277,7 @@ class Normalization
$hasPrimaryKey = '0';
$legendText = __('Step 1.') . $step . ' ' . $stepTxt;
$extra = '';
- if ($primary !== false) {
+ if ($primary !== null) {
$headText = __('Primary key already exists.');
$subText = __('Taking you to next step…');
$hasPrimaryKey = '1';
@@ -376,7 +376,7 @@ class Normalization
. '<input class="btn btn-secondary" type="submit" value="' . __('No repeating group')
. '" onclick="goToStep4();">';
$primary = Index::getPrimary($this->dbi, $table, $db);
- $primarycols = $primary === false ? [] : $primary->getColumns();
+ $primarycols = $primary === null ? [] : $primary->getColumns();
$pk = [];
foreach ($primarycols as $col) {
$pk[] = $col->getName();
@@ -403,7 +403,7 @@ class Normalization
{
$legendText = __('Step 2.') . '1 ' . __('Find partial dependencies');
$primary = Index::getPrimary($this->dbi, $table, $db);
- $primarycols = $primary === false ? [] : $primary->getColumns();
+ $primarycols = $primary === null ? [] : $primary->getColumns();
$pk = [];
$subText = '';
$selectPkForm = '';
@@ -627,7 +627,7 @@ class Normalization
}
$primary = Index::getPrimary($this->dbi, $table, $db);
- $primarycols = $primary === false ? [] : $primary->getColumns();
+ $primarycols = $primary === null ? [] : $primary->getColumns();
$pk = [];
foreach ($primarycols as $col) {
$pk[] = $col->getName();
@@ -879,7 +879,7 @@ class Normalization
$cnt = 0;
foreach ($tables as $table) {
$primary = Index::getPrimary($this->dbi, $table, $db);
- $primarycols = $primary === false ? [] : $primary->getColumns();
+ $primarycols = $primary === null ? [] : $primary->getColumns();
$selectTdForm = '';
$pk = [];
foreach ($primarycols as $col) {
@@ -961,7 +961,7 @@ class Normalization
);
$totalRows = $totalRowsRes[0];
$primary = Index::getPrimary($this->dbi, $table, $db);
- $primarycols = $primary === false ? [] : $primary->getColumns();
+ $primarycols = $primary === null ? [] : $primary->getColumns();
$pk = [];
foreach ($primarycols as $col) {
$pk[] = Util::backquote($col->getName());
diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php
index eca4bf0628..8beae20045 100644
--- a/libraries/classes/Sql.php
+++ b/libraries/classes/Sql.php
@@ -504,7 +504,7 @@ class Sql
$primaryKey = null;
$primary = Index::getPrimary($this->dbi, $table, $db);
- if ($primary !== false) {
+ if ($primary !== null) {
$primarycols = $primary->getColumns();
foreach ($primarycols as $col) {