Skip to content

Commit 4b71da0

Browse files
Merge pull request #18127 from kamil-tekiela/nonUnique-to-bool
Change nonUnique prop to be bool
2 parents 2a4803a + 1967a25 commit 4b71da0

3 files changed

Lines changed: 12 additions & 22 deletions

File tree

‎libraries/classes/Controllers/Table/IndexesController.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ private function displayForm(Index $index): void
114114
if (isset($_POST['create_edit_table'])) {
115115
$fields = json_decode($_POST['columns'], true);
116116
$index_params = [
117-
'Non_unique' => $_POST['index']['Index_choice'] === 'UNIQUE'
118-
? '0' : '1',
117+
'Non_unique' => $_POST['index']['Index_choice'] !== 'UNIQUE',
119118
];
120119
$index->set($index_params);
121120
$add_fields = count($fields);

‎libraries/classes/Index.php‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class Index
7373
*/
7474
private $comment = '';
7575

76-
/** @var int 0 if the index cannot contain duplicates, 1 if it can. */
77-
private $nonUnique = 0;
76+
/** @var bool false if the index cannot contain duplicates, true if it can. */
77+
private bool $nonUnique = false;
7878

7979
/**
8080
* Indicates how the key is packed. NULL if it is not.
@@ -317,7 +317,7 @@ public function set(array $params): void
317317
}
318318

319319
if (isset($params['Non_unique'])) {
320-
$this->nonUnique = $params['Non_unique'];
320+
$this->nonUnique = (bool) $params['Non_unique'];
321321
}
322322

323323
if (isset($params['Packed'])) {
@@ -334,7 +334,7 @@ public function set(array $params): void
334334
} elseif ($this->type === 'SPATIAL') {
335335
$this->choice = 'SPATIAL';
336336
$this->type = '';
337-
} elseif ($this->nonUnique == '0') {
337+
} elseif (! $this->nonUnique) {
338338
$this->choice = 'UNIQUE';
339339
} else {
340340
$this->choice = 'INDEX';
@@ -480,11 +480,11 @@ public function isPacked()
480480
}
481481

482482
/**
483-
* Returns integer 0 if the index cannot contain duplicates, 1 if it can
483+
* Returns bool false if the index cannot contain duplicates, true if it can
484484
*
485-
* @return int 0 if the index cannot contain duplicates, 1 if it can
485+
* @return bool false if the index cannot contain duplicates, true if it can
486486
*/
487-
public function getNonUnique()
487+
public function getNonUnique(): bool
488488
{
489489
return $this->nonUnique;
490490
}
@@ -494,23 +494,15 @@ public function getNonUnique()
494494
*
495495
* @param bool $as_text whether to output should be in text
496496
*
497-
* @return mixed whether the index is a 'Unique' index
497+
* @return string|bool whether the index is a 'Unique' index
498498
*/
499-
public function isUnique($as_text = false)
499+
public function isUnique($as_text = false): string|bool
500500
{
501501
if ($as_text) {
502-
$r = [
503-
'0' => __('Yes'),
504-
'1' => __('No'),
505-
];
506-
} else {
507-
$r = [
508-
'0' => true,
509-
'1' => false,
510-
];
502+
return $this->nonUnique ? __('No') : __('Yes');
511503
}
512504

513-
return $r[$this->nonUnique];
505+
return ! $this->nonUnique;
514506
}
515507

516508
/**

‎psalm-baseline.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9166,7 +9166,6 @@
91669166
<code><![CDATA[$this->choice]]></code>
91679167
<code><![CDATA[$this->comment]]></code>
91689168
<code><![CDATA[$this->name]]></code>
9169-
<code><![CDATA[$this->nonUnique]]></code>
91709169
<code><![CDATA[$this->packed]]></code>
91719170
<code><![CDATA[$this->parser]]></code>
91729171
<code><![CDATA[$this->remarks]]></code>

0 commit comments

Comments
 (0)