Visitar URL original
Split Util::getSupportedDatatypes (#18420) · phpmyadmin/phpmyadmin@0dce80a · GitHub
Skip to content

Commit 0dce80a

Browse files
Split Util::getSupportedDatatypes (#18420)
* Split Util::getSupportedDatatypes Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Add test for getSupportedDatatypes Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent e7d1ecb commit 0dce80a

10 files changed

Lines changed: 74 additions & 38 deletions

File tree

‎libraries/classes/Database/Routines.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,7 @@ public function getParameterRow(array $routine = [], mixed $index = null, string
690690
'item_param_name' => $routine['item_param_name'][$i] ?? '',
691691
'item_param_length' => $routine['item_param_length'][$i] ?? '',
692692
'item_param_opts_num' => $routine['item_param_opts_num'][$i] ?? '',
693-
'supported_datatypes' => Util::getSupportedDatatypes(
694-
true,
693+
'supported_datatypes' => Generator::getSupportedDatatypes(
695694
$routine['item_param_type'][$i],
696695
),
697696
'charsets' => $charsets,

‎libraries/classes/Twig/UtilExtension.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getFunctions(): array
7878
),
7979
new TwigFunction(
8080
'get_supported_datatypes',
81-
Util::getSupportedDatatypes(...),
81+
Generator::getSupportedDatatypes(...),
8282
['is_safe' => ['html']],
8383
),
8484
new TwigFunction(

‎libraries/classes/Util.php‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,33 +1450,25 @@ public static function expandUserString(
14501450

14511451
/**
14521452
* This function processes the datatypes supported by the DB,
1453-
* as specified in Types->getColumns() and either returns an array
1454-
* (useful for quickly checking if a datatype is supported)
1455-
* or an HTML snippet that creates a drop-down list.
1453+
* as specified in Types->getColumns() and returns an array
1454+
* (useful for quickly checking if a datatype is supported).
14561455
*
1457-
* @param bool $html Whether to generate an html snippet or an array
1458-
* @param string $selected The value to mark as selected in HTML mode
1459-
*
1460-
* @return mixed An HTML snippet or an array of datatypes.
1456+
* @return mixed[] An array of datatypes.
14611457
*/
1462-
public static function getSupportedDatatypes(bool $html = false, string $selected = ''): mixed
1458+
public static function getSupportedDatatypes(): array
14631459
{
1464-
if ($html) {
1465-
$retval = Generator::getSupportedDatatypes($selected);
1466-
} else {
1467-
$retval = [];
1468-
foreach ($GLOBALS['dbi']->types->getColumns() as $value) {
1469-
if (is_array($value)) {
1470-
foreach ($value as $subvalue) {
1471-
if ($subvalue === '-') {
1472-
continue;
1473-
}
1474-
1475-
$retval[] = $subvalue;
1460+
$retval = [];
1461+
foreach ($GLOBALS['dbi']->types->getColumns() as $value) {
1462+
if (is_array($value)) {
1463+
foreach ($value as $subvalue) {
1464+
if ($subvalue === '-') {
1465+
continue;
14761466
}
1477-
} elseif ($value !== '-') {
1478-
$retval[] = $value;
1467+
1468+
$retval[] = $subvalue;
14791469
}
1470+
} elseif ($value !== '-') {
1471+
$retval[] = $value;
14801472
}
14811473
}
14821474

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,11 +3310,6 @@ parameters:
33103310
count: 1
33113311
path: libraries/classes/Database/Routines.php
33123312

3313-
-
3314-
message: "#^Parameter \\#2 \\$haystack of function in_array expects array, mixed given\\.$#"
3315-
count: 3
3316-
path: libraries/classes/Database/Routines.php
3317-
33183313
-
33193314
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
33203315
count: 1

‎psalm-baseline.xml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5488,9 +5488,6 @@
54885488
<code>$value</code>
54895489
<code>$value</code>
54905490
<code>$value</code>
5491-
<code>Util::getSupportedDatatypes()</code>
5492-
<code>Util::getSupportedDatatypes()</code>
5493-
<code>Util::getSupportedDatatypes()</code>
54945491
</MixedArgument>
54955492
<MixedArgumentTypeCoercion>
54965493
<code>$options</code>

‎templates/columns_definitions/column_attributes.twig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<td class="text-center">
2121
<select class="column_type" name="field_type[{{ column_number }}]" id="field_{{ column_number }}_{{ ci - ci_offset }}"
2222
{{- column_meta['column_status'] is defined and not column_meta['column_status']['isEditable'] ? ' disabled' }}>
23-
{{ get_supported_datatypes(true, type_upper) }}
23+
{{ get_supported_datatypes(type_upper) }}
2424
</select>
2525
{% set ci = ci + 1 %}
2626
</td>

‎templates/database/central_columns/edit_table_row.twig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<td name="col_type" class="text-nowrap">
1515
<select class="column_type" name="field_type[{{ row_num }}]" id="field_{{ row_num }}_1">
16-
{{ get_supported_datatypes(true, row['col_type']|upper) }}
16+
{{ get_supported_datatypes(row['col_type']|upper) }}
1717
</select>
1818
</td>
1919

‎templates/database/central_columns/main.twig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</td>
6363
<td name="col_type" class="text-nowrap">
6464
<select class="column_type" name="field_type[0]" id="field_0_1">
65-
{{ get_supported_datatypes(true) }}
65+
{{ get_supported_datatypes('') }}
6666
</select>
6767
</td>
6868
<td class="text-nowrap" name="col_length">
@@ -294,7 +294,7 @@
294294
<td name="col_type" class="text-nowrap">
295295
<span>{{ row['col_type'] }}</span>
296296
<select class="column_type" name="field_type[{{ row_num }}]" id="field_{{ row_num }}_1">
297-
{{ get_supported_datatypes(true, types_upper[row_num]) }}
297+
{{ get_supported_datatypes(types_upper[row_num]) }}
298298
</select>
299299
</td>
300300
<td class="text-nowrap" name="col_length">

‎templates/database/routines/editor_form.twig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<td class="text-nowrap">{% trans 'Return type' %}</td>
8181
<td>
8282
<select name="item_returntype">
83-
{{ get_supported_datatypes(true, routine.item_returntype) }}
83+
{{ get_supported_datatypes(routine.item_returntype) }}
8484
</select>
8585
</td>
8686
</tr>

‎test/classes/UtilTest.php‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,4 +1813,57 @@ public static function providerForTestGetLowerCaseNames(): iterable
18131813
yield 'lower_case_table_names=1' => ['1', ''];
18141814
yield 'lower_case_table_names=2' => ['2', 'COLLATE utf8_general_ci'];
18151815
}
1816+
1817+
public function testGetSupportedDatatypes(): void
1818+
{
1819+
$dbiDummy = $this->createDbiDummy();
1820+
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
1821+
$expected = [
1822+
'INT',
1823+
'VARCHAR',
1824+
'TEXT',
1825+
'DATE',
1826+
'TINYINT',
1827+
'SMALLINT',
1828+
'MEDIUMINT',
1829+
'INT',
1830+
'BIGINT',
1831+
'DECIMAL',
1832+
'FLOAT',
1833+
'DOUBLE',
1834+
'REAL',
1835+
'BIT',
1836+
'BOOLEAN',
1837+
'SERIAL',
1838+
'DATE',
1839+
'DATETIME',
1840+
'TIMESTAMP',
1841+
'TIME',
1842+
'YEAR',
1843+
'CHAR',
1844+
'VARCHAR',
1845+
'TINYTEXT',
1846+
'TEXT',
1847+
'MEDIUMTEXT',
1848+
'LONGTEXT',
1849+
'BINARY',
1850+
'VARBINARY',
1851+
'TINYBLOB',
1852+
'BLOB',
1853+
'MEDIUMBLOB',
1854+
'LONGBLOB',
1855+
'ENUM',
1856+
'SET',
1857+
'GEOMETRY',
1858+
'POINT',
1859+
'LINESTRING',
1860+
'POLYGON',
1861+
'MULTIPOINT',
1862+
'MULTILINESTRING',
1863+
'MULTIPOLYGON',
1864+
'GEOMETRYCOLLECTION',
1865+
'JSON',
1866+
];
1867+
$this->assertSame($expected, Util::getSupportedDatatypes());
1868+
}
18161869
}

0 commit comments

Comments
 (0)