Skip to content

Commit 5d17681

Browse files
Refactor SubPartition and Partition (#18142)
* Set native types Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Remove redundant variable Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Update baselines Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent ab4af68 commit 5d17681

4 files changed

Lines changed: 36 additions & 90 deletions

File tree

libraries/classes/Partitioning/Partition.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@
99

1010
use function array_values;
1111

12-
/**
13-
* base Partition Class
14-
*/
1512
class Partition extends SubPartition
1613
{
17-
/** @var string partition description */
18-
protected $description;
19-
/** @var SubPartition[] sub partitions */
20-
protected $subPartitions = [];
14+
protected string|null $description = null;
15+
/** @var SubPartition[] */
16+
protected array $subPartitions = [];
2117

2218
/**
2319
* Loads data from the fetched row from information_schema.PARTITIONS
2420
*
2521
* @param array $row fetched row
2622
*/
27-
protected function loadData(array $row): void
23+
public function __construct(array $row)
2824
{
2925
$this->name = $row['PARTITION_NAME'];
30-
$this->ordinal = $row['PARTITION_ORDINAL_POSITION'];
26+
$this->ordinal = $row['PARTITION_ORDINAL_POSITION'] !== null ? (int) $row['PARTITION_ORDINAL_POSITION'] : null;
3127
$this->method = $row['PARTITION_METHOD'];
3228
$this->expression = $row['PARTITION_EXPRESSION'];
3329
$this->description = $row['PARTITION_DESCRIPTION'];
@@ -41,30 +37,26 @@ protected function loadData(array $row): void
4137

4238
/**
4339
* Returns the partition description
44-
*
45-
* @return string partition description
4640
*/
47-
public function getDescription(): string
41+
public function getDescription(): string|null
4842
{
4943
return $this->description;
5044
}
5145

5246
/**
5347
* Add a sub partition
54-
*
55-
* @param SubPartition $partition Sub partition
5648
*/
57-
public function addSubPartition(SubPartition $partition): void
49+
public function addSubPartition(SubPartition $subPartition): void
5850
{
59-
$this->subPartitions[] = $partition;
51+
$this->subPartitions[] = $subPartition;
6052
}
6153

6254
/**
6355
* Whether there are sub partitions
6456
*/
6557
public function hasSubPartitions(): bool
6658
{
67-
return ! empty($this->subPartitions);
59+
return $this->subPartitions !== [];
6860
}
6961

7062
/**
@@ -74,7 +66,7 @@ public function hasSubPartitions(): bool
7466
*/
7567
public function getRows(): int
7668
{
77-
if (empty($this->subPartitions)) {
69+
if ($this->subPartitions === []) {
7870
return $this->rows;
7971
}
8072

@@ -93,7 +85,7 @@ public function getRows(): int
9385
*/
9486
public function getDataLength(): int
9587
{
96-
if (empty($this->subPartitions)) {
88+
if ($this->subPartitions === []) {
9789
return $this->dataLength;
9890
}
9991

@@ -112,7 +104,7 @@ public function getDataLength(): int
112104
*/
113105
public function getIndexLength(): int
114106
{
115-
if (empty($this->subPartitions)) {
107+
if ($this->subPartitions === []) {
116108
return $this->indexLength;
117109
}
118110

@@ -165,9 +157,7 @@ public static function getPartitions($db, $table): array
165157
continue;
166158
}
167159

168-
$parentPartition = $partition;
169-
$partition = new SubPartition($row);
170-
$parentPartition->addSubPartition($partition);
160+
$partition->addSubPartition(new SubPartition($row));
171161
}
172162

173163
return array_values($partitionMap);

libraries/classes/Partitioning/SubPartition.php

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,25 @@
1212
*/
1313
class SubPartition
1414
{
15-
/** @var string partition name */
16-
protected $name;
17-
/** @var int ordinal */
18-
protected $ordinal;
19-
/** @var string partition method */
20-
protected $method;
21-
/** @var string partition expression */
22-
protected $expression;
23-
/** @var int no of table rows in the partition */
24-
protected $rows;
25-
/** @var int data length */
26-
protected $dataLength;
27-
/** @var int index length */
28-
protected $indexLength;
29-
/** @var string partition comment */
30-
protected $comment;
15+
protected string|null $name = null;
16+
protected int|null $ordinal = null;
17+
protected string|null $method = null;
18+
protected string|null $expression = null;
19+
protected int $rows = 0;
20+
protected int $dataLength = 0;
21+
protected int $indexLength = 0;
22+
protected string $comment = '';
3123

3224
/**
3325
* Constructs a partition
3426
*
3527
* @param array $row fetched row from information_schema.PARTITIONS
3628
*/
3729
public function __construct(array $row)
38-
{
39-
$this->loadData($row);
40-
}
41-
42-
/**
43-
* Loads data from the fetched row from information_schema.PARTITIONS
44-
*
45-
* @param array $row fetched row
46-
*/
47-
protected function loadData(array $row): void
4830
{
4931
$this->name = $row['SUBPARTITION_NAME'];
50-
$this->ordinal = $row['SUBPARTITION_ORDINAL_POSITION'];
32+
$this->ordinal = $row['SUBPARTITION_ORDINAL_POSITION'] !== null
33+
? (int) $row['SUBPARTITION_ORDINAL_POSITION'] : null;
5134
$this->method = $row['SUBPARTITION_METHOD'];
5235
$this->expression = $row['SUBPARTITION_EXPRESSION'];
5336
$this->loadCommonData($row);
@@ -60,56 +43,46 @@ protected function loadData(array $row): void
6043
*/
6144
protected function loadCommonData(array $row): void
6245
{
63-
$this->rows = $row['TABLE_ROWS'];
64-
$this->dataLength = $row['DATA_LENGTH'];
65-
$this->indexLength = $row['INDEX_LENGTH'];
46+
$this->rows = (int) $row['TABLE_ROWS'];
47+
$this->dataLength = (int) $row['DATA_LENGTH'];
48+
$this->indexLength = (int) $row['INDEX_LENGTH'];
6649
$this->comment = $row['PARTITION_COMMENT'];
6750
}
6851

6952
/**
7053
* Return the partition name
71-
*
72-
* @return string partition name
7354
*/
74-
public function getName(): string
55+
public function getName(): string|null
7556
{
7657
return $this->name;
7758
}
7859

7960
/**
8061
* Return the ordinal of the partition
81-
*
82-
* @return int the ordinal
8362
*/
84-
public function getOrdinal(): int
63+
public function getOrdinal(): int|null
8564
{
8665
return $this->ordinal;
8766
}
8867

8968
/**
9069
* Returns the partition method
91-
*
92-
* @return string partition method
9370
*/
94-
public function getMethod(): string
71+
public function getMethod(): string|null
9572
{
9673
return $this->method;
9774
}
9875

9976
/**
10077
* Returns the partition expression
101-
*
102-
* @return string partition expression
10378
*/
104-
public function getExpression(): string
79+
public function getExpression(): string|null
10580
{
10681
return $this->expression;
10782
}
10883

10984
/**
11085
* Returns the number of data rows
111-
*
112-
* @return int number of rows
11386
*/
11487
public function getRows(): int
11588
{
@@ -118,8 +91,6 @@ public function getRows(): int
11891

11992
/**
12093
* Returns the data length
121-
*
122-
* @return int data length
12394
*/
12495
public function getDataLength(): int
12596
{
@@ -128,8 +99,6 @@ public function getDataLength(): int
12899

129100
/**
130101
* Returns the index length
131-
*
132-
* @return int index length
133102
*/
134103
public function getIndexLength(): int
135104
{
@@ -138,8 +107,6 @@ public function getIndexLength(): int
138107

139108
/**
140109
* Returns the partition comment
141-
*
142-
* @return string partition comment
143110
*/
144111
public function getComment(): string
145112
{

phpstan-baseline.neon

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6021,12 +6021,12 @@ parameters:
60216021
path: libraries/classes/Partitioning/Maintenance.php
60226022

60236023
-
6024-
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\Partition\\:\\:getPartitionNames\\(\\) return type has no value type specified in iterable type array\\.$#"
6024+
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\Partition\\:\\:__construct\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
60256025
count: 1
60266026
path: libraries/classes/Partitioning/Partition.php
60276027

60286028
-
6029-
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\Partition\\:\\:loadData\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
6029+
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\Partition\\:\\:getPartitionNames\\(\\) return type has no value type specified in iterable type array\\.$#"
60306030
count: 1
60316031
path: libraries/classes/Partitioning/Partition.php
60326032

@@ -6036,17 +6036,17 @@ parameters:
60366036
path: libraries/classes/Partitioning/Partition.php
60376037

60386038
-
6039-
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\SubPartition\\:\\:__construct\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
6039+
message: "#^PhpMyAdmin\\\\Partitioning\\\\Partition\\:\\:__construct\\(\\) does not call parent constructor from PhpMyAdmin\\\\Partitioning\\\\SubPartition\\.$#"
60406040
count: 1
6041-
path: libraries/classes/Partitioning/SubPartition.php
6041+
path: libraries/classes/Partitioning/Partition.php
60426042

60436043
-
6044-
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\SubPartition\\:\\:loadCommonData\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
6044+
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\SubPartition\\:\\:__construct\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
60456045
count: 1
60466046
path: libraries/classes/Partitioning/SubPartition.php
60476047

60486048
-
6049-
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\SubPartition\\:\\:loadData\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
6049+
message: "#^Method PhpMyAdmin\\\\Partitioning\\\\SubPartition\\:\\:loadCommonData\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#"
60506050
count: 1
60516051
path: libraries/classes/Partitioning/SubPartition.php
60526052

psalm-baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10329,7 +10329,6 @@
1032910329
<code><![CDATA[$this->expression]]></code>
1033010330
<code><![CDATA[$this->method]]></code>
1033110331
<code><![CDATA[$this->name]]></code>
10332-
<code><![CDATA[$this->ordinal]]></code>
1033310332
<code>$value</code>
1033410333
</MixedAssignment>
1033510334
<MixedInferredReturnType>
@@ -10346,23 +10345,13 @@
1034610345
<code>getSubPartitions</code>
1034710346
<code>hasSubPartitions</code>
1034810347
</PossiblyUnusedMethod>
10349-
<PropertyNotSetInConstructor>
10350-
<code>Partition</code>
10351-
<code>Partition</code>
10352-
<code>Partition</code>
10353-
<code>Partition</code>
10354-
</PropertyNotSetInConstructor>
1035510348
</file>
1035610349
<file src="libraries/classes/Partitioning/SubPartition.php">
1035710350
<MixedAssignment>
1035810351
<code><![CDATA[$this->comment]]></code>
10359-
<code><![CDATA[$this->dataLength]]></code>
1036010352
<code><![CDATA[$this->expression]]></code>
10361-
<code><![CDATA[$this->indexLength]]></code>
1036210353
<code><![CDATA[$this->method]]></code>
1036310354
<code><![CDATA[$this->name]]></code>
10364-
<code><![CDATA[$this->ordinal]]></code>
10365-
<code><![CDATA[$this->rows]]></code>
1036610355
</MixedAssignment>
1036710356
</file>
1036810357
<file src="libraries/classes/Partitioning/TablePartitionDefinition.php">

0 commit comments

Comments
 (0)