diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b7708eca8c..b2d998709a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4200,11 +4200,6 @@ parameters: count: 1 path: src/Controllers/Operations/TableController.php - - - message: "#^Only booleans are allowed in an if condition, string given\\.$#" - count: 1 - path: src/Controllers/Operations/TableController.php - - message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumns\\(\\) expects string, mixed given\\.$#" count: 1 diff --git a/resources/templates/database/data_dictionary/index.twig b/resources/templates/database/data_dictionary/index.twig index d1b1b221cb..c35303fa04 100644 --- a/resources/templates/database/data_dictionary/index.twig +++ b/resources/templates/database/data_dictionary/index.twig @@ -103,7 +103,7 @@ {{ column.getCardinality() }} {{ column.getCollation() }} - {{ column.getNull(true) }} + {{ column.getNull() }} {% if column.getSeqInIndex() == 1 %} {{ index.getComments() }} diff --git a/resources/templates/indexes.twig b/resources/templates/indexes.twig index d31f0067b1..19fdb10b5c 100644 --- a/resources/templates/indexes.twig +++ b/resources/templates/indexes.twig @@ -78,7 +78,7 @@ {{ column.getCardinality() }} {{ column.getCollation() }} - {{ column.getNull(true) }} + {{ column.getNull() }} {% if column.getSeqInIndex() == 1 %} {{ index.getComments() }} diff --git a/resources/templates/table/structure/display_structure.twig b/resources/templates/table/structure/display_structure.twig index 975c178a28..de6a2562e4 100644 --- a/resources/templates/table/structure/display_structure.twig +++ b/resources/templates/table/structure/display_structure.twig @@ -544,7 +544,7 @@ {{ column.getCardinality() }} {{ column.getCollation() }} - {{ column.getNull(true) }} + {{ column.getNull() }} {% if column.getSeqInIndex() == 1 %} {{ index.getComments() }} diff --git a/src/Controllers/Operations/TableController.php b/src/Controllers/Operations/TableController.php index 8056776f7a..bf98a92a7e 100644 --- a/src/Controllers/Operations/TableController.php +++ b/src/Controllers/Operations/TableController.php @@ -423,7 +423,7 @@ class TableController extends AbstractController $notNull = true; foreach ($idx->getColumns() as $column) { - if ($column->getNull()) { + if ($column->isNullable()) { $notNull = false; break; } diff --git a/src/IndexColumn.php b/src/IndexColumn.php index 1201d6684c..cdec660a0b 100644 --- a/src/IndexColumn.php +++ b/src/IndexColumn.php @@ -137,24 +137,20 @@ class IndexColumn } /** - * Returns whether the column is nullable - * - * @param bool $asText whether to returned the string representation - * - * @return string nullability of the column. True/false or Yes/No depending - * on the value of the $as_text parameter + * Returns the text whether the column is nullable */ - public function getNull(bool $asText = false): string + public function getNull(): string { - if ($asText) { - if ($this->null === '' || $this->null === 'NO') { - return __('No'); - } - - return __('Yes'); + if ($this->null === '' || $this->null === 'NO') { + return __('No'); } - return $this->null; + return __('Yes'); + } + + public function isNullable(): bool + { + return $this->null === 'YES'; } /** diff --git a/test/classes/IndexColumnTest.php b/test/classes/IndexColumnTest.php index a89964d57d..0dc3ed0883 100644 --- a/test/classes/IndexColumnTest.php +++ b/test/classes/IndexColumnTest.php @@ -20,11 +20,18 @@ class IndexColumnTest extends TestCase public function testGetNull(): void { - $this->assertEquals('', $this->object->getNull()); - $this->assertEquals('No', $this->object->getNull(true)); + $this->object->set(['Null' => '']); + $this->assertEquals('No', $this->object->getNull()); $this->object->set(['Null' => 'YES']); - $this->assertEquals('YES', $this->object->getNull()); - $this->assertEquals('Yes', $this->object->getNull(true)); + $this->assertEquals('Yes', $this->object->getNull()); + } + + public function testIsNullable(): void + { + $this->object->set(['Null' => '']); + $this->assertEquals(false, $this->object->isNullable()); + $this->object->set(['Null' => 'YES']); + $this->assertEquals(true, $this->object->isNullable()); } public function testGetSeqInIndex(): void