From b6bea791aa70021199c1160f2a098928c45cd37c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 30 Sep 2024 14:11:01 +0100 Subject: [PATCH] Split getForeigners into getForeignersInternal Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 34 ++------------------ psalm-baseline.xml | 10 ------ src/ConfigStorage/Relation.php | 25 ++++++++++---- src/Controllers/Table/RelationController.php | 4 +-- src/Database/Designer/Common.php | 2 +- src/Display/Results.php | 2 +- src/Operations.php | 2 +- src/Plugins/Export/ExportSql.php | 2 +- src/Plugins/Schema/Dia/DiaRelationSchema.php | 2 +- src/Plugins/Schema/Eps/EpsRelationSchema.php | 2 +- src/Plugins/Schema/Pdf/PdfRelationSchema.php | 4 +-- src/Plugins/Schema/Svg/SvgRelationSchema.php | 2 +- 12 files changed, 31 insertions(+), 60 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6f0c17204e..001bdbf28a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10682,12 +10682,12 @@ parameters: - message: "#^Cannot access offset mixed on mixed\\.$#" - count: 13 + count: 3 path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - message: "#^Cannot access offset string on mixed\\.$#" - count: 4 + count: 14 path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - @@ -10720,11 +10720,6 @@ parameters: count: 3 path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - message: "#^Parameter \\#1 \\$txt of method TCPDF\\:\\:Bookmark\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - message: "#^Parameter \\#1 \\$value of method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:setTableOrder\\(\\) expects string, mixed given\\.$#" count: 1 @@ -10740,31 +10735,6 @@ parameters: count: 1 path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:getComments\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:getForeigners\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumns\\(\\) expects string, mixed given\\.$#" - count: 2 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Transformations\\:\\:getMime\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - - - message: "#^Parameter \\#2 \\$tableName of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTable\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Plugins/Schema/Pdf/PdfRelationSchema.php - - message: "#^Parameter \\#4 \\$foreignField of method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:addRelation\\(\\) expects string, mixed given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 47a209bfa7..62ecb5480e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -9238,9 +9238,6 @@ - - - pdf->customLinks['RT']['-']]]> pdf->customLinks['doc'][$table][$fieldName]]]> pdf->customLinks['doc'][$table]['-']]]> @@ -9272,20 +9269,15 @@ - pdf->customLinks['RT'][$table]]]> pdf->customLinks['doc'][$foreigner['foreign_table']]]]> pdf->customLinks['doc'][$foreigner['foreign_table']]]]> pdf->customLinks['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]]]> - pdf->customLinks['doc'][$table]]]> - pdf->customLinks['doc'][$table]]]> - - @@ -9294,8 +9286,6 @@ - - diff --git a/src/ConfigStorage/Relation.php b/src/ConfigStorage/Relation.php index f42b4dd5c4..13ff2bd961 100644 --- a/src/ConfigStorage/Relation.php +++ b/src/ConfigStorage/Relation.php @@ -369,12 +369,27 @@ class Relation * @param string $db the name of the db to check for * @param string $table the name of the table to check for * @param string $column the name of the column to check for - * @param string $source the source for foreign key information - * @psalm-param 'both'|'internal' $source * * @return array> */ - public function getForeigners(string $db, string $table, string $column = '', string $source = 'both'): array + public function getForeigners(string $db, string $table, string $column = ''): array + { + $foreign = $this->getForeignersInternal($db, $table, $column); + + if ($table !== '') { + $foreign['foreign_keys_data'] = $this->getForeignKeysData($db, $table); + } + + return $foreign; + } + + /** + * Gets all Relations to foreign tables for a given table or + * optionally a given column in a table + * + * @return array> + */ + public function getForeignersInternal(string $db, string $table, string $column = ''): array { $relationFeature = $this->getRelationParameters()->relationFeature; $foreign = []; @@ -394,10 +409,6 @@ class Relation $foreign = $this->dbi->fetchResult($relQuery, 'master_field', null, ConnectionType::ControlUser); } - if ($source === 'both' && $table !== '') { - $foreign['foreign_keys_data'] = $this->getForeignKeysData($db, $table); - } - /** * Emulating relations for some information_schema tables */ diff --git a/src/Controllers/Table/RelationController.php b/src/Controllers/Table/RelationController.php index 64ce9ee455..314e507ed9 100644 --- a/src/Controllers/Table/RelationController.php +++ b/src/Controllers/Table/RelationController.php @@ -66,7 +66,7 @@ final class RelationController implements InvocableController $relations = []; if ($relationParameters->relationFeature !== null) { - $relations = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal'); + $relations = $this->relation->getForeignersInternal(Current::$database, Current::$table); } $relationsForeign = []; @@ -149,7 +149,7 @@ final class RelationController implements InvocableController // If we did an update, refresh our data if (isset($_POST['destination_db']) && $relationParameters->relationFeature !== null) { - $relations = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal'); + $relations = $this->relation->getForeignersInternal(Current::$database, Current::$table); } if (isset($_POST['destination_foreign_db']) && ForeignKey::isSupported($storageEngine)) { diff --git a/src/Database/Designer/Common.php b/src/Database/Designer/Common.php index 017068ea02..8e05a8dd93 100644 --- a/src/Database/Designer/Common.php +++ b/src/Database/Designer/Common.php @@ -116,7 +116,7 @@ class Common while ($val = $allTabRs->fetchRow()) { $val = (string) $val[0]; - $row = $this->relation->getForeigners(Current::$database, $val, '', 'internal'); + $row = $this->relation->getForeignersInternal(Current::$database, $val); foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; diff --git a/src/Display/Results.php b/src/Display/Results.php index eec4d8cd9a..b077601f40 100644 --- a/src/Display/Results.php +++ b/src/Display/Results.php @@ -3478,7 +3478,7 @@ class Results // the name related to a numeric id). $map = []; - foreach ($this->relation->getForeigners($this->db, $this->table, '', 'internal') as $masterField => $rel) { + foreach ($this->relation->getForeignersInternal($this->db, $this->table) as $masterField => $rel) { $map[$masterField] = new ForeignKeyRelatedTable( $rel['foreign_table'], $rel['foreign_field'], diff --git a/src/Operations.php b/src/Operations.php index 4b37714c7e..8d940be77b 100644 --- a/src/Operations.php +++ b/src/Operations.php @@ -555,7 +555,7 @@ class Operations $foreigners = []; $this->dbi->selectDb(Current::$database); - $foreign = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal'); + $foreign = $this->relation->getForeignersInternal(Current::$database, Current::$table); foreach ($foreign as $master => $arr) { $joinQuery = 'SELECT ' diff --git a/src/Plugins/Export/ExportSql.php b/src/Plugins/Export/ExportSql.php index 099ab1e9e7..08f069ca77 100644 --- a/src/Plugins/Export/ExportSql.php +++ b/src/Plugins/Export/ExportSql.php @@ -1778,7 +1778,7 @@ class ExportSql extends ExportPlugin // Check if we can use Relations $foreigners = $doRelation && $relationParameters->relationFeature !== null ? - $this->relation->getForeigners($db, $table, '', 'internal') + $this->relation->getForeignersInternal($db, $table) : []; if ($foreigners !== []) { diff --git a/src/Plugins/Schema/Dia/DiaRelationSchema.php b/src/Plugins/Schema/Dia/DiaRelationSchema.php index 78cc9f2098..3b98e51a60 100644 --- a/src/Plugins/Schema/Dia/DiaRelationSchema.php +++ b/src/Plugins/Schema/Dia/DiaRelationSchema.php @@ -92,7 +92,7 @@ class DiaRelationSchema extends ExportRelationSchema $seenARelation = false; foreach ($alltables as $oneTable) { - $existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal'); + $existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable); $seenARelation = true; foreach ($existRel as $masterField => $rel) { diff --git a/src/Plugins/Schema/Eps/EpsRelationSchema.php b/src/Plugins/Schema/Eps/EpsRelationSchema.php index 8e27563f72..9dd725f5ae 100644 --- a/src/Plugins/Schema/Eps/EpsRelationSchema.php +++ b/src/Plugins/Schema/Eps/EpsRelationSchema.php @@ -98,7 +98,7 @@ class EpsRelationSchema extends ExportRelationSchema $seenARelation = false; foreach ($alltables as $oneTable) { - $existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal'); + $existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable); $seenARelation = true; foreach ($existRel as $masterField => $rel) { diff --git a/src/Plugins/Schema/Pdf/PdfRelationSchema.php b/src/Plugins/Schema/Pdf/PdfRelationSchema.php index 1689dea4ed..5b705c760c 100644 --- a/src/Plugins/Schema/Pdf/PdfRelationSchema.php +++ b/src/Plugins/Schema/Pdf/PdfRelationSchema.php @@ -196,7 +196,7 @@ class PdfRelationSchema extends ExportRelationSchema // and finding its foreigns is OK (then we can support innodb) $seenARelation = false; foreach ($alltables as $oneTable) { - $existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal'); + $existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable); $seenARelation = true; foreach ($existRel as $masterField => $rel) { @@ -438,7 +438,7 @@ class PdfRelationSchema extends ExportRelationSchema /** * Generates data dictionary pages. * - * @param mixed[] $alltables Tables to document. + * @param string[] $alltables Tables to document. */ public function dataDictionaryDoc(array $alltables): void { diff --git a/src/Plugins/Schema/Svg/SvgRelationSchema.php b/src/Plugins/Schema/Svg/SvgRelationSchema.php index f066465418..fa9d050864 100644 --- a/src/Plugins/Schema/Svg/SvgRelationSchema.php +++ b/src/Plugins/Schema/Svg/SvgRelationSchema.php @@ -113,7 +113,7 @@ class SvgRelationSchema extends ExportRelationSchema $seenARelation = false; foreach ($alltables as $oneTable) { - $existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal'); + $existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable); if ($existRel === []) { continue; }