From 19e769d107d966ed9358a72ea95768e6307efebf Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 10 Mar 2022 13:03:27 +0200 Subject: [PATCH] type fixes --- application/Espo/Core/Utils/Config.php | 52 +++++++++++++++---- .../Core/Utils/Config/ConfigFileManager.php | 14 ++++- .../Espo/Core/Utils/Config/ConfigWriter.php | 27 ++++++++-- .../Utils/Config/ConfigWriterFileManager.php | 31 +++++++++-- .../Core/Utils/Currency/DatabasePopulator.php | 4 ++ 5 files changed, 105 insertions(+), 23 deletions(-) diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index fe8f75be55..ecf8654a8b 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -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 + */ + private $data = null; + /** + * @var array + */ 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|\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 + */ private function getData(): array { if (!$this->isLoaded()) { @@ -322,20 +345,25 @@ class Config return in_array($name, $this->internalParamList); } - /** @deprecated */ + /** + * @deprecated + * @param array $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 */ public function updateCacheTimestamp(bool $returnOnlyValue = false) { @@ -347,7 +375,9 @@ class Config return $timestamp; } - return $this->set($timestamp); + $this->set($timestamp); + + return null; } /** diff --git a/application/Espo/Core/Utils/Config/ConfigFileManager.php b/application/Espo/Core/Utils/Config/ConfigFileManager.php index 285cd6fa7c..2186270803 100644 --- a/application/Espo/Core/Utils/Config/ConfigFileManager.php +++ b/application/Espo/Core/Utils/Config/ConfigFileManager.php @@ -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 $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 $data + */ public function putPhpContents(string $path, array $data): void { $this->putPhpContentsInternal($path, $data, true); } + /** + * @param array $data + */ public function putPhpContentsNoRenaming(string $path, array $data): void { $this->putPhpContentsInternal($path, $data, false); } /** - * @return array|false + * @return array|false */ public function getPhpContents(string $path) { diff --git a/application/Espo/Core/Utils/Config/ConfigWriter.php b/application/Espo/Core/Utils/Config/ConfigWriter.php index ab25135688..989dbe001a 100644 --- a/application/Espo/Core/Utils/Config/ConfigWriter.php +++ b/application/Espo/Core/Utils/Config/ConfigWriter.php @@ -39,10 +39,19 @@ use Exception; */ class ConfigWriter { + /** + * @var array + */ 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 $params */ public function setMultiple(array $params): void { @@ -176,6 +189,10 @@ class ConfigWriter $this->config->update(); } + /** + * @param array $data + * @throws Error + */ private function saveData(string $path, array &$data, string $timeParam): void { $data[$timeParam] = $microtime = $this->helper->generateMicrotime(); diff --git a/application/Espo/Core/Utils/Config/ConfigWriterFileManager.php b/application/Espo/Core/Utils/Config/ConfigWriterFileManager.php index 4ce0164813..a390d563a5 100644 --- a/application/Espo/Core/Utils/Config/ConfigWriterFileManager.php +++ b/application/Espo/Core/Utils/Config/ConfigWriterFileManager.php @@ -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 $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 $data $data + */ + public function putPhpContents(string $path, array $data): void { $this->putPhpContentsInternal($path, $data, true); } - public function putPhpContentsNoRenaming(string $path, array $data) + /** + * @param array $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); diff --git a/application/Espo/Core/Utils/Currency/DatabasePopulator.php b/application/Espo/Core/Utils/Currency/DatabasePopulator.php index 249e1d46dc..f6ef977c00 100644 --- a/application/Espo/Core/Utils/Currency/DatabasePopulator.php +++ b/application/Espo/Core/Utils/Currency/DatabasePopulator.php @@ -75,6 +75,10 @@ class DatabasePopulator } } + /** + * @param array $currencyRates + * @return array + */ private function exchangeRates(string $baseCurrency, string $defaultCurrency, array $currencyRates): array { $precision = 5;