Visitar URL original
Merge pull request #19288 from kamil-tekiela/Fix-type-hints · phpmyadmin/phpmyadmin@b8e1366 · GitHub
Skip to content

Commit b8e1366

Browse files
Merge pull request #19288 from kamil-tekiela/Fix-type-hints
Fix type hints
2 parents 166b114 + 4697f32 commit b8e1366

12 files changed

Lines changed: 280 additions & 325 deletions

‎composer.lock‎

Lines changed: 156 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎phpstan-baseline.neon‎

Lines changed: 40 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,11 +4125,6 @@ parameters:
41254125
count: 3
41264126
path: src/Controllers/Table/GisVisualizationController.php
41274127

4128-
-
4129-
message: "#^Method PhpMyAdmin\\\\Controllers\\\\Table\\\\GisVisualizationController\\:\\:getVisualizationSettings\\(\\) should return array\\{spatialColumn\\: non\\-empty\\-string, labelColumn\\?\\: non\\-empty\\-string\\} but returns array\\{labelColumn\\?\\: non\\-empty\\-string, spatialColumn\\: mixed\\}\\.$#"
4130-
count: 1
4131-
path: src/Controllers/Table/GisVisualizationController.php
4132-
41334128
-
41344129
message: "#^Parameter \\#2 \\$format of method PhpMyAdmin\\\\Gis\\\\GisVisualization\\:\\:toFile\\(\\) expects string, mixed given\\.$#"
41354130
count: 1
@@ -6296,12 +6291,7 @@ parameters:
62966291
path: src/Dbal/MysqliResult.php
62976292

62986293
-
6299-
message: "#^Method PhpMyAdmin\\\\Dbal\\\\MysqliResult\\:\\:getFieldNames\\(\\) should return array\\<int, non\\-empty\\-string\\> but returns array\\<int, string\\>\\.$#"
6300-
count: 1
6301-
path: src/Dbal/MysqliResult.php
6302-
6303-
-
6304-
message: "#^Parameter \\#1 \\$field of class PhpMyAdmin\\\\FieldMetadata constructor expects object\\{name\\: non\\-empty\\-string, orgname\\: string, table\\: string, orgtable\\: string, max_length\\: int, length\\: int, charsetnr\\: int, flags\\: int, type\\: int, decimals\\: int, db\\: string, def\\: string, catalog\\: string\\}, object\\{name\\: string, orgname\\: string, table\\: string, orgtable\\: string, def\\: string, db\\: string, catalog\\: 'def', max_length\\: 0, length\\: int, charsetnr\\: string, flags\\: int, type\\: int, decimals\\: int\\}&stdClass given\\.$#"
6294+
message: "#^Parameter \\#1 \\$field of class PhpMyAdmin\\\\FieldMetadata constructor expects object\\{name\\: string, orgname\\: string, table\\: string, orgtable\\: string, max_length\\: int, length\\: int, charsetnr\\: int, flags\\: int, type\\: int, decimals\\: int, db\\: string, def\\: string, catalog\\: string\\}, object\\{name\\: string, orgname\\: string, table\\: string, orgtable\\: string, def\\: string, db\\: string, catalog\\: string, max_length\\: int, length\\: int, charsetnr\\: string, flags\\: int, type\\: int, decimals\\: int\\}&stdClass given\\.$#"
63056295
count: 1
63066296
path: src/Dbal/MysqliResult.php
63076297

@@ -6701,7 +6691,7 @@ parameters:
67016691
path: src/Display/Results.php
67026692

67036693
-
6704-
message: "#^Property PhpMyAdmin\\\\FieldMetadata\\:\\:\\$name \\(non\\-empty\\-string\\) does not accept mixed\\.$#"
6694+
message: "#^Property PhpMyAdmin\\\\FieldMetadata\\:\\:\\$name \\(string\\) does not accept mixed\\.$#"
67056695
count: 1
67066696
path: src/Display/Results.php
67076697

@@ -9221,12 +9211,12 @@ parameters:
92219211
path: src/Plugins.php
92229212

92239213
-
9224-
message: "#^Call to an undefined method PhpMyAdmin\\\\Properties\\\\Options\\\\OptionsPropertyItem\\:\\:getProperties\\(\\)\\.$#"
9214+
message: "#^Call to function method_exists\\(\\) with PhpMyAdmin\\\\Properties\\\\Options\\\\OptionsPropertyItem and 'getText' will always evaluate to true\\.$#"
92259215
count: 1
92269216
path: src/Plugins.php
92279217

92289218
-
9229-
message: "#^Call to function method_exists\\(\\) with PhpMyAdmin\\\\Properties\\\\Options\\\\OptionsPropertyItem and 'getText' will always evaluate to true\\.$#"
9219+
message: "#^Cannot call method getProperties\\(\\) on mixed\\.$#"
92309220
count: 1
92319221
path: src/Plugins.php
92329222

@@ -9270,6 +9260,11 @@ parameters:
92709260
count: 1
92719261
path: src/Plugins.php
92729262

9263+
-
9264+
message: "#^Parameter \\#3 \\$propertyGroup of static method PhpMyAdmin\\\\Plugins\\:\\:getOneOption\\(\\) expects PhpMyAdmin\\\\Properties\\\\Options\\\\OptionsPropertyItem, mixed given\\.$#"
9265+
count: 1
9266+
path: src/Plugins.php
9267+
92739268
-
92749269
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, bool\\|int\\<0, max\\>\\|string given\\.$#"
92759270
count: 1
@@ -9545,14 +9540,9 @@ parameters:
95459540
count: 1
95469541
path: src/Plugins/Export/ExportCsv.php
95479542

9548-
-
9549-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9550-
count: 1
9551-
path: src/Plugins/Export/ExportCsv.php
9552-
95539543
-
95549544
message: "#^Cannot access offset string on mixed\\.$#"
9555-
count: 1
9545+
count: 2
95569546
path: src/Plugins/Export/ExportCsv.php
95579547

95589548
-
@@ -9595,14 +9585,9 @@ parameters:
95959585
count: 3
95969586
path: src/Plugins/Export/ExportHtmlword.php
95979587

9598-
-
9599-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9600-
count: 1
9601-
path: src/Plugins/Export/ExportHtmlword.php
9602-
96039588
-
96049589
message: "#^Cannot access offset string on mixed\\.$#"
9605-
count: 5
9590+
count: 6
96069591
path: src/Plugins/Export/ExportHtmlword.php
96079592

96089593
-
@@ -9655,14 +9640,9 @@ parameters:
96559640
count: 2
96569641
path: src/Plugins/Export/ExportLatex.php
96579642

9658-
-
9659-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9660-
count: 1
9661-
path: src/Plugins/Export/ExportLatex.php
9662-
96639643
-
96649644
message: "#^Cannot access offset string on mixed\\.$#"
9665-
count: 3
9645+
count: 4
96669646
path: src/Plugins/Export/ExportLatex.php
96679647

96689648
-
@@ -9735,14 +9715,9 @@ parameters:
97359715
count: 1
97369716
path: src/Plugins/Export/ExportOds.php
97379717

9738-
-
9739-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9740-
count: 1
9741-
path: src/Plugins/Export/ExportOds.php
9742-
97439718
-
97449719
message: "#^Cannot access offset string on mixed\\.$#"
9745-
count: 1
9720+
count: 2
97469721
path: src/Plugins/Export/ExportOds.php
97479722

97489723
-
@@ -9795,14 +9770,9 @@ parameters:
97959770
count: 3
97969771
path: src/Plugins/Export/ExportOdt.php
97979772

9798-
-
9799-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9800-
count: 1
9801-
path: src/Plugins/Export/ExportOdt.php
9802-
98039773
-
98049774
message: "#^Cannot access offset string on mixed\\.$#"
9805-
count: 5
9775+
count: 6
98069776
path: src/Plugins/Export/ExportOdt.php
98079777

98089778
-
@@ -9875,14 +9845,9 @@ parameters:
98759845
count: 1
98769846
path: src/Plugins/Export/ExportPhparray.php
98779847

9878-
-
9879-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9880-
count: 1
9881-
path: src/Plugins/Export/ExportPhparray.php
9882-
98839848
-
98849849
message: "#^Cannot access offset string on mixed\\.$#"
9885-
count: 1
9850+
count: 2
98869851
path: src/Plugins/Export/ExportPhparray.php
98879852

98889853
-
@@ -9985,14 +9950,9 @@ parameters:
99859950
count: 2
99869951
path: src/Plugins/Export/ExportSql.php
99879952

9988-
-
9989-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
9990-
count: 1
9991-
path: src/Plugins/Export/ExportSql.php
9992-
99939953
-
99949954
message: "#^Cannot access offset string on mixed\\.$#"
9995-
count: 9
9955+
count: 10
99969956
path: src/Plugins/Export/ExportSql.php
99979957

99989958
-
@@ -10180,14 +10140,9 @@ parameters:
1018010140
count: 3
1018110141
path: src/Plugins/Export/ExportTexytext.php
1018210142

10183-
-
10184-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
10185-
count: 1
10186-
path: src/Plugins/Export/ExportTexytext.php
10187-
1018810143
-
1018910144
message: "#^Cannot access offset string on mixed\\.$#"
10190-
count: 5
10145+
count: 6
1019110146
path: src/Plugins/Export/ExportTexytext.php
1019210147

1019310148
-
@@ -10230,14 +10185,9 @@ parameters:
1023010185
count: 1
1023110186
path: src/Plugins/Export/ExportXml.php
1023210187

10233-
-
10234-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
10235-
count: 1
10236-
path: src/Plugins/Export/ExportXml.php
10237-
1023810188
-
1023910189
message: "#^Cannot access offset string on mixed\\.$#"
10240-
count: 1
10190+
count: 2
1024110191
path: src/Plugins/Export/ExportXml.php
1024210192

1024310193
-
@@ -10275,14 +10225,9 @@ parameters:
1027510225
count: 1
1027610226
path: src/Plugins/Export/ExportYaml.php
1027710227

10278-
-
10279-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
10280-
count: 1
10281-
path: src/Plugins/Export/ExportYaml.php
10282-
1028310228
-
1028410229
message: "#^Cannot access offset string on mixed\\.$#"
10285-
count: 1
10230+
count: 2
1028610231
path: src/Plugins/Export/ExportYaml.php
1028710232

1028810233
-
@@ -10330,14 +10275,9 @@ parameters:
1033010275
count: 2
1033110276
path: src/Plugins/Export/Helpers/Pdf.php
1033210277

10333-
-
10334-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
10335-
count: 1
10336-
path: src/Plugins/Export/Helpers/Pdf.php
10337-
1033810278
-
1033910279
message: "#^Cannot access offset string on mixed\\.$#"
10340-
count: 1
10280+
count: 2
1034110281
path: src/Plugins/Export/Helpers/Pdf.php
1034210282

1034310283
-
@@ -14250,6 +14190,26 @@ parameters:
1425014190
count: 1
1425114191
path: tests/end-to-end/TestBase.php
1425214192

14193+
-
14194+
message: "#^Parameter \\#1 \\$handle of function curl_errno expects CurlHandle, \\(CurlHandle\\|false\\) given\\.$#"
14195+
count: 2
14196+
path: tests/end-to-end/TestBase.php
14197+
14198+
-
14199+
message: "#^Parameter \\#1 \\$handle of function curl_error expects CurlHandle, \\(CurlHandle\\|false\\) given\\.$#"
14200+
count: 3
14201+
path: tests/end-to-end/TestBase.php
14202+
14203+
-
14204+
message: "#^Parameter \\#1 \\$handle of function curl_exec expects CurlHandle, \\(CurlHandle\\|false\\) given\\.$#"
14205+
count: 2
14206+
path: tests/end-to-end/TestBase.php
14207+
14208+
-
14209+
message: "#^Parameter \\#1 \\$handle of function curl_setopt expects CurlHandle, \\(CurlHandle\\|false\\) given\\.$#"
14210+
count: 9
14211+
path: tests/end-to-end/TestBase.php
14212+
1425314213
-
1425414214
message: "#^Parameter \\#1 \\$handle of method Facebook\\\\WebDriver\\\\Remote\\\\RemoteTargetLocator\\:\\:window\\(\\) expects string, mixed given\\.$#"
1425514215
count: 3

‎psalm-baseline.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="app/services_loader.php">
44
<MixedArgument>
55
<code><![CDATA[$argumentName]]></code>

‎src/Controllers/GisDataEditorController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use PhpMyAdmin\Gis\GisFactory;
1111
use PhpMyAdmin\Gis\GisVisualization;
12+
use PhpMyAdmin\Gis\GisVisualizationSettings;
1213
use PhpMyAdmin\Http\Response;
1314
use PhpMyAdmin\Http\ServerRequest;
1415
use PhpMyAdmin\ResponseRenderer;
@@ -82,7 +83,7 @@ public function __invoke(ServerRequest $request): Response
8283
$result = "'" . $wkt . "'," . $srid;
8384

8485
// Generate SVG based visualization
85-
$visualizationSettings = ['width' => 450, 'height' => 300, 'spatialColumn' => 'wkt'];
86+
$visualizationSettings = new GisVisualizationSettings(450, 300, 'wkt');
8687
$data = [['wkt' => $wktWithZero, 'srid' => $srid]];
8788

8889
$visualization = GisVisualization::getByData($data, $visualizationSettings);

‎src/Controllers/Table/GisVisualizationController.php‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpMyAdmin\DbTableExists;
1313
use PhpMyAdmin\FieldMetadata;
1414
use PhpMyAdmin\Gis\GisVisualization;
15+
use PhpMyAdmin\Gis\GisVisualizationSettings;
1516
use PhpMyAdmin\Html\Generator;
1617
use PhpMyAdmin\Http\Factory\ResponseFactory;
1718
use PhpMyAdmin\Http\Response;
@@ -24,6 +25,7 @@
2425
use PhpMyAdmin\Util;
2526

2627
use function __;
28+
use function array_search;
2729
use function in_array;
2830
use function is_array;
2931
use function is_string;
@@ -106,9 +108,11 @@ public function __invoke(ServerRequest $request): Response
106108
}
107109

108110
// Get settings if any posted
109-
$visualizationSettings = $this->getVisualizationSettings($spatialCandidates, $labelCandidates);
110-
$visualizationSettings['width'] = 600;
111-
$visualizationSettings['height'] = 450;
111+
$visualizationSettings = $this->getVisualizationSettings(
112+
$spatialCandidates,
113+
$labelCandidates,
114+
$request->getParam('visualizationSettings'),
115+
);
112116

113117
$rows = $this->getRows();
114118
$pos = $this->getPos();
@@ -198,38 +202,34 @@ private function getSqlQuery(): string|null
198202
/**
199203
* @param string[] $spatialCandidates
200204
* @param string[] $labelCandidates
201-
* @psalm-param non-empty-list<non-empty-string> $spatialCandidates
202-
* @psalm-param list<non-empty-string> $labelCandidates
203-
*
204-
* @return mixed[];
205-
* @psalm-return array{spatialColumn:non-empty-string,labelColumn?:non-empty-string}
205+
* @psalm-param non-empty-list<string> $spatialCandidates
206+
* @psalm-param list<string> $labelCandidates
206207
*/
207-
private function getVisualizationSettings(array $spatialCandidates, array $labelCandidates): array
208-
{
209-
$settingsIn = [];
210-
// Download as PNG/SVG/PDF use _GET and the normal form uses _POST
211-
if (is_array($_POST['visualizationSettings'] ?? null)) {
212-
/** @var mixed[] $settingsIn */
213-
$settingsIn = $_POST['visualizationSettings'];
214-
} elseif (is_array($_GET['visualizationSettings'] ?? null)) {
215-
/** @var mixed[] $settingsIn */
216-
$settingsIn = $_GET['visualizationSettings'];
208+
private function getVisualizationSettings(
209+
array $spatialCandidates,
210+
array $labelCandidates,
211+
mixed $settingsIn,
212+
): GisVisualizationSettings {
213+
if (! is_array($settingsIn)) {
214+
return new GisVisualizationSettings(600, 450, $spatialCandidates[0]);
217215
}
218216

219-
$settings = [];
217+
$labelColumn = null;
220218
if (
221219
isset($settingsIn['labelColumn']) &&
222220
in_array($settingsIn['labelColumn'], $labelCandidates, true)
223221
) {
224-
$settings['labelColumn'] = $settingsIn['labelColumn'];
222+
$labelColumn = $settingsIn['labelColumn'];
225223
}
226224

227225
// If spatial column is not set, use first geometric column as spatial column
228-
$spatialColumnValid = isset($settingsIn['spatialColumn']) &&
229-
in_array($settingsIn['spatialColumn'], $spatialCandidates, true);
230-
$settings['spatialColumn'] = $spatialColumnValid ? $settingsIn['spatialColumn'] : $spatialCandidates[0];
226+
$spatialColumn = $spatialCandidates[array_search(
227+
$settingsIn['spatialColumn'] ?? null,
228+
$spatialCandidates,
229+
true,
230+
)];
231231

232-
return $settings;
232+
return new GisVisualizationSettings(600, 450, $spatialColumn, $labelColumn);
233233
}
234234

235235
private function getPos(): int

‎src/Dbal/MysqliResult.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function seek(int $offset): bool
207207
}
208208

209209
/**
210-
* returns meta info for fields in $result
210+
* Returns meta info for fields in $result
211211
*
212212
* @return array<int, FieldMetadata> meta info for fields in $result
213213
* @psalm-return list<FieldMetadata>
@@ -229,8 +229,7 @@ public function getFieldsMeta(): array
229229
/**
230230
* Returns the names of the fields in the result
231231
*
232-
* @return array<int, string> Fields names
233-
* @psalm-return list<non-empty-string>
232+
* @return list<string> Fields names
234233
*/
235234
public function getFieldNames(): array
236235
{

0 commit comments

Comments
 (0)