Skip to content

Commit 40c5a13

Browse files
Merge pull request #19429 from kamil-tekiela/Types-refactoring
Types refactoring
2 parents b7a63b1 + 39d23ad commit 40c5a13

11 files changed

Lines changed: 169 additions & 438 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18855,12 +18855,6 @@ parameters:
1885518855
count: 1
1885618856
path: src/TwoFactor.php
1885718857

18858-
-
18859-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
18860-
identifier: equal.notAllowed
18861-
count: 1
18862-
path: src/Types.php
18863-
1886418858
-
1886518859
message: '''
1886618860
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\DatabaseInterface\:

psalm-baseline.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14238,7 +14238,6 @@
1423814238
<PossiblyUnusedMethod>
1423914239
<code><![CDATA[providerFortTestGetAllFunctions]]></code>
1424014240
<code><![CDATA[providerFortTestGetColumns]]></code>
14241-
<code><![CDATA[providerFortTestGetFunctions]]></code>
1424214241
<code><![CDATA[providerFortTestGetFunctionsClass]]></code>
1424314242
</PossiblyUnusedMethod>
1424414243
</file>

src/ConfigStorage/Relation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
1717
use PhpMyAdmin\SqlParser\Utils\ForeignKey;
1818
use PhpMyAdmin\Table\Table;
19+
use PhpMyAdmin\TypeClass;
1920
use PhpMyAdmin\Util;
2021
use PhpMyAdmin\Version;
2122

@@ -500,7 +501,7 @@ public function getDisplayField(string $db, string $table): string
500501
*/
501502
$columns = $this->dbi->getColumnsFull($db, $table);
502503
foreach ($columns as $column) {
503-
if ($this->dbi->types->getTypeClass($column['DATA_TYPE']) === 'CHAR') {
504+
if ($this->dbi->types->getTypeClass($column['DATA_TYPE']) === TypeClass::Char) {
504505
return $column['COLUMN_NAME'];
505506
}
506507
}

src/Database/Routines.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PhpMyAdmin\SqlParser\Parser;
1515
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
1616
use PhpMyAdmin\SqlParser\TokensList;
17+
use PhpMyAdmin\TypeClass;
1718
use PhpMyAdmin\UserPrivileges;
1819
use PhpMyAdmin\Util;
1920

@@ -691,7 +692,7 @@ private function processParamsAndBuild(
691692
}
692693

693694
if (! empty($itemParamOpsText[$i])) {
694-
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === 'CHAR') {
695+
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === TypeClass::Char) {
695696
if (! in_array($itemParamType[$i], ['VARBINARY', 'BINARY'], true)) {
696697
$params .= ' CHARSET '
697698
. mb_strtolower($itemParamOpsText[$i]);
@@ -700,7 +701,7 @@ private function processParamsAndBuild(
700701
}
701702

702703
if (! empty($itemParamOpsNum[$i])) {
703-
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === 'NUMBER') {
704+
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === TypeClass::Number) {
704705
$params .= ' '
705706
. mb_strtoupper($itemParamOpsNum[$i]);
706707
}
@@ -757,14 +758,14 @@ private function processFunctionSpecificParameters(
757758
}
758759

759760
if (! empty($_POST['item_returnopts_text'])) {
760-
if ($this->dbi->types->getTypeClass($itemReturnType) === 'CHAR') {
761+
if ($this->dbi->types->getTypeClass($itemReturnType) === TypeClass::Char) {
761762
$query .= ' CHARSET '
762763
. mb_strtolower($_POST['item_returnopts_text']);
763764
}
764765
}
765766

766767
if (! empty($_POST['item_returnopts_num'])) {
767-
if ($this->dbi->types->getTypeClass($itemReturnType) === 'NUMBER') {
768+
if ($this->dbi->types->getTypeClass($itemReturnType) === TypeClass::Number) {
768769
$query .= ' '
769770
. mb_strtoupper($_POST['item_returnopts_num']);
770771
}

src/Html/Generator.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpMyAdmin\SqlParser\Parser;
2222
use PhpMyAdmin\SqlParser\Utils\Error as ParserError;
2323
use PhpMyAdmin\Template;
24+
use PhpMyAdmin\TypeClass;
2425
use PhpMyAdmin\Url;
2526
use PhpMyAdmin\Util;
2627
use Throwable;
@@ -257,12 +258,15 @@ public static function getDefaultFunctionForField(
257258
// Can we get field class based values?
258259
$currentClass = $dbi->types->getTypeClass($trueType);
259260
$config = Config::getInstance();
260-
if ($currentClass !== '' && isset($config->settings['DefaultFunctions']['FUNC_' . $currentClass])) {
261-
$defaultFunction = $config->settings['DefaultFunctions']['FUNC_' . $currentClass];
261+
if (
262+
$currentClass !== TypeClass::Unknown
263+
&& isset($config->settings['DefaultFunctions']['FUNC_' . $currentClass->value])
264+
) {
265+
$defaultFunction = $config->settings['DefaultFunctions']['FUNC_' . $currentClass->value];
262266
// Change the configured default function to include the ST_ prefix with MySQL 5.6 and later.
263267
// It needs to match the function listed in the select html element.
264268
if (
265-
$currentClass === 'SPATIAL' &&
269+
$currentClass === TypeClass::Spatial &&
266270
$dbi->getVersion() >= 50600 &&
267271
stripos($defaultFunction, 'ST_') !== 0
268272
) {

src/InsertEdit.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ private function getNullifyCodeForNullColumn(
366366
* @param string $onChangeClause onchange clause for fields
367367
* @param string $specialCharsEncoded replaced char if the string starts
368368
* with a \r\n pair (0x0d0a) add an extra \n
369-
* @param string $dataType the html5 data-* attribute type
369+
* @param TypeClass $dataType the html5 data-* attribute type
370370
*
371371
* @return string an html snippet
372372
*/
@@ -376,7 +376,7 @@ private function getTextarea(
376376
string $columnNameAppendix,
377377
string $onChangeClause,
378378
string $specialCharsEncoded,
379-
string $dataType,
379+
TypeClass $dataType,
380380
): string {
381381
$theClass = '';
382382
$textAreaRows = $this->config->settings['TextareaRows'];
@@ -407,7 +407,7 @@ private function getTextarea(
407407
. ' id="field_' . $this->fieldIndex . '_3"'
408408
. ($onChangeClause !== '' ? ' onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' : '')
409409
. ' tabindex="' . $this->fieldIndex . '"'
410-
. ' data-type="' . $dataType . '">'
410+
. ' data-type="' . $dataType->value . '">'
411411
. $specialCharsEncoded
412412
. '</textarea>';
413413
}
@@ -578,7 +578,7 @@ private function getValueColumnForOtherDatatypes(
578578
$specialChars,
579579
$fieldsize,
580580
$onChangeClause,
581-
$dataType,
581+
$dataType->value,
582582
);
583583
}
584584

@@ -1705,7 +1705,7 @@ private function getHtmlForInsertEditFormColumn(
17051705

17061706
$columnValue = '';
17071707
$foreignDropdown = '';
1708-
$dataType = '';
1708+
$dataType = TypeClass::Unknown;
17091709
$textAreaRows = $this->config->settings['TextareaRows'];
17101710
$textareaCols = $this->config->settings['TextareaCols'];
17111711
$maxlength = '';
@@ -1823,7 +1823,7 @@ private function getHtmlForInsertEditFormColumn(
18231823
'data' => $data,
18241824
'gis_data_types' => Gis::getDataTypes(),
18251825
'foreign_dropdown' => $foreignDropdown,
1826-
'data_type' => $dataType,
1826+
'data_type' => $dataType->value,
18271827
'textarea_cols' => $textareaCols,
18281828
'textarea_rows' => $textAreaRows,
18291829
'max_length' => $maxlength,

src/TypeClass.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin;
6+
7+
enum TypeClass: string
8+
{
9+
case Number = 'NUMBER';
10+
case Date = 'DATE';
11+
case Char = 'CHAR';
12+
case Spatial = 'SPATIAL';
13+
case Json = 'JSON';
14+
case Uuid = 'UUID';
15+
case Unknown = '';
16+
}

0 commit comments

Comments
 (0)