Add isNullable

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-11-29 19:36:22 +01:00
parent d2b967cf49
commit a33c982ff3
7 changed files with 25 additions and 27 deletions

View File

@ -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

View File

@ -103,7 +103,7 @@
</td>
<td>{{ column.getCardinality() }}</td>
<td>{{ column.getCollation() }}</td>
<td>{{ column.getNull(true) }}</td>
<td>{{ column.getNull() }}</td>
{% if column.getSeqInIndex() == 1 %}
<td rowspan="{{ columns_count }}">{{ index.getComments() }}</td>

View File

@ -78,7 +78,7 @@
</td>
<td>{{ column.getCardinality() }}</td>
<td>{{ column.getCollation() }}</td>
<td>{{ column.getNull(true) }}</td>
<td>{{ column.getNull() }}</td>
{% if column.getSeqInIndex() == 1 %}
<td rowspan="{{ columns_count }}">{{ index.getComments() }}</td>

View File

@ -544,7 +544,7 @@
</td>
<td>{{ column.getCardinality() }}</td>
<td>{{ column.getCollation() }}</td>
<td>{{ column.getNull(true) }}</td>
<td>{{ column.getNull() }}</td>
{% if column.getSeqInIndex() == 1 %}
<td rowspan="{{ columns_count }}">{{ index.getComments() }}</td>

View File

@ -423,7 +423,7 @@ class TableController extends AbstractController
$notNull = true;
foreach ($idx->getColumns() as $column) {
if ($column->getNull()) {
if ($column->isNullable()) {
$notNull = false;
break;
}

View File

@ -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';
}
/**

View File

@ -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