Skip to content

Commit 45dc648

Browse files
Merge pull request #19307 from kamil-tekiela/getForeignersInternal
Split getForeigners into getForeignersInternal
2 parents 9df8efb + b6bea79 commit 45dc648

12 files changed

Lines changed: 31 additions & 60 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10682,12 +10682,12 @@ parameters:
1068210682

1068310683
-
1068410684
message: "#^Cannot access offset mixed on mixed\\.$#"
10685-
count: 13
10685+
count: 3
1068610686
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
1068710687

1068810688
-
1068910689
message: "#^Cannot access offset string on mixed\\.$#"
10690-
count: 4
10690+
count: 14
1069110691
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
1069210692

1069310693
-
@@ -10720,11 +10720,6 @@ parameters:
1072010720
count: 3
1072110721
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
1072210722

10723-
-
10724-
message: "#^Parameter \\#1 \\$txt of method TCPDF\\:\\:Bookmark\\(\\) expects string, mixed given\\.$#"
10725-
count: 1
10726-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10727-
1072810723
-
1072910724
message: "#^Parameter \\#1 \\$value of method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:setTableOrder\\(\\) expects string, mixed given\\.$#"
1073010725
count: 1
@@ -10740,31 +10735,6 @@ parameters:
1074010735
count: 1
1074110736
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
1074210737

10743-
-
10744-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:getComments\\(\\) expects string, mixed given\\.$#"
10745-
count: 1
10746-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10747-
10748-
-
10749-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:getForeigners\\(\\) expects string, mixed given\\.$#"
10750-
count: 1
10751-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10752-
10753-
-
10754-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumns\\(\\) expects string, mixed given\\.$#"
10755-
count: 2
10756-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10757-
10758-
-
10759-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Transformations\\:\\:getMime\\(\\) expects string, mixed given\\.$#"
10760-
count: 1
10761-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10762-
10763-
-
10764-
message: "#^Parameter \\#2 \\$tableName of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTable\\(\\) expects string, mixed given\\.$#"
10765-
count: 1
10766-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
10767-
1076810738
-
1076910739
message: "#^Parameter \\#4 \\$foreignField of method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:addRelation\\(\\) expects string, mixed given\\.$#"
1077010740
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9238,9 +9238,6 @@
92389238
<MixedArgument>
92399239
<code><![CDATA[$mimeMap[$fieldName]['mimetype']]]></code>
92409240
<code><![CDATA[$rel['foreign_field']]]></code>
9241-
<code><![CDATA[$table]]></code>
9242-
<code><![CDATA[$table]]></code>
9243-
<code><![CDATA[$table]]></code>
92449241
<code><![CDATA[$this->pdf->customLinks['RT']['-']]]></code>
92459242
<code><![CDATA[$this->pdf->customLinks['doc'][$table][$fieldName]]]></code>
92469243
<code><![CDATA[$this->pdf->customLinks['doc'][$table]['-']]]></code>
@@ -9272,20 +9269,15 @@
92729269
</MixedArrayAssignment>
92739270
<MixedArrayOffset>
92749271
<code><![CDATA[$foreignTable[$foreigner['foreign_field']]]]></code>
9275-
<code><![CDATA[$this->pdf->customLinks['RT'][$table]]]></code>
92769272
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']]]]></code>
92779273
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']]]]></code>
92789274
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]]]></code>
9279-
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
9280-
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
92819275
</MixedArrayOffset>
92829276
<MixedAssignment>
92839277
<code><![CDATA[$attribute]]></code>
92849278
<code><![CDATA[$foreignTable]]></code>
92859279
<code><![CDATA[$links[0]]]></code>
92869280
<code><![CDATA[$links[6]]]></code>
9287-
<code><![CDATA[$table]]></code>
9288-
<code><![CDATA[$table]]></code>
92899281
<code><![CDATA[$type]]></code>
92909282
</MixedAssignment>
92919283
<MixedOperand>
@@ -9294,8 +9286,6 @@
92949286
<code><![CDATA[$foreigner['foreign_table']]]></code>
92959287
<code><![CDATA[$foreigner['on_delete']]]></code>
92969288
<code><![CDATA[$foreigner['on_update']]]></code>
9297-
<code><![CDATA[$table]]></code>
9298-
<code><![CDATA[$table]]></code>
92999289
</MixedOperand>
93009290
<PossiblyInvalidArgument>
93019291
<code><![CDATA[$_REQUEST['pdf_table_order']]]></code>

src/ConfigStorage/Relation.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,27 @@ public function tryUpgradeTransformations(): bool
369369
* @param string $db the name of the db to check for
370370
* @param string $table the name of the table to check for
371371
* @param string $column the name of the column to check for
372-
* @param string $source the source for foreign key information
373-
* @psalm-param 'both'|'internal' $source
374372
*
375373
* @return array<array<mixed>>
376374
*/
377-
public function getForeigners(string $db, string $table, string $column = '', string $source = 'both'): array
375+
public function getForeigners(string $db, string $table, string $column = ''): array
376+
{
377+
$foreign = $this->getForeignersInternal($db, $table, $column);
378+
379+
if ($table !== '') {
380+
$foreign['foreign_keys_data'] = $this->getForeignKeysData($db, $table);
381+
}
382+
383+
return $foreign;
384+
}
385+
386+
/**
387+
* Gets all Relations to foreign tables for a given table or
388+
* optionally a given column in a table
389+
*
390+
* @return array<array<mixed>>
391+
*/
392+
public function getForeignersInternal(string $db, string $table, string $column = ''): array
378393
{
379394
$relationFeature = $this->getRelationParameters()->relationFeature;
380395
$foreign = [];
@@ -394,10 +409,6 @@ public function getForeigners(string $db, string $table, string $column = '', st
394409
$foreign = $this->dbi->fetchResult($relQuery, 'master_field', null, ConnectionType::ControlUser);
395410
}
396411

397-
if ($source === 'both' && $table !== '') {
398-
$foreign['foreign_keys_data'] = $this->getForeignKeysData($db, $table);
399-
}
400-
401412
/**
402413
* Emulating relations for some information_schema tables
403414
*/

src/Controllers/Table/RelationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __invoke(ServerRequest $request): Response
6666

6767
$relations = [];
6868
if ($relationParameters->relationFeature !== null) {
69-
$relations = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal');
69+
$relations = $this->relation->getForeignersInternal(Current::$database, Current::$table);
7070
}
7171

7272
$relationsForeign = [];
@@ -149,7 +149,7 @@ public function __invoke(ServerRequest $request): Response
149149

150150
// If we did an update, refresh our data
151151
if (isset($_POST['destination_db']) && $relationParameters->relationFeature !== null) {
152-
$relations = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal');
152+
$relations = $this->relation->getForeignersInternal(Current::$database, Current::$table);
153153
}
154154

155155
if (isset($_POST['destination_foreign_db']) && ForeignKey::isSupported($storageEngine)) {

src/Database/Designer/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getScriptContr(array $designerTables): array
116116
while ($val = $allTabRs->fetchRow()) {
117117
$val = (string) $val[0];
118118

119-
$row = $this->relation->getForeigners(Current::$database, $val, '', 'internal');
119+
$row = $this->relation->getForeignersInternal(Current::$database, $val);
120120

121121
foreach ($row as $field => $value) {
122122
$con['C_NAME'][$i] = '';

src/Display/Results.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3478,7 +3478,7 @@ private function getForeignKeyRelatedTables(): array
34783478
// the name related to a numeric id).
34793479

34803480
$map = [];
3481-
foreach ($this->relation->getForeigners($this->db, $this->table, '', 'internal') as $masterField => $rel) {
3481+
foreach ($this->relation->getForeignersInternal($this->db, $this->table) as $masterField => $rel) {
34823482
$map[$masterField] = new ForeignKeyRelatedTable(
34833483
$rel['foreign_table'],
34843484
$rel['foreign_field'],

src/Operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public function getForeignersForReferentialIntegrityCheck(
555555

556556
$foreigners = [];
557557
$this->dbi->selectDb(Current::$database);
558-
$foreign = $this->relation->getForeigners(Current::$database, Current::$table, '', 'internal');
558+
$foreign = $this->relation->getForeignersInternal(Current::$database, Current::$table);
559559

560560
foreach ($foreign as $master => $arr) {
561561
$joinQuery = 'SELECT '

src/Plugins/Export/ExportSql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ private function getTableComments(
17781778

17791779
// Check if we can use Relations
17801780
$foreigners = $doRelation && $relationParameters->relationFeature !== null ?
1781-
$this->relation->getForeigners($db, $table, '', 'internal')
1781+
$this->relation->getForeignersInternal($db, $table)
17821782
: [];
17831783

17841784
if ($foreigners !== []) {

src/Plugins/Schema/Dia/DiaRelationSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct(Relation $relation, DatabaseName $db)
9292

9393
$seenARelation = false;
9494
foreach ($alltables as $oneTable) {
95-
$existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal');
95+
$existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable);
9696

9797
$seenARelation = true;
9898
foreach ($existRel as $masterField => $rel) {

src/Plugins/Schema/Eps/EpsRelationSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __construct(Relation $relation, DatabaseName $db)
9898

9999
$seenARelation = false;
100100
foreach ($alltables as $oneTable) {
101-
$existRel = $this->relation->getForeigners($this->db->getName(), $oneTable, '', 'internal');
101+
$existRel = $this->relation->getForeignersInternal($this->db->getName(), $oneTable);
102102

103103
$seenARelation = true;
104104
foreach ($existRel as $masterField => $rel) {

0 commit comments

Comments
 (0)