Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / IndexColumn.php
blobcdec660a0bc991a0873f5ee8ef659aa836dece46
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin;
7 use function __;
9 /**
10 * Index column wrapper
12 class IndexColumn
14 /** @var string The column name */
15 private string $name = '';
17 /** @var int The column sequence number in the index, starting with 1. */
18 private int $seqInIndex = 1;
20 /** @var string|null How the column is sorted in the index. "A" (Ascending) or NULL (Not sorted) */
21 private string|null $collation = null;
23 /**
24 * The number of indexed characters if the column is only partly indexed,
25 * NULL if the entire column is indexed.
27 private int|null $subPart = null;
29 /**
30 * Contains YES if the column may contain NULL.
31 * If not, the column contains NO.
33 private string $null = '';
35 /**
36 * An estimate of the number of unique values in the index. This is updated
37 * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
38 * statistics stored as integers, so the value is not necessarily exact even
39 * for small tables. The higher the cardinality, the greater the chance that
40 * MySQL uses the index when doing joins.
42 private int|null $cardinality = null;
44 /**
45 * If the Index uses an expression and not a name
47 private string|null $expression = null;
49 /** @param mixed[] $params an array containing the parameters of the index column */
50 public function __construct(array $params = [])
52 $this->set($params);
55 /**
56 * If the Index has an expression
58 public function hasExpression(): bool
60 return $this->expression !== null;
63 /**
64 * The Index expression if it has one
66 public function getExpression(): string|null
68 return $this->expression;
71 /**
72 * Sets parameters of the index column
74 * @param mixed[] $params an array containing the parameters of the index column
76 public function set(array $params): void
78 if (isset($params['Column_name'])) {
79 $this->name = $params['Column_name'];
82 if (isset($params['Seq_in_index'])) {
83 $this->seqInIndex = (int) $params['Seq_in_index'];
86 if (isset($params['Collation'])) {
87 $this->collation = $params['Collation'];
90 if (isset($params['Cardinality'])) {
91 $this->cardinality = (int) $params['Cardinality'];
94 if (isset($params['Sub_part'])) {
95 $this->subPart = (int) $params['Sub_part'];
98 if (isset($params['Expression'])) {
99 $this->expression = $params['Expression'];
102 if (! isset($params['Null'])) {
103 return;
106 $this->null = $params['Null'];
110 * Returns the column name
112 * @return string column name
114 public function getName(): string
116 return $this->name;
120 * Return the column collation
122 * @return string|null column collation
124 public function getCollation(): string|null
126 return $this->collation;
130 * Returns the cardinality of the column
132 * @return int|null cardinality of the column
134 public function getCardinality(): int|null
136 return $this->cardinality;
140 * Returns the text whether the column is nullable
142 public function getNull(): string
144 if ($this->null === '' || $this->null === 'NO') {
145 return __('No');
148 return __('Yes');
151 public function isNullable(): bool
153 return $this->null === 'YES';
157 * Returns the sequence number of the column in the index
159 * @return int sequence number of the column in the index
161 public function getSeqInIndex(): int
163 return $this->seqInIndex;
167 * Returns the number of indexed characters if the column is only
168 * partly indexed
170 * @return int|null the number of indexed characters
172 public function getSubPart(): int|null
174 return $this->subPart;
178 * Gets the properties in an array for comparison purposes
180 * @return array<string, int|string|null>
181 * @psalm-return array{
182 * Column_name: string,
183 * Seq_in_index: int,
184 * Collation: string|null,
185 * Sub_part: int|null,
186 * Null: string
189 public function getCompareData(): array
191 return [
192 'Column_name' => $this->name,
193 'Seq_in_index' => $this->seqInIndex,
194 'Collation' => $this->collation,
195 'Sub_part' => $this->subPart,
196 'Null' => $this->null,