Extract dependency from Util::getSupportedDatatypes()

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2026-01-30 16:13:34 -03:00
parent a15c6d6a47
commit 0a8974668e
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
5 changed files with 7 additions and 10 deletions

View File

@ -13143,7 +13143,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
count: 5
count: 4
path: src/Util.php
-

View File

@ -8530,7 +8530,6 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$array]]></code>

View File

@ -358,7 +358,7 @@ class Routines
$retval['item_param_name'] = $_POST['item_param_name'];
$retval['item_param_type'] = $_POST['item_param_type'];
foreach ($retval['item_param_type'] as $key => $value) {
if (in_array($value, Util::getSupportedDatatypes(), true)) {
if (in_array($value, Util::getSupportedDatatypes($this->dbi), true)) {
continue;
}
@ -380,7 +380,7 @@ class Routines
$retval['item_returntype'] = '';
if (
isset($_POST['item_returntype'])
&& in_array($_POST['item_returntype'], Util::getSupportedDatatypes(), true)
&& in_array($_POST['item_returntype'], Util::getSupportedDatatypes($this->dbi), true)
) {
$retval['item_returntype'] = $_POST['item_returntype'];
}
@ -726,7 +726,7 @@ class Routines
): string {
$itemReturnType = $_POST['item_returntype'] ?? null;
if ($itemReturnType !== '' && in_array($itemReturnType, Util::getSupportedDatatypes(), true)) {
if ($itemReturnType !== '' && in_array($itemReturnType, Util::getSupportedDatatypes($this->dbi), true)) {
$query .= 'RETURNS ' . $itemReturnType;
} else {
$this->errors[] = __('You must provide a valid return type for the routine.');

View File

@ -1162,10 +1162,10 @@ class Util
*
* @return string[] An array of datatypes.
*/
public static function getSupportedDatatypes(): array
public static function getSupportedDatatypes(DatabaseInterface $dbi): array
{
$retval = [];
foreach (DatabaseInterface::getInstance()->types->getColumns() as $value) {
foreach ($dbi->types->getColumns() as $value) {
if (is_array($value)) {
foreach ($value as $subvalue) {
if ($subvalue === '-') {

View File

@ -1367,8 +1367,6 @@ SQL;
public function testGetSupportedDatatypes(): void
{
$dbiDummy = $this->createDbiDummy();
DatabaseInterface::$instance = $this->createDatabaseInterface($dbiDummy);
$expected = [
'INT',
'VARCHAR',
@ -1415,7 +1413,7 @@ SQL;
'GEOMETRYCOLLECTION',
'JSON',
];
self::assertSame($expected, Util::getSupportedDatatypes());
self::assertSame($expected, Util::getSupportedDatatypes($this->createDatabaseInterface()));
}
/**