diff --git a/application/Espo/Core/Utils/Route.php b/application/Espo/Core/Utils/Route.php index 538aef04f2..0df8758ac2 100644 --- a/application/Espo/Core/Utils/Route.php +++ b/application/Espo/Core/Utils/Route.php @@ -48,6 +48,7 @@ class Route * route:string, * method:string, * noAuth?:bool, + * params?:array, * } * > */ @@ -92,6 +93,8 @@ class Route $this->init(); } + assert($this->data !== null); + return array_map( function (array $item): RouteItem { return new RouteItem( @@ -117,6 +120,7 @@ class Route * route:string, * method:string, * noAuth?:bool, + * params?:array, * } * > */ @@ -141,6 +145,7 @@ class Route * route:string, * method:string, * noAuth?:bool, + * params?:array, * } * > */ @@ -175,6 +180,7 @@ class Route * route:string, * method:string, * noAuth?:bool, + * params?:array, * } * > $currentData * @return array< @@ -183,6 +189,7 @@ class Route * route:string, * method:string, * noAuth?:bool, + * params?:array, * } * > */ @@ -256,6 +263,7 @@ class Route private function adjustPath(string $path): string { // to fast route format + /** @var string */ $pathFormatteted = preg_replace('/\:([a-zA-Z0-9]+)/', '{${1}}', trim($path)); if (substr($pathFormatteted, 0, 1) !== '/') { diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index 823855c169..4e58a9329d 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -136,7 +136,8 @@ class ScheduledJob $command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default']; foreach ($data as $name => $value) { - $command = str_replace('{'.$name.'}', $value, $command); + /** @var string */ + $command = str_replace('{' . $name . '}', $value ?? '', $command); } return [ diff --git a/application/Espo/Core/Utils/SystemRequirements.php b/application/Espo/Core/Utils/SystemRequirements.php index 6a36c9b288..1ab13f2352 100644 --- a/application/Espo/Core/Utils/SystemRequirements.php +++ b/application/Espo/Core/Utils/SystemRequirements.php @@ -310,7 +310,9 @@ class SystemRequirements case 'requiredMysqlVersion': case 'requiredMariadbVersion': /** @var string $data */ + /** @var PDO $pdo */ $actualVersion = $databaseHelper->getPdoDatabaseVersion($pdo); + $requiredVersion = $data; $acceptable = true; @@ -331,6 +333,9 @@ class SystemRequirements /** @var string[] $data */ foreach ($data as $name => $value) { $requiredValue = $value; + + /** @var PDO $pdo */ + $actualValue = $databaseHelper->getPdoDatabaseParam($name, $pdo); $acceptable = false; diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 6eddaf1bac..bda2c0f206 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -71,6 +71,7 @@ class Util */ public static function toFormat($name, $delimiter = '/') { + /** @var string */ return preg_replace("/[\/\\\]/", $delimiter, $name); } @@ -99,6 +100,7 @@ class Util $input = ucfirst($input); } + /** @var string */ return preg_replace_callback( '/' . $symbol . '([a-zA-Z])/', /** @@ -129,6 +131,7 @@ class Util $input[0] = strtolower($input[0]); + /** @var string */ return preg_replace_callback( '/([A-Z])/', function ($matches) use ($symbol) { @@ -491,7 +494,9 @@ class Util */ public static function getClassName(string $filePath): string { + /** @var string */ $className = preg_replace('/\.php$/i', '', $filePath); + /** @var string */ $className = preg_replace('/^(application|custom)(\/|\\\)/i', '', $className); $className = static::toFormat($className, '\\'); @@ -636,6 +641,7 @@ class Util public static function sanitizeFileName(string $fileName): string { + /** @var string */ return preg_replace("/([^\w\s\d\-_~,;:\[\]\(\).])/u", '_', $fileName); } @@ -839,6 +845,7 @@ class Util $sanitized = htmlspecialchars($text, \ENT_QUOTES | \ENT_HTML5, 'UTF-8'); foreach ($permittedHtmlTags as $htmlTag) { + /** @var string */ $sanitized = preg_replace('/<(\/)?(' . $htmlTag . ')>/i', '<$1$2>', $sanitized); } @@ -858,7 +865,9 @@ class Util ]; $url = trim($url); + /** @var string */ $url = preg_replace('/\/\?$/', '', $url); + /** @var string */ $url = preg_replace('/\/$/', '', $url); return $url . '/?' . http_build_query($params); @@ -888,8 +897,11 @@ class Util $newUrl = str_replace($urlQuery, http_build_query($params), $url); if (empty($params)) { + /** @var string */ $newUrl = preg_replace('/\/\?$/', '', $newUrl); + /** @var string */ $newUrl = preg_replace('/\/$/', '', $newUrl); + $newUrl .= $suffix; } diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.php index a27631d49e..f9c5fe5432 100644 --- a/application/Espo/Core/Webhook/Manager.php +++ b/application/Espo/Core/Webhook/Manager.php @@ -43,6 +43,8 @@ use Espo\Entities\{ Webhook, }; +use RuntimeException; + /** * Processes events. Holds an information about existing events. */ @@ -106,6 +108,10 @@ class Manager private function storeDataToCache(): void { + if ($this->data === null) { + throw new RuntimeException("No data to store."); + } + $this->dataCache->store($this->cacheKey, $this->data); } diff --git a/application/Espo/Core/Webhook/Queue.php b/application/Espo/Core/Webhook/Queue.php index b877a7f13b..c930a14c50 100644 --- a/application/Espo/Core/Webhook/Queue.php +++ b/application/Espo/Core/Webhook/Queue.php @@ -198,12 +198,14 @@ class Queue ->limit(0, $batchSize) ->find(); - $webhook = $this->entityManager->getEntity(Webhook::ENTITY_TYPE, $webhookId); + $webhook = $this->entityManager->getEntityById(Webhook::ENTITY_TYPE, $webhookId); if (!$webhook || !$webhook->get('isActive')) { foreach ($itemList as $item) { $this->deleteQueueItem($item); } + + return; } $forbiddenAttributeList = [];