Constructor property promotion - risky

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-08-14 23:10:48 +01:00
parent 17ffc863a5
commit 95a98ccd04
25 changed files with 100 additions and 289 deletions

View File

@ -13,41 +13,17 @@ namespace PhpMyAdmin\Charsets;
final class Charset
{
/**
* The character set name
*/
private string $name;
/**
* A description of the character set
*/
private string $description;
/**
* The default collation for the character set
*/
private string $defaultCollation;
/**
* The maximum number of bytes required to store one character
*/
private int $maxLength;
/**
* @param string $name Charset name
* @param string $description Description
* @param string $defaultCollation Default collation
* @param int $maxLength Maximum length
* @param string $name The character set name
* @param string $description A description of the character set
* @param string $defaultCollation The default collation for the character set
* @param int $maxLength The maximum number of bytes required to store one character
*/
private function __construct(
string $name,
string $description,
string $defaultCollation,
int $maxLength,
private string $name,
private string $description,
private string $defaultCollation,
private int $maxLength,
) {
$this->name = $name;
$this->description = $description;
$this->defaultCollation = $defaultCollation;
$this->maxLength = $maxLength;
}
/**

View File

@ -17,71 +17,29 @@ use function implode;
*/
final class Collation
{
/**
* The collation name
*/
private string $name;
/**
* A description of the collation
*/
private string $description;
/**
* The name of the character set with which the collation is associated
*/
private string $charset;
/**
* The collation ID
*/
private int $id;
/**
* Whether the collation is the default for its character set
*/
private bool $isDefault;
/**
* Whether the character set is compiled into the server
*/
private bool $isCompiled;
/**
* Used for determining the memory used to sort strings in this collation
*/
private int $sortLength;
/**
* The collation pad attribute
*/
private string $padAttribute;
/**
* @param string $name Collation name
* @param string $charset Related charset
* @param int $id Collation ID
* @param bool $isDefault Whether is the default
* @param bool $isCompiled Whether the charset is compiled
* @param int $sortLength Sort length
* @param string $padAttribute Pad attribute
* @param string $name The collation name
* @param string $charset The name of the character set with which the collation is associated
* @param int $id The collation ID
* @param bool $isDefault Whether the collation is the default for its character set
* @param bool $isCompiled Whether the character set is compiled into the server
* @param int $sortLength Used for determining the memory used to sort strings in this collation
* @param string $padAttribute The collation pad attribute
*/
private function __construct(
string $name,
string $charset,
int $id,
bool $isDefault,
bool $isCompiled,
int $sortLength,
string $padAttribute,
private string $name,
private string $charset,
private int $id,
private bool $isDefault,
private bool $isCompiled,
private int $sortLength,
private string $padAttribute,
) {
$this->name = $name;
$this->charset = $charset;
$this->id = $id;
$this->isDefault = $isDefault;
$this->isCompiled = $isCompiled;
$this->sortLength = $sortLength;
$this->padAttribute = $padAttribute;
$this->description = $this->buildDescription();
}

View File

@ -41,13 +41,6 @@ class ConfigFile
*/
private array $cfgDb;
/**
* Stores original PMA config, not modified by user preferences
*
* @var mixed[]|null
*/
private array|null $baseCfg = null;
/**
* Whether we are currently working in PMA Setup context
*/
@ -81,10 +74,11 @@ class ConfigFile
/**
* @param mixed[]|null $baseConfig base configuration read from
* {@link PhpMyAdmin\Config::$base_config},
* use only when not in PMA Setup
{@link PhpMyAdmin\Config::$base_config},
use only when not in PMA Setup
Stores original PMA config, not modified by user preferences
*/
public function __construct(array|null $baseConfig = null)
public function __construct(private array|null $baseConfig = null)
{
// load default config values
$settings = new Settings([]);
@ -92,8 +86,6 @@ class ConfigFile
// load additional config information
$this->cfgDb = $this->getAllowedValues();
$this->baseCfg = $baseConfig;
$this->isInSetup = $baseConfig === null;
$this->id = 'ConfigFile' . $GLOBALS['server'];
if (isset($_SESSION[$this->id])) {
@ -206,7 +198,7 @@ class ConfigFile
// get original config values not overwritten by user
// preferences to allow for overwriting options set in
// config.inc.php with default values
$instanceDefaultValue = Core::arrayRead($canonicalPath, $this->baseCfg);
$instanceDefaultValue = Core::arrayRead($canonicalPath, $this->baseConfig);
// remove if it has a default value and base config (config.inc.php)
// uses default value
$removePath = $removePath

View File

@ -36,11 +36,6 @@ class Form
*/
public string $name;
/**
* Arbitrary index, doesn't affect class' behavior
*/
public int|null $index;
/**
* Form fields (paths), filled by {@link readFormPaths()}, indexed by field name
*
@ -62,11 +57,6 @@ class Form
*/
private array $fieldsTypes;
/**
* ConfigFile instance
*/
private ConfigFile $configFile;
/**
* A counter for the number of groups
*/
@ -75,19 +65,17 @@ class Form
/**
* Reads default config values
*
* @param string $formName Form name
* @param mixed[] $form Form data
* @param ConfigFile $cf Config file instance
* @param int|null $index arbitrary index, stored in Form::$index
* @param string $formName Form name
* @param mixed[] $form Form data
* @param ConfigFile $configFile ConfigFile instance
* @param int|null $index Arbitrary index, doesn't affect class' behavior
*/
public function __construct(
string $formName,
array $form,
ConfigFile $cf,
int|null $index = null,
private ConfigFile $configFile,
public int|null $index = null,
) {
$this->index = $index;
$this->configFile = $cf;
$this->loadForm($formName, $form);
}

View File

@ -45,11 +45,6 @@ use const E_USER_WARNING;
*/
class FormDisplay
{
/**
* ConfigFile instance
*/
private ConfigFile $configFile;
/**
* Form list
*
@ -102,11 +97,9 @@ class FormDisplay
private bool $isSetupScript;
/** @param ConfigFile $cf Config file instance */
public function __construct(ConfigFile $cf)
public function __construct(private ConfigFile $configFile)
{
$this->formDisplayTemplate = new FormDisplayTemplate($GLOBALS['config']);
$this->configFile = $cf;
$this->isSetupScript = Sanitize::isSetup();
// initialize validators
Validator::getValidators($this->configFile);

View File

@ -30,13 +30,8 @@ use const SODIUM_CRYPTO_SECRETBOX_KEYBYTES;
*/
class ServerConfigChecks
{
/** @var ConfigFile configurations being checked */
protected ConfigFile $cfg;
/** @param ConfigFile $cfg Configuration */
public function __construct(ConfigFile $cfg)
public function __construct(protected ConfigFile $cfg)
{
$this->cfg = $cfg;
}
/**

View File

@ -17,13 +17,9 @@ use function __;
final class AccountLockController extends AbstractController
{
private AccountLocking $model;
public function __construct(ResponseRenderer $response, Template $template, AccountLocking $accountLocking)
public function __construct(ResponseRenderer $response, Template $template, private AccountLocking $model)
{
parent::__construct($response, $template);
$this->model = $accountLocking;
}
public function __invoke(ServerRequest $request): void

View File

@ -17,13 +17,9 @@ use function __;
final class AccountUnlockController extends AbstractController
{
private AccountLocking $model;
public function __construct(ResponseRenderer $response, Template $template, AccountLocking $accountLocking)
public function __construct(ResponseRenderer $response, Template $template, private AccountLocking $model)
{
parent::__construct($response, $template);
$this->model = $accountLocking;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class AnalyzeController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class CheckController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class DropController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class OptimizeController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class RebuildController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class RepairController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -21,16 +21,12 @@ use function __;
final class TruncateController extends AbstractController
{
private Maintenance $model;
public function __construct(
ResponseRenderer $response,
Template $template,
Maintenance $maintenance,
private Maintenance $model,
) {
parent::__construct($response, $template);
$this->model = $maintenance;
}
public function __invoke(ServerRequest $request): void

View File

@ -24,11 +24,6 @@ use function is_string;
*/
class Search
{
/**
* Database name
*/
private string $db;
/**
* Table Names
*
@ -70,10 +65,8 @@ class Search
*/
private string $criteriaColumnName;
/** @param string $db Database name */
public function __construct(private DatabaseInterface $dbi, string $db, public Template $template)
public function __construct(private DatabaseInterface $dbi, private string $db, public Template $template)
{
$this->db = $db;
$this->searchTypes = [
'1' => __('at least one of the words'),
'2' => __('all of the words'),

View File

@ -94,8 +94,6 @@ class DatabaseInterface implements DbalInterface
*/
public const GETVAR_GLOBAL = 2;
private DbiExtension $extension;
/**
* Opened database connections.
*
@ -133,10 +131,9 @@ class DatabaseInterface implements DbalInterface
private ListDatabase|null $databaseList = null;
/** @param DbiExtension $ext Object to be used for database queries */
public function __construct(DbiExtension $ext)
/** @param DbiExtension $extension Object to be used for database queries */
public function __construct(private DbiExtension $extension)
{
$this->extension = $ext;
if (defined('TESTSUITE')) {
$this->connections[Connection::TYPE_USER] = new Connection(new stdClass());
$this->connections[Connection::TYPE_CONTROL] = new Connection(new stdClass());

View File

@ -7,17 +7,13 @@ namespace PhpMyAdmin\Export;
/** @psalm-immutable */
final class Template
{
/** @var string JSON */
private string $data;
private function __construct(
private int $id,
private string $username,
private string $exportType,
private string $name,
string $data,
private string $data,
) {
$this->data = $data;
}
/** @param array<string, mixed> $state */

View File

@ -65,11 +65,6 @@ class GisVisualization
private string|null $labelColumn;
/** Number of rows */
private int $rows;
/** Start position */
private int $pos;
public function getWidth(): int
{
return $this->width;
@ -158,11 +153,15 @@ class GisVisualization
* or an array with data.
* If it is an array row and pos are ignored
* @param array<string,mixed> $options Users specified options
* @param int $rows number of rows
* @param int $pos start position
* @param int $rows Number of rows
* @param int $pos Start position
*/
private function __construct(array|string $sqlOrData, array $options, int $rows = 0, int $pos = 0)
{
private function __construct(
array|string $sqlOrData,
array $options,
private int $rows = 0,
private int $pos = 0,
) {
$width = $options['width'] ?? null;
Assert::positiveInteger($width);
$this->width = $width;
@ -179,9 +178,6 @@ class GisVisualization
Assert::nullOrStringNotEmpty($labelColumn);
$this->labelColumn = $labelColumn;
$this->pos = $pos;
$this->rows = $rows;
$this->data = is_string($sqlOrData)
? $this->modifyQueryAndFetch($sqlOrData)
: $sqlOrData;

View File

@ -49,11 +49,6 @@ use const DIRECTORY_SEPARATOR;
*/
class Git
{
/**
* Enable Git information search and process
*/
private bool $showGitRevision;
/**
* The path where the to search for .git folders
*/
@ -64,9 +59,9 @@ class Git
*/
private bool $hasGit = false;
public function __construct(bool $showGitRevision, string|null $baseDir = null)
/** @param bool $showGitRevision Enable Git information search and process */
public function __construct(private bool $showGitRevision, string|null $baseDir = null)
{
$this->showGitRevision = $showGitRevision;
$this->baseDir = $baseDir ?? ROOT_PATH;
}

View File

@ -28,16 +28,6 @@ use function preg_replace;
*/
class Menu
{
/**
* Database name
*/
private string $db;
/**
* Table name
*/
private string $table;
private Relation $relation;
/**
@ -49,11 +39,9 @@ class Menu
public function __construct(
private DatabaseInterface $dbi,
private readonly Template $template,
string $db,
string $table,
private string $db,
private string $table,
) {
$this->db = $db;
$this->table = $table;
$this->relation = new Relation($dbi);
}

View File

@ -41,11 +41,6 @@ class RecentFavoriteTable
*/
private array $tables;
/**
* Defines type of action, Favorite or Recent table.
*/
private string $tableType;
/**
* RecentFavoriteTable instances.
*
@ -58,13 +53,12 @@ class RecentFavoriteTable
/**
* Creates a new instance of RecentFavoriteTable
*
* @param string $type the table type
* @phpstan-param 'favorite'|'recent' $type
* @param string $tableType Defines type of action, Favorite or Recent table.
* @phpstan-param 'favorite'|'recent' $tableType
*/
private function __construct(public Template $template, string $type)
private function __construct(public Template $template, private string $tableType)
{
$this->relation = new Relation($GLOBALS['dbi']);
$this->tableType = $type;
$serverId = $GLOBALS['server'];
// Code search hint: recentTables
// Code search hint: favoriteTables
@ -141,16 +135,10 @@ class RecentFavoriteTable
$success = $GLOBALS['dbi']->tryQuery($sqlQuery, Connection::TYPE_CONTROL);
if (! $success) {
$errorMsg = '';
switch ($this->tableType) {
case 'recent':
$errorMsg = __('Could not save recent table!');
break;
case 'favorite':
$errorMsg = __('Could not save favorite table!');
break;
}
$errorMsg = match ($this->tableType) {
'recent' => __('Could not save recent table!'),
'favorite' => __('Could not save favorite table!'),
};
$message = Message::error($errorMsg);
$message->addMessage(

View File

@ -90,23 +90,15 @@ class Table implements Stringable
/** @var mixed[] messages */
public array $messages = [];
/** @var string table name */
protected string $name = '';
/** @var string database name */
protected string $dbName = '';
private Relation $relation;
/**
* @param string $tableName table name
* @param string $dbName database name
* @param DatabaseInterface $dbi database interface for the table
* @param string $name table name
* @param string $dbName database name
* @param DatabaseInterface $dbi database interface for the table
*/
public function __construct(string $tableName, string $dbName, protected DatabaseInterface $dbi)
public function __construct(protected string $name, protected string $dbName, protected DatabaseInterface $dbi)
{
$this->name = $tableName;
$this->dbName = $dbName;
$this->relation = new Relation($this->dbi);
}

View File

@ -8206,12 +8206,12 @@ parameters:
path: libraries/classes/Controllers/Table/RelationController.php
-
message: "#^Parameter \\#1 \\$queryData of static method PhpMyAdmin\\\\Core\\:\\:previewSQL\\(\\) expects array\\|string, mixed given\\.$#"
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/RelationController.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
message: "#^Parameter \\#1 \\$queryData of static method PhpMyAdmin\\\\Core\\:\\:previewSQL\\(\\) expects array\\|string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/RelationController.php
@ -8470,6 +8470,11 @@ parameters:
count: 1
path: libraries/classes/Controllers/Table/ReplaceController.php
-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/ReplaceController.php
-
message: "#^Parameter \\#1 \\$oneWhereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:setSessionForEditNext\\(\\) expects string, mixed given\\.$#"
count: 1
@ -8510,11 +8515,6 @@ parameters:
count: 1
path: libraries/classes/Controllers/Table/ReplaceController.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/ReplaceController.php
-
message: "#^Parameter \\#1 \\$urlParams of method PhpMyAdmin\\\\InsertEdit\\:\\:getErrorUrl\\(\\) expects array, mixed given\\.$#"
count: 1
@ -9051,7 +9051,7 @@ parameters:
path: libraries/classes/Controllers/Table/Structure/PartitioningController.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/Structure/PartitioningController.php
@ -13010,6 +13010,11 @@ parameters:
count: 2
path: libraries/classes/Export/Export.php
-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 2
path: libraries/classes/Export/Export.php
-
message: "#^Parameter \\#1 \\$params of static method PhpMyAdmin\\\\Url\\:\\:getCommonRaw\\(\\) expects array\\<int\\|string, bool\\|int\\|string\\>, array\\<string, mixed\\> given\\.$#"
count: 2
@ -13025,11 +13030,6 @@ parameters:
count: 2
path: libraries/classes/Export/Export.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 2
path: libraries/classes/Export/Export.php
-
message: "#^Parameter \\#2 \\$dbAlias of method PhpMyAdmin\\\\Plugins\\\\ExportPlugin\\:\\:exportDBHeader\\(\\) expects string, mixed given\\.$#"
count: 2
@ -14945,6 +14945,11 @@ parameters:
count: 1
path: libraries/classes/Import/Import.php
-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Import/Import.php
-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, mixed given\\.$#"
count: 1
@ -14980,11 +14985,6 @@ parameters:
count: 2
path: libraries/classes/Import/Import.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Import/Import.php
-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
count: 6
@ -22640,6 +22640,11 @@ parameters:
count: 4
path: libraries/classes/Query/Utilities.php
-
message: "#^Cannot access offset 'NumFavoriteTables'\\|'NumRecentTables' on mixed\\.$#"
count: 1
path: libraries/classes/RecentFavoriteTable.php
-
message: "#^Cannot access offset 'Server' on mixed\\.$#"
count: 2
@ -22675,11 +22680,6 @@ parameters:
count: 4
path: libraries/classes/RecentFavoriteTable.php
-
message: "#^Cannot access offset non\\-falsy\\-string on mixed\\.$#"
count: 1
path: libraries/classes/RecentFavoriteTable.php
-
message: "#^Cannot call method fetchValue\\(\\) on mixed\\.$#"
count: 1
@ -25365,6 +25365,11 @@ parameters:
count: 1
path: libraries/classes/Table/ColumnsDefinition.php
-
message: "#^Parameter \\#1 \\$name of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Table/ColumnsDefinition.php
-
message: "#^Parameter \\#1 \\$str of function preg_quote expects string, mixed given\\.$#"
count: 1
@ -25380,11 +25385,6 @@ parameters:
count: 1
path: libraries/classes/Table/ColumnsDefinition.php
-
message: "#^Parameter \\#1 \\$tableName of class PhpMyAdmin\\\\Table constructor expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Table/ColumnsDefinition.php
-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1

View File

@ -358,7 +358,7 @@
<code><![CDATA[$_SESSION[$this->id]]]></code>
</PossiblyInvalidArrayOffset>
<PossiblyNullArgument>
<code><![CDATA[$this->baseCfg]]></code>
<code><![CDATA[$this->baseConfig]]></code>
</PossiblyNullArgument>
</file>
<file src="libraries/classes/Config/Form.php">