diff --git a/application/Espo/Core/Utils/NumberUtil.php b/application/Espo/Core/Utils/NumberUtil.php index 1be8dfabe4..0ec9022290 100644 --- a/application/Espo/Core/Utils/NumberUtil.php +++ b/application/Espo/Core/Utils/NumberUtil.php @@ -31,42 +31,47 @@ namespace Espo\Core\Utils; class NumberUtil { - protected $decimalMark; + private $decimalMark; - protected $thousandSeparator; + private $thousandSeparator; - public function __construct($decimalMark = '.', $thousandSeparator = ',') + public function __construct(?string $decimalMark = '.', ?string $thousandSeparator = ',') { $this->decimalMark = $decimalMark; $this->thousandSeparator = $thousandSeparator; } - public function format($value, $decimals = null, $decimalMark = null, $thousandSeparator = null) - { + public function format( + $value, + ?int $decimals = null, + ?string $decimalMark = null, + ?string $thousandSeparator = null + ): string { + if (is_null($decimalMark)) { $decimalMark = $this->decimalMark; } + if (is_null($thousandSeparator)) { $thousandSeparator = $this->thousandSeparator; } if (!is_null($decimals)) { - return number_format($value, $decimals, $decimalMark, $thousandSeparator); - } else { - $s = strval($value); - $arr = explode('.', $value); - - $r = '0'; - if (!empty($arr[0])) { - $r = number_format(intval($arr[0]), 0, '.', $thousandSeparator); - } - - if (!empty($arr[1])) { - $r = $r . $decimalMark . $arr[1]; - } - - return $r; + return number_format($value, $decimals, $decimalMark, $thousandSeparator); } + + $arr = explode('.', strval($value)); + + $r = '0'; + + if (!empty($arr[0])) { + $r = number_format(intval($arr[0]), 0, '.', $thousandSeparator); + } + + if (!empty($arr[1])) { + $r = $r . $decimalMark . $arr[1]; + } + + return $r; } } - diff --git a/application/Espo/Core/Utils/ObjectUtil.php b/application/Espo/Core/Utils/ObjectUtil.php index 994b168a68..8e273450b8 100644 --- a/application/Espo/Core/Utils/ObjectUtil.php +++ b/application/Espo/Core/Utils/ObjectUtil.php @@ -33,7 +33,7 @@ use StdClass; class ObjectUtil { - public static function clone(StdClass $source) : StdClass + public static function clone(StdClass $source): StdClass { $cloned = (object) []; diff --git a/application/Espo/Core/Utils/PasswordHash.php b/application/Espo/Core/Utils/PasswordHash.php index 0dc7235929..114f3c320e 100644 --- a/application/Espo/Core/Utils/PasswordHash.php +++ b/application/Espo/Core/Utils/PasswordHash.php @@ -36,9 +36,7 @@ class PasswordHash private $config; /** - * Salt format of SHA-512 - * - * @var string + * SHA-512 salt format. */ private $saltFormat = '$6${0}$'; @@ -47,15 +45,10 @@ class PasswordHash $this->config = $config; } - protected function getConfig() - { - return $this->config; - } - /** * Hash a password. */ - public function hash(string $password, bool $useMd5 = true) : string + public function hash(string $password, bool $useMd5 = true): string { $salt = $this->getSalt(); @@ -71,12 +64,11 @@ class PasswordHash /** * Get a salt from config and normalize it. - * - * @return string */ - protected function getSalt() + protected function getSalt(): string { - $salt = $this->getConfig()->get('passwordSalt'); + $salt = $this->config->get('passwordSalt'); + if (!isset($salt)) { throw new Error('Option "passwordSalt" does not exist in config.php'); } @@ -88,11 +80,8 @@ class PasswordHash /** * Convert salt in format in accordance to $saltFormat. - * - * @param string $salt - * @return string */ - protected function normalizeSalt($salt) + protected function normalizeSalt(string $salt): string { return str_replace("{0}", $salt, $this->saltFormat); } @@ -100,7 +89,7 @@ class PasswordHash /** * Generate a new salt. */ - public function generateSalt() : string + public function generateSalt(): string { return substr(md5(uniqid()), 0, 16); } diff --git a/application/Espo/Core/Utils/Preload.php b/application/Espo/Core/Utils/Preload.php index 5cb4673170..76b6df2a9a 100644 --- a/application/Espo/Core/Utils/Preload.php +++ b/application/Espo/Core/Utils/Preload.php @@ -63,7 +63,7 @@ class Preload } } - public function getCount() : int + public function getCount(): int { return $this->counter; } @@ -90,7 +90,7 @@ class Preload $this->counter++; } - protected function isFileToBeIgnored(string $file) : bool + protected function isFileToBeIgnored(string $file): bool { $file = str_replace('\\', '/', $file); diff --git a/application/Espo/Core/Utils/Route.php b/application/Espo/Core/Utils/Route.php index aec2d19347..c962e67359 100644 --- a/application/Espo/Core/Utils/Route.php +++ b/application/Espo/Core/Utils/Route.php @@ -65,7 +65,7 @@ class Route /** * Get all routes. */ - public function getFullList() : array + public function getFullList(): array { if (!isset($this->data)) { $this->init(); @@ -91,7 +91,7 @@ class Route } } - protected function unify() : array + protected function unify(): array { $data = $this->addDataFromFile([], $this->paths['customPath']); @@ -114,7 +114,7 @@ class Route return $data; } - protected function addDataFromFile(array $currentData, string $routeFile) : array + protected function addDataFromFile(array $currentData, string $routeFile): array { if (!file_exists($routeFile)) { return $currentData; @@ -133,7 +133,7 @@ class Route return $this->appendRoutesToData($currentData, $data); } - protected function appendRoutesToData(array $data, array $newData) : array + protected function appendRoutesToData(array $data, array $newData): array { foreach ($newData as $route) { $route['route'] = $this->adjustPath($route['route']); @@ -157,7 +157,7 @@ class Route /** * Check and adjust the route path. */ - protected function adjustPath(string $routePath) : string + protected function adjustPath(string $routePath): string { $routePath = trim($routePath); @@ -171,7 +171,7 @@ class Route return $routePath; } - public static function detectBasePath() : string + public static function detectBasePath(): string { $scriptName = parse_url($_SERVER['SCRIPT_NAME'] , PHP_URL_PATH); $scriptDir = dirname($scriptName); @@ -189,7 +189,7 @@ class Route return ''; } - public static function detectEntryPointRoute() : string + public static function detectEntryPointRoute(): string { $basePath = self::detectBasePath(); @@ -206,7 +206,7 @@ class Route return '/'; } - static protected function isRouteInList(array $newRoute, array $routeList) : bool + static protected function isRouteInList(array $newRoute, array $routeList): bool { foreach ($routeList as $route) { if (Util::isEquals($route, $newRoute)) { diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index b598aeb3df..b9374c1558 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -74,7 +74,7 @@ class ScheduledJob $this->systemUtil = new System(); } - public function getAvailableList() : array + public function getAvailableList(): array { $map = $this->classFinder->getMap('Jobs'); @@ -83,7 +83,7 @@ class ScheduledJob return $list; } - public function getSetupMessage() : array + public function getSetupMessage(): array { $language = $this->language; @@ -115,7 +115,7 @@ class ScheduledJob /** * Check if crontab is configured properly. */ - public function isCronConfigured() : bool + public function isCronConfigured(): bool { $r1From = new DateTime('-' . $this->checkingCronPeriod); $r1To = new DateTime('+' . $this->checkingCronPeriod); diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 58180ffba6..d72d69553b 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -46,12 +46,12 @@ class Util return static::$separator; } - public static function camelCaseToUnderscore(string $string) : string + public static function camelCaseToUnderscore(string $string): string { return static::toUnderScore($string); } - public static function hyphenToCamelCase(string $string) : string + public static function hyphenToCamelCase(string $string): string { return self::toCamelCase($string, '-'); } @@ -293,7 +293,7 @@ class Util $object = (array) $object; } - return is_array($object) ? array_map("static::objectToArray", $object) : $object; + return is_array($object) ? array_map("static::objectToArray", $object): $object; } /** @@ -555,17 +555,17 @@ class Util return true; } - public static function generateId() : string + public static function generateId(): string { return uniqid() . substr(md5(rand()), 0, 4); } - public static function generateMoreEntropyId() : string + public static function generateMoreEntropyId(): string { return substr(md5(uniqid(rand(), true)), 0, 16) . substr(md5(rand()), 0, 4); } - public static function generateCryptId() : string + public static function generateCryptId(): string { if (!function_exists('random_bytes')) { return self::generateMoreEntropyId(); @@ -573,17 +573,17 @@ class Util return bin2hex(random_bytes(16)); } - public static function generateApiKey() : string + public static function generateApiKey(): string { return self::generateCryptId(); } - public static function generateSecretKey() : string + public static function generateSecretKey(): string { return self::generateCryptId(); } - public static function generateKey() : string + public static function generateKey(): string { return md5(uniqid(rand(), true)); } @@ -680,7 +680,7 @@ class Util * @param mixed $v1 * @param mixed $v2 */ - public static function areValuesEqual($v1, $v2, bool $isUnordered = false) : bool + public static function areValuesEqual($v1, $v2, bool $isUnordered = false): bool { if (is_array($v1) && is_array($v2)) { if ($isUnordered) { diff --git a/application/Espo/Core/Webhook/Sender.php b/application/Espo/Core/Webhook/Sender.php index 098ae7d25b..a1ea484a25 100644 --- a/application/Espo/Core/Webhook/Sender.php +++ b/application/Espo/Core/Webhook/Sender.php @@ -110,7 +110,7 @@ class Sender return $code; } - protected function buildSignature(Webhook $webhook, string $payload, string $secretKey) + protected function buildSignature(Webhook $webhook, string $payload, string $secretKey): string { return base64_encode($webhook->id . ':' . hash_hmac('sha256', $payload, $secretKey, true)); }