Skip to content

Commit 895c118

Browse files
Merge pull request #18625 from kamil-tekiela/Constructor-property-promotion
Constructor property promotion - risky
2 parents 17ffc86 + 95a98cc commit 895c118

25 files changed

Lines changed: 99 additions & 288 deletions

‎libraries/classes/Charsets/Charset.php‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,17 @@
1313
final class Charset
1414
{
1515
/**
16-
* The character set name
17-
*/
18-
private string $name;
19-
20-
/**
21-
* A description of the character set
22-
*/
23-
private string $description;
24-
25-
/**
26-
* The default collation for the character set
27-
*/
28-
private string $defaultCollation;
29-
30-
/**
31-
* The maximum number of bytes required to store one character
32-
*/
33-
private int $maxLength;
34-
35-
/**
36-
* @param string $name Charset name
37-
* @param string $description Description
38-
* @param string $defaultCollation Default collation
39-
* @param int $maxLength Maximum length
16+
* @param string $name The character set name
17+
* @param string $description A description of the character set
18+
* @param string $defaultCollation The default collation for the character set
19+
* @param int $maxLength The maximum number of bytes required to store one character
4020
*/
4121
private function __construct(
42-
string $name,
43-
string $description,
44-
string $defaultCollation,
45-
int $maxLength,
22+
private string $name,
23+
private string $description,
24+
private string $defaultCollation,
25+
private int $maxLength,
4626
) {
47-
$this->name = $name;
48-
$this->description = $description;
49-
$this->defaultCollation = $defaultCollation;
50-
$this->maxLength = $maxLength;
5127
}
5228

5329
/**

‎libraries/classes/Charsets/Collation.php‎

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,29 @@
1717
*/
1818
final class Collation
1919
{
20-
/**
21-
* The collation name
22-
*/
23-
private string $name;
24-
2520
/**
2621
* A description of the collation
2722
*/
2823
private string $description;
2924

3025
/**
31-
* The name of the character set with which the collation is associated
32-
*/
33-
private string $charset;
34-
35-
/**
36-
* The collation ID
37-
*/
38-
private int $id;
39-
40-
/**
41-
* Whether the collation is the default for its character set
42-
*/
43-
private bool $isDefault;
44-
45-
/**
46-
* Whether the character set is compiled into the server
47-
*/
48-
private bool $isCompiled;
49-
50-
/**
51-
* Used for determining the memory used to sort strings in this collation
52-
*/
53-
private int $sortLength;
54-
55-
/**
56-
* The collation pad attribute
57-
*/
58-
private string $padAttribute;
59-
60-
/**
61-
* @param string $name Collation name
62-
* @param string $charset Related charset
63-
* @param int $id Collation ID
64-
* @param bool $isDefault Whether is the default
65-
* @param bool $isCompiled Whether the charset is compiled
66-
* @param int $sortLength Sort length
67-
* @param string $padAttribute Pad attribute
26+
* @param string $name The collation name
27+
* @param string $charset The name of the character set with which the collation is associated
28+
* @param int $id The collation ID
29+
* @param bool $isDefault Whether the collation is the default for its character set
30+
* @param bool $isCompiled Whether the character set is compiled into the server
31+
* @param int $sortLength Used for determining the memory used to sort strings in this collation
32+
* @param string $padAttribute The collation pad attribute
6833
*/
6934
private function __construct(
70-
string $name,
71-
string $charset,
72-
int $id,
73-
bool $isDefault,
74-
bool $isCompiled,
75-
int $sortLength,
76-
string $padAttribute,
35+
private string $name,
36+
private string $charset,
37+
private int $id,
38+
private bool $isDefault,
39+
private bool $isCompiled,
40+
private int $sortLength,
41+
private string $padAttribute,
7742
) {
78-
$this->name = $name;
79-
$this->charset = $charset;
80-
$this->id = $id;
81-
$this->isDefault = $isDefault;
82-
$this->isCompiled = $isCompiled;
83-
$this->sortLength = $sortLength;
84-
$this->padAttribute = $padAttribute;
8543
$this->description = $this->buildDescription();
8644
}
8745

‎libraries/classes/Config/ConfigFile.php‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ class ConfigFile
4141
*/
4242
private array $cfgDb;
4343

44-
/**
45-
* Stores original PMA config, not modified by user preferences
46-
*
47-
* @var mixed[]|null
48-
*/
49-
private array|null $baseCfg = null;
50-
5144
/**
5245
* Whether we are currently working in PMA Setup context
5346
*/
@@ -81,19 +74,18 @@ class ConfigFile
8174

8275
/**
8376
* @param mixed[]|null $baseConfig base configuration read from
84-
* {@link PhpMyAdmin\Config::$base_config},
85-
* use only when not in PMA Setup
77+
{@link PhpMyAdmin\Config::$base_config},
78+
use only when not in PMA Setup
79+
Stores original PMA config, not modified by user preferences
8680
*/
87-
public function __construct(array|null $baseConfig = null)
81+
public function __construct(private array|null $baseConfig = null)
8882
{
8983
// load default config values
9084
$settings = new Settings([]);
9185
$this->defaultCfg = $settings->asArray();
9286

9387
// load additional config information
9488
$this->cfgDb = $this->getAllowedValues();
95-
96-
$this->baseCfg = $baseConfig;
9789
$this->isInSetup = $baseConfig === null;
9890
$this->id = 'ConfigFile' . $GLOBALS['server'];
9991
if (isset($_SESSION[$this->id])) {
@@ -206,7 +198,7 @@ public function set(string $path, mixed $value, string|null $canonicalPath = nul
206198
// get original config values not overwritten by user
207199
// preferences to allow for overwriting options set in
208200
// config.inc.php with default values
209-
$instanceDefaultValue = Core::arrayRead($canonicalPath, $this->baseCfg);
201+
$instanceDefaultValue = Core::arrayRead($canonicalPath, $this->baseConfig);
210202
// remove if it has a default value and base config (config.inc.php)
211203
// uses default value
212204
$removePath = $removePath

‎libraries/classes/Config/Form.php‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ class Form
3636
*/
3737
public string $name;
3838

39-
/**
40-
* Arbitrary index, doesn't affect class' behavior
41-
*/
42-
public int|null $index;
43-
4439
/**
4540
* Form fields (paths), filled by {@link readFormPaths()}, indexed by field name
4641
*
@@ -62,11 +57,6 @@ class Form
6257
*/
6358
private array $fieldsTypes;
6459

65-
/**
66-
* ConfigFile instance
67-
*/
68-
private ConfigFile $configFile;
69-
7060
/**
7161
* A counter for the number of groups
7262
*/
@@ -75,19 +65,17 @@ class Form
7565
/**
7666
* Reads default config values
7767
*
78-
* @param string $formName Form name
79-
* @param mixed[] $form Form data
80-
* @param ConfigFile $cf Config file instance
81-
* @param int|null $index arbitrary index, stored in Form::$index
68+
* @param string $formName Form name
69+
* @param mixed[] $form Form data
70+
* @param ConfigFile $configFile ConfigFile instance
71+
* @param int|null $index Arbitrary index, doesn't affect class' behavior
8272
*/
8373
public function __construct(
8474
string $formName,
8575
array $form,
86-
ConfigFile $cf,
87-
int|null $index = null,
76+
private ConfigFile $configFile,
77+
public int|null $index = null,
8878
) {
89-
$this->index = $index;
90-
$this->configFile = $cf;
9179
$this->loadForm($formName, $form);
9280
}
9381

‎libraries/classes/Config/FormDisplay.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
*/
4646
class FormDisplay
4747
{
48-
/**
49-
* ConfigFile instance
50-
*/
51-
private ConfigFile $configFile;
52-
5348
/**
5449
* Form list
5550
*
@@ -102,11 +97,9 @@ class FormDisplay
10297

10398
private bool $isSetupScript;
10499

105-
/** @param ConfigFile $cf Config file instance */
106-
public function __construct(ConfigFile $cf)
100+
public function __construct(private ConfigFile $configFile)
107101
{
108102
$this->formDisplayTemplate = new FormDisplayTemplate($GLOBALS['config']);
109-
$this->configFile = $cf;
110103
$this->isSetupScript = Sanitize::isSetup();
111104
// initialize validators
112105
Validator::getValidators($this->configFile);

‎libraries/classes/Config/ServerConfigChecks.php‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@
3030
*/
3131
class ServerConfigChecks
3232
{
33-
/** @var ConfigFile configurations being checked */
34-
protected ConfigFile $cfg;
35-
36-
/** @param ConfigFile $cfg Configuration */
37-
public function __construct(ConfigFile $cfg)
33+
public function __construct(protected ConfigFile $cfg)
3834
{
39-
$this->cfg = $cfg;
4035
}
4136

4237
/**

‎libraries/classes/Controllers/Server/Privileges/AccountLockController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
final class AccountLockController extends AbstractController
1919
{
20-
private AccountLocking $model;
21-
22-
public function __construct(ResponseRenderer $response, Template $template, AccountLocking $accountLocking)
20+
public function __construct(ResponseRenderer $response, Template $template, private AccountLocking $model)
2321
{
2422
parent::__construct($response, $template);
25-
26-
$this->model = $accountLocking;
2723
}
2824

2925
public function __invoke(ServerRequest $request): void

‎libraries/classes/Controllers/Server/Privileges/AccountUnlockController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
final class AccountUnlockController extends AbstractController
1919
{
20-
private AccountLocking $model;
21-
22-
public function __construct(ResponseRenderer $response, Template $template, AccountLocking $accountLocking)
20+
public function __construct(ResponseRenderer $response, Template $template, private AccountLocking $model)
2321
{
2422
parent::__construct($response, $template);
25-
26-
$this->model = $accountLocking;
2723
}
2824

2925
public function __invoke(ServerRequest $request): void

‎libraries/classes/Controllers/Table/Partition/AnalyzeController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121

2222
final class AnalyzeController extends AbstractController
2323
{
24-
private Maintenance $model;
25-
2624
public function __construct(
2725
ResponseRenderer $response,
2826
Template $template,
29-
Maintenance $maintenance,
27+
private Maintenance $model,
3028
) {
3129
parent::__construct($response, $template);
32-
33-
$this->model = $maintenance;
3430
}
3531

3632
public function __invoke(ServerRequest $request): void

‎libraries/classes/Controllers/Table/Partition/CheckController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121

2222
final class CheckController extends AbstractController
2323
{
24-
private Maintenance $model;
25-
2624
public function __construct(
2725
ResponseRenderer $response,
2826
Template $template,
29-
Maintenance $maintenance,
27+
private Maintenance $model,
3028
) {
3129
parent::__construct($response, $template);
32-
33-
$this->model = $maintenance;
3430
}
3531

3632
public function __invoke(ServerRequest $request): void

0 commit comments

Comments
 (0)