type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-10 13:03:27 +02:00
parent 8cc4ffdd80
commit 19e769d107
5 changed files with 105 additions and 23 deletions
+41 -11
View File
@@ -40,14 +40,17 @@ use E_USER_DEPRECATED;
*/
class Config
{
private $configPath = 'data/config.php';
private string $configPath = 'data/config.php';
private $internalConfigPath = 'data/config-internal.php';
private string $internalConfigPath = 'data/config-internal.php';
private $systemConfigPath = 'application/Espo/Resources/defaults/systemConfig.php';
private string $systemConfigPath = 'application/Espo/Resources/defaults/systemConfig.php';
private $cacheTimestamp = 'cacheTimestamp';
private string $cacheTimestamp = 'cacheTimestamp';
/**
* @var string[]
*/
protected $associativeArrayAttributeList = [
'currencyRates',
'database',
@@ -55,14 +58,26 @@ class Config
'defaultPermissions',
];
private $data;
/**
* @var ?array<string,mixed>
*/
private $data = null;
/**
* @var array<string,mixed>
*/
private $changedData = [];
/**
* @var string[]
*/
private $removeData = [];
private $fileManager;
private ConfigFileManager $fileManager;
/**
* @var string[]
*/
private $internalParamList = [];
public function __construct(ConfigFileManager $fileManager)
@@ -159,15 +174,18 @@ class Config
* @todo Get rid of this method. Use ConfigData as a dependency.
* `$configData->update();`
*/
public function update()
public function update(): void
{
$this->load();
}
/**
* @deprecated Since v7.0.
*
* @param string|array<string,mixed>|\stdClass $name
* @param mixed $value
*/
public function set($name, $value = null, bool $dontMarkDirty = false)
public function set($name, $value = null, bool $dontMarkDirty = false): void
{
if (is_object($name)) {
$name = get_object_vars($name);
@@ -208,6 +226,8 @@ class Config
/**
* @deprecated Since v7.0.
*
* @return bool
*/
public function save()
{
@@ -269,6 +289,9 @@ class Config
return isset($this->data) && !empty($this->data);
}
/**
* @return array<string,mixed>
*/
private function getData(): array
{
if (!$this->isLoaded()) {
@@ -322,20 +345,25 @@ class Config
return in_array($name, $this->internalParamList);
}
/** @deprecated */
/**
* @deprecated
* @param array<string,mixed> $data
* @return void
*/
public function setData($data)
{
if (is_object($data)) {
$data = get_object_vars($data);
}
return $this->set($data);
$this->set($data);
}
/**
* Update cache timestamp.
*
* @deprecated
* @return ?array<string,int>
*/
public function updateCacheTimestamp(bool $returnOnlyValue = false)
{
@@ -347,7 +375,9 @@ class Config
return $timestamp;
}
return $this->set($timestamp);
$this->set($timestamp);
return null;
}
/**
@@ -38,7 +38,7 @@ use RuntimeException;
class ConfigFileManager
{
protected $fileManager;
protected FileManager $fileManager;
public function __construct()
{
@@ -57,6 +57,10 @@ class ConfigFileManager
return $this->fileManager->isFile($filePath);
}
/**
* @param array<string,mixed> $data
* @throws RuntimeException
*/
protected function putPhpContentsInternal(string $path, array $data, bool $useRenaming = false): void
{
$result = $this->fileManager->putPhpContents($path, $data, true, $useRenaming);
@@ -66,18 +70,24 @@ class ConfigFileManager
}
}
/**
* @param array<string,mixed> $data
*/
public function putPhpContents(string $path, array $data): void
{
$this->putPhpContentsInternal($path, $data, true);
}
/**
* @param array<string,mixed> $data
*/
public function putPhpContentsNoRenaming(string $path, array $data): void
{
$this->putPhpContentsInternal($path, $data, false);
}
/**
* @return array|false
* @return array<string,mixed>|false
*/
public function getPhpContents(string $path)
{
@@ -39,10 +39,19 @@ use Exception;
*/
class ConfigWriter
{
/**
* @var array<string,mixed>
*/
private $changedData = [];
/**
* @var string[]
*/
private $removeParamList = [];
/**
* @var string[]
*/
protected $associativeArrayAttributeList = [
'currencyRates',
'database',
@@ -50,15 +59,15 @@ class ConfigWriter
'defaultPermissions',
];
private $cacheTimestampParam = 'cacheTimestamp';
private string $cacheTimestampParam = 'cacheTimestamp';
private $config;
private Config $config;
private $fileManager;
private ConfigWriterFileManager $fileManager;
private $helper;
private ConfigWriterHelper $helper;
private $internalConfigHelper;
private InternalConfigHelper $internalConfigHelper;
public function __construct(
Config $config,
@@ -74,6 +83,8 @@ class ConfigWriter
/**
* Set a parameter.
*
* @param mixed $value
*/
public function set(string $name, $value): void
{
@@ -86,6 +97,8 @@ class ConfigWriter
/**
* Set multiple parameters.
*
* @param array<string,mixed> $params
*/
public function setMultiple(array $params): void
{
@@ -176,6 +189,10 @@ class ConfigWriter
$this->config->update();
}
/**
* @param array<string,mixed> $data
* @throws Error
*/
private function saveData(string $path, array &$data, string $timeParam): void
{
$data[$timeParam] = $microtime = $this->helper->generateMicrotime();
@@ -38,8 +38,16 @@ use RuntimeException;
class ConfigWriterFileManager
{
private $fileManager;
private FileManager $fileManager;
/**
* @param ?array{
* dir: string|int|null,
* file: string|int|null,
* user: string|int|null,
* group: string|int|null,
* } $defaultPermissions
*/
public function __construct(?Config $config = null, ?array $defaultPermissions = null)
{
$defaultPermissionsToSet = null;
@@ -54,7 +62,7 @@ class ConfigWriterFileManager
$this->fileManager = new FileManager($defaultPermissionsToSet);
}
public function setConfig(Config $config)
public function setConfig(Config $config): void
{
$this->fileManager = new FileManager(
$config->get('defaultPermissions')
@@ -66,7 +74,11 @@ class ConfigWriterFileManager
return $this->fileManager->isFile($filePath);
}
protected function putPhpContentsInternal(string $path, array $data, bool $useRenaming = false)
/**
* @param array<string,mixed> $data
* @throws RuntimeException
*/
protected function putPhpContentsInternal(string $path, array $data, bool $useRenaming = false): void
{
$result = $this->fileManager->putPhpContents($path, $data, true, $useRenaming);
@@ -75,16 +87,25 @@ class ConfigWriterFileManager
}
}
public function putPhpContents(string $path, array $data)
/**
* @param array<string,mixed> $data $data
*/
public function putPhpContents(string $path, array $data): void
{
$this->putPhpContentsInternal($path, $data, true);
}
public function putPhpContentsNoRenaming(string $path, array $data)
/**
* @param array<string,mixed> $data
*/
public function putPhpContentsNoRenaming(string $path, array $data): void
{
$this->putPhpContentsInternal($path, $data, false);
}
/**
* @return mixed
*/
public function getPhpContents(string $path)
{
return $this->fileManager->getPhpContents($path);
@@ -75,6 +75,10 @@ class DatabasePopulator
}
}
/**
* @param array<string,float> $currencyRates
* @return array<string,float>
*/
private function exchangeRates(string $baseCurrency, string $defaultCurrency, array $currencyRates): array
{
$precision = 5;