Skip to content

Commit cc76daf

Browse files
Merge pull request #18757 from MauricioFauth/schema-export-refactor
Refactor ExportRelationSchema classes
2 parents d653f93 + 129d35c commit cc76daf

16 files changed

+246
-243
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15750,11 +15750,6 @@ parameters:
1575015750
count: 1
1575115751
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
1575215752

15753-
-
15754-
message: "#^Parameter \\#2 \\$value of method PhpMyAdmin\\\\Pdf\\:\\:setAlias\\(\\) expects string, int given\\.$#"
15755-
count: 2
15756-
path: src/Plugins/Schema/Pdf/PdfRelationSchema.php
15757-
1575815753
-
1575915754
message: "#^Parameter \\#3 \\$foreignTable of method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:addRelation\\(\\) expects string, mixed given\\.$#"
1576015755
count: 2

psalm-baseline.xml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10048,7 +10048,6 @@
1004810048
<file src="src/Plugins/Schema/ExportRelationSchema.php">
1004910049
<DeprecatedMethod>
1005010050
<code>DatabaseInterface::getInstance()</code>
10051-
<code>DatabaseInterface::getInstance()</code>
1005210051
</DeprecatedMethod>
1005310052
<MixedArgument>
1005410053
<code>$table</code>
@@ -10132,10 +10131,6 @@
1013210131
<DeprecatedMethod>
1013310132
<code>DatabaseInterface::getInstance()</code>
1013410133
</DeprecatedMethod>
10135-
<InvalidArgument>
10136-
<code><![CDATA[$this->diagram->PageNo()]]></code>
10137-
<code><![CDATA[$this->diagram->PageNo()]]></code>
10138-
</InvalidArgument>
1013910134
<MixedArgument>
1014010135
<code><![CDATA[$mimeMap[$fieldName]['mimetype']]]></code>
1014110136
<code>$oneField</code>
@@ -10149,9 +10144,9 @@
1014910144
<code>$table</code>
1015010145
<code>$table</code>
1015110146
<code>$table</code>
10152-
<code><![CDATA[$this->diagram->customLinks['RT']['-']]]></code>
10153-
<code><![CDATA[$this->diagram->customLinks['doc'][$table][$fieldName]]]></code>
10154-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]['-']]]></code>
10147+
<code><![CDATA[$this->pdf->customLinks['RT']['-']]]></code>
10148+
<code><![CDATA[$this->pdf->customLinks['doc'][$table][$fieldName]]]></code>
10149+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]['-']]]></code>
1015510150
</MixedArgument>
1015610151
<MixedArgumentTypeCoercion>
1015710152
<code>$masterField</code>
@@ -10172,33 +10167,33 @@
1017210167
<code><![CDATA[$showTable['Comment']]]></code>
1017310168
<code><![CDATA[$showTable['Create_time']]]></code>
1017410169
<code><![CDATA[$showTable['Update_time']]]></code>
10175-
<code><![CDATA[$this->diagram->customLinks['RT']['-']]]></code>
10176-
<code><![CDATA[$this->diagram->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10177-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10178-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10179-
<code><![CDATA[$this->diagram->customLinks['doc'][$table][$fieldName]]]></code>
10180-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]['-']]]></code>
10170+
<code><![CDATA[$this->pdf->customLinks['RT']['-']]]></code>
10171+
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10172+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
10173+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
10174+
<code><![CDATA[$this->pdf->customLinks['doc'][$table][$fieldName]]]></code>
10175+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]['-']]]></code>
1018110176
</MixedArrayAccess>
1018210177
<MixedArrayAssignment>
10183-
<code><![CDATA[$this->diagram->customLinks['RT'][$table]]]></code>
10184-
<code><![CDATA[$this->diagram->customLinks['RT'][$table]]]></code>
10185-
<code><![CDATA[$this->diagram->customLinks['RT'][$table][$fieldName]]]></code>
10186-
<code><![CDATA[$this->diagram->customLinks['RT'][$table]['-']]]></code>
10187-
<code><![CDATA[$this->diagram->customLinks['RT']['-']]]></code>
10188-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10189-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10190-
<code><![CDATA[$this->diagram->customLinks['doc'][$table][$fieldName]]]></code>
10191-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]['-']]]></code>
10178+
<code><![CDATA[$this->pdf->customLinks['RT'][$table]]]></code>
10179+
<code><![CDATA[$this->pdf->customLinks['RT'][$table]]]></code>
10180+
<code><![CDATA[$this->pdf->customLinks['RT'][$table][$fieldName]]]></code>
10181+
<code><![CDATA[$this->pdf->customLinks['RT'][$table]['-']]]></code>
10182+
<code><![CDATA[$this->pdf->customLinks['RT']['-']]]></code>
10183+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
10184+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
10185+
<code><![CDATA[$this->pdf->customLinks['doc'][$table][$fieldName]]]></code>
10186+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]['-']]]></code>
1019210187
</MixedArrayAssignment>
1019310188
<MixedArrayOffset>
1019410189
<code><![CDATA[$foreignTable[$foreigner['foreign_field']]]]></code>
1019510190
<code><![CDATA[$oneKey['ref_index_list'][$index]]]></code>
10196-
<code><![CDATA[$this->diagram->customLinks['RT'][$table]]]></code>
10197-
<code><![CDATA[$this->diagram->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10198-
<code><![CDATA[$this->diagram->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10199-
<code><![CDATA[$this->diagram->customLinks['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]]]></code>
10200-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10201-
<code><![CDATA[$this->diagram->customLinks['doc'][$table]]]></code>
10191+
<code><![CDATA[$this->pdf->customLinks['RT'][$table]]]></code>
10192+
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10193+
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']]]]></code>
10194+
<code><![CDATA[$this->pdf->customLinks['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]]]></code>
10195+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
10196+
<code><![CDATA[$this->pdf->customLinks['doc'][$table]]]></code>
1020210197
</MixedArrayOffset>
1020310198
<MixedAssignment>
1020410199
<code>$attribute</code>
@@ -10357,21 +10352,33 @@
1035710352
</PossiblyFalseOperand>
1035810353
</file>
1035910354
<file src="src/Plugins/Schema/SchemaDia.php">
10355+
<DeprecatedMethod>
10356+
<code>DatabaseInterface::getInstance()</code>
10357+
</DeprecatedMethod>
1036010358
<UnusedClass>
1036110359
<code>SchemaDia</code>
1036210360
</UnusedClass>
1036310361
</file>
1036410362
<file src="src/Plugins/Schema/SchemaEps.php">
10363+
<DeprecatedMethod>
10364+
<code>DatabaseInterface::getInstance()</code>
10365+
</DeprecatedMethod>
1036510366
<UnusedClass>
1036610367
<code>SchemaEps</code>
1036710368
</UnusedClass>
1036810369
</file>
1036910370
<file src="src/Plugins/Schema/SchemaPdf.php">
10371+
<DeprecatedMethod>
10372+
<code>DatabaseInterface::getInstance()</code>
10373+
</DeprecatedMethod>
1037010374
<UnusedClass>
1037110375
<code>SchemaPdf</code>
1037210376
</UnusedClass>
1037310377
</file>
1037410378
<file src="src/Plugins/Schema/SchemaSvg.php">
10379+
<DeprecatedMethod>
10380+
<code>DatabaseInterface::getInstance()</code>
10381+
</DeprecatedMethod>
1037510382
<UnusedClass>
1037610383
<code>SchemaSvg</code>
1037710384
</UnusedClass>

src/Plugins/Schema/Dia/DiaRelationSchema.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Dia;
99

10+
use PhpMyAdmin\ConfigStorage\Relation;
1011
use PhpMyAdmin\Identifiers\DatabaseName;
1112
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
1213

@@ -23,8 +24,6 @@
2324
* Dia XML is generated by using XMLWriter php extension and this class
2425
* inherits ExportRelationSchema class has common functionality added
2526
* to this class
26-
*
27-
* @extends ExportRelationSchema<Dia>
2827
*/
2928
class DiaRelationSchema extends ExportRelationSchema
3029
{
@@ -44,6 +43,8 @@ class DiaRelationSchema extends ExportRelationSchema
4443

4544
public static int $objectId = 0;
4645

46+
private Dia $dia;
47+
4748
/**
4849
* Upon instantiation This outputs the Dia XML document
4950
* that user can download
@@ -52,16 +53,18 @@ class DiaRelationSchema extends ExportRelationSchema
5253
* @see TableStatsDia
5354
* @see RelationStatsDia
5455
*/
55-
public function __construct(DatabaseName $db)
56+
public function __construct(Relation $relation, DatabaseName $db)
5657
{
57-
parent::__construct($db, new Dia());
58+
parent::__construct($relation, $db);
59+
60+
$this->dia = new Dia();
5861

5962
$this->setShowColor(isset($_REQUEST['dia_show_color']));
6063
$this->setShowKeys(isset($_REQUEST['dia_show_keys']));
6164
$this->setOrientation((string) $_REQUEST['dia_orientation']);
6265
$this->setPaper((string) $_REQUEST['dia_paper']);
6366

64-
$this->diagram->startDiaDoc(
67+
$this->dia->startDiaDoc(
6568
$this->paper,
6669
$this->topMargin,
6770
$this->bottomMargin,
@@ -78,7 +81,7 @@ public function __construct(DatabaseName $db)
7881
}
7982

8083
$this->tables[$table] = new TableStatsDia(
81-
$this->diagram,
84+
$this->dia,
8285
$this->db->getName(),
8386
$table,
8487
$this->pageNumber,
@@ -136,13 +139,13 @@ public function __construct(DatabaseName $db)
136139
$this->drawRelations();
137140
}
138141

139-
$this->diagram->endDiaDoc();
142+
$this->dia->endDiaDoc();
140143
}
141144

142145
/** @return array{fileName: non-empty-string, fileData: string} */
143146
public function getExportInfo(): array
144147
{
145-
return ['fileName' => $this->getFileName('.dia'), 'fileData' => $this->diagram->getOutputData()];
148+
return ['fileName' => $this->getFileName('.dia'), 'fileData' => $this->dia->getOutputData()];
146149
}
147150

148151
/**
@@ -165,7 +168,7 @@ private function addRelation(
165168
): void {
166169
if (! isset($this->tables[$masterTable])) {
167170
$this->tables[$masterTable] = new TableStatsDia(
168-
$this->diagram,
171+
$this->dia,
169172
$this->db->getName(),
170173
$masterTable,
171174
$this->pageNumber,
@@ -175,7 +178,7 @@ private function addRelation(
175178

176179
if (! isset($this->tables[$foreignTable])) {
177180
$this->tables[$foreignTable] = new TableStatsDia(
178-
$this->diagram,
181+
$this->dia,
179182
$this->db->getName(),
180183
$foreignTable,
181184
$this->pageNumber,
@@ -184,7 +187,7 @@ private function addRelation(
184187
}
185188

186189
$this->relations[] = new RelationStatsDia(
187-
$this->diagram,
190+
$this->dia,
188191
$this->tables[$masterTable],
189192
$masterField,
190193
$this->tables[$foreignTable],

src/Plugins/Schema/Eps/EpsRelationSchema.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Eps;
99

10+
use PhpMyAdmin\ConfigStorage\Relation;
1011
use PhpMyAdmin\Identifiers\DatabaseName;
1112
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
1213
use PhpMyAdmin\Version;
@@ -27,8 +28,6 @@
2728
*
2829
* This class inherits ExportRelationSchema class has common functionality added
2930
* to this class
30-
*
31-
* @extends ExportRelationSchema<Eps>
3231
*/
3332
class EpsRelationSchema extends ExportRelationSchema
3433
{
@@ -40,44 +39,48 @@ class EpsRelationSchema extends ExportRelationSchema
4039

4140
private int|float $tablewidth = 0;
4241

42+
private Eps $eps;
43+
4344
/**
4445
* Upon instantiation This starts writing the EPS document
4546
* user will be prompted for download as .eps extension
4647
*
4748
* @see Eps
4849
*/
49-
public function __construct(DatabaseName $db)
50+
public function __construct(Relation $relation, DatabaseName $db)
5051
{
51-
parent::__construct($db, new Eps());
52+
parent::__construct($relation, $db);
53+
54+
$this->eps = new Eps();
5255

5356
$this->setShowColor(isset($_REQUEST['eps_show_color']));
5457
$this->setShowKeys(isset($_REQUEST['eps_show_keys']));
5558
$this->setTableDimension(isset($_REQUEST['eps_show_table_dimension']));
5659
$this->setAllTablesSameWidth(isset($_REQUEST['eps_all_tables_same_width']));
5760
$this->setOrientation((string) $_REQUEST['eps_orientation']);
5861

59-
$this->diagram->setTitle(
62+
$this->eps->setTitle(
6063
sprintf(
6164
__('Schema of the %s database - Page %s'),
6265
$this->db->getName(),
6366
$this->pageNumber,
6467
),
6568
);
66-
$this->diagram->setAuthor('phpMyAdmin ' . Version::VERSION);
67-
$this->diagram->setDate(date('j F Y, g:i a'));
68-
$this->diagram->setOrientation($this->orientation);
69-
$this->diagram->setFont('Verdana', 10);
69+
$this->eps->setAuthor('phpMyAdmin ' . Version::VERSION);
70+
$this->eps->setDate(date('j F Y, g:i a'));
71+
$this->eps->setOrientation($this->orientation);
72+
$this->eps->setFont('Verdana', 10);
7073

7174
$alltables = $this->getTablesFromRequest();
7275

7376
foreach ($alltables as $table) {
7477
if (! isset($this->tables[$table])) {
7578
$this->tables[$table] = new TableStatsEps(
76-
$this->diagram,
79+
$this->eps,
7780
$this->db->getName(),
7881
$table,
79-
$this->diagram->getFont(),
80-
$this->diagram->getFontSize(),
82+
$this->eps->getFont(),
83+
$this->eps->getFontSize(),
8184
$this->pageNumber,
8285
$this->showKeys,
8386
$this->tableDimension,
@@ -111,8 +114,8 @@ public function __construct(DatabaseName $db)
111114
if (in_array($rel['foreign_table'], $alltables)) {
112115
$this->addRelation(
113116
$oneTable,
114-
$this->diagram->getFont(),
115-
$this->diagram->getFontSize(),
117+
$this->eps->getFont(),
118+
$this->eps->getFontSize(),
116119
$masterField,
117120
$rel['foreign_table'],
118121
$rel['foreign_field'],
@@ -131,8 +134,8 @@ public function __construct(DatabaseName $db)
131134
foreach ($oneKey['index_list'] as $index => $oneField) {
132135
$this->addRelation(
133136
$oneTable,
134-
$this->diagram->getFont(),
135-
$this->diagram->getFontSize(),
137+
$this->eps->getFont(),
138+
$this->eps->getFontSize(),
136139
$oneField,
137140
$oneKey['ref_table_name'],
138141
$oneKey['ref_index_list'][$index],
@@ -148,13 +151,13 @@ public function __construct(DatabaseName $db)
148151
}
149152

150153
$this->drawTables();
151-
$this->diagram->endEpsDoc();
154+
$this->eps->endEpsDoc();
152155
}
153156

154157
/** @return array{fileName: non-empty-string, fileData: string} */
155158
public function getExportInfo(): array
156159
{
157-
return ['fileName' => $this->getFileName('.eps'), 'fileData' => $this->diagram->getOutputData()];
160+
return ['fileName' => $this->getFileName('.eps'), 'fileData' => $this->eps->getOutputData()];
158161
}
159162

160163
/**
@@ -183,7 +186,7 @@ private function addRelation(
183186
): void {
184187
if (! isset($this->tables[$masterTable])) {
185188
$this->tables[$masterTable] = new TableStatsEps(
186-
$this->diagram,
189+
$this->eps,
187190
$this->db->getName(),
188191
$masterTable,
189192
$font,
@@ -197,7 +200,7 @@ private function addRelation(
197200

198201
if (! isset($this->tables[$foreignTable])) {
199202
$this->tables[$foreignTable] = new TableStatsEps(
200-
$this->diagram,
203+
$this->eps,
201204
$this->db->getName(),
202205
$foreignTable,
203206
$font,
@@ -210,7 +213,7 @@ private function addRelation(
210213
}
211214

212215
$this->relations[] = new RelationStatsEps(
213-
$this->diagram,
216+
$this->eps,
214217
$this->tables[$masterTable],
215218
$masterField,
216219
$this->tables[$foreignTable],

src/Plugins/Schema/ExportRelationSchema.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* This class is inherited by all schema classes
2424
* It contains those methods which are common in them
2525
* it works like factory pattern
26-
*
27-
* @template T
2826
*/
2927
class ExportRelationSchema
3028
{
@@ -44,14 +42,10 @@ class ExportRelationSchema
4442

4543
protected bool $offline = false;
4644

47-
protected Relation $relation;
48-
49-
/** @param T $diagram */
50-
public function __construct(protected DatabaseName $db, protected $diagram)
45+
public function __construct(protected Relation $relation, protected DatabaseName $db)
5146
{
5247
$this->setPageNumber((int) $_REQUEST['page_number']);
5348
$this->setOffline(isset($_REQUEST['offline_export']));
54-
$this->relation = new Relation(DatabaseInterface::getInstance());
5549
}
5650

5751
/**

0 commit comments

Comments
 (0)