From 1e9648256f77290d3550546d53e9c05c86773593 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 8 Mar 2022 14:44:55 +0200 Subject: [PATCH] type fixes --- application/Espo/Core/DataManager.php | 6 +++- application/Espo/Core/HookManager.php | 43 +++++++++++++++++++++++++-- application/Espo/Core/Injectable.php | 20 ++++++------- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/application/Espo/Core/DataManager.php b/application/Espo/Core/DataManager.php index 4df0d8277a..bc441629f5 100644 --- a/application/Espo/Core/DataManager.php +++ b/application/Espo/Core/DataManager.php @@ -74,7 +74,7 @@ class DataManager private $rebuildActionProcessor; - private $cachePath = 'data/cache'; + private string $cachePath = 'data/cache'; public function __construct( EntityManager $entityManager, @@ -104,6 +104,8 @@ class DataManager /** * Rebuild the system with metadata, database and cache clearing. + * + * @param ?string[] $entityList */ public function rebuild(?array $entityList = null): void { @@ -137,6 +139,8 @@ class DataManager /** * Rebuild database. + * + * @param ?string[] $entityList */ public function rebuildDatabase(?array $entityList = null): void { diff --git a/application/Espo/Core/HookManager.php b/application/Espo/Core/HookManager.php index cdb3dfe37a..d417fdd790 100644 --- a/application/Espo/Core/HookManager.php +++ b/application/Espo/Core/HookManager.php @@ -49,16 +49,28 @@ class HookManager { private const DEFAULT_ORDER = 9; - private $data; + /** + * @var ?array> + */ + private $data = null; - private $isDisabled; + private bool $isDisabled = false; + /** + * @var array + */ private $hookListHash = []; + /** + * @var array + */ private $hooks; - private $cacheKey = 'hooks'; + private string $cacheKey = 'hooks'; + /** + * @var string[] + */ private $ignoredMethodList = [ '__construct', 'getDependencyList', @@ -97,6 +109,11 @@ class HookManager $this->pathProvider = $pathProvider; } + /** + * @param mixed $injection + * @param array $options + * @param array $hookData + */ public function process( string $scope, string $hookName, @@ -173,6 +190,9 @@ class HookManager } } + /** + * @param class-string $className + */ private function createHookByClassName(string $className): object { if (!class_exists($className)) { @@ -184,6 +204,11 @@ class HookManager return $obj; } + /** + * @param string $hookDir + * @param array> $hookData + * @return array> + */ private function readHookData(string $hookDir, array $hookData = []): array { if (!$this->fileManager->exists($hookDir)) { @@ -232,6 +257,9 @@ class HookManager /** * Sort hooks by the order parameter. + * + * @param array> $hooks + * @return array> */ private function sortHooks(array $hooks): array { @@ -246,6 +274,8 @@ class HookManager /** * Get sorted hook list. + * + * @return class-string[] */ private function getHookList(string $scope, string $hookName): array { @@ -278,6 +308,9 @@ class HookManager /** * Check if hook exists in the list. + * + * @param class-string $className + * @param array $hookData */ private function hookExists(string $className, array $hookData): bool { @@ -292,6 +325,10 @@ class HookManager return false; } + /** + * @param array $a + * @param array $b + */ private function cmpHooks($a, $b): int { if ($a['order'] == $b['order']) { diff --git a/application/Espo/Core/Injectable.php b/application/Espo/Core/Injectable.php index c5c228ab53..466dbb3675 100644 --- a/application/Espo/Core/Injectable.php +++ b/application/Espo/Core/Injectable.php @@ -32,25 +32,25 @@ namespace Espo\Core; /** @deprecated */ abstract class Injectable implements \Espo\Core\Interfaces\Injectable { - protected $dependencyList = []; + protected $dependencyList = []; /** @phpstan-ignore-line */ - protected $injections = []; + protected $injections = []; /** @phpstan-ignore-line */ - public function inject($name, $object) + public function inject($name, $object) /** @phpstan-ignore-line */ { $this->injections[$name] = $object; } - public function __construct() + public function __construct() /** @phpstan-ignore-line */ { $this->init(); } - protected function init() + protected function init() /** @phpstan-ignore-line */ { } - public function __call($methodName, $args) + public function __call($methodName, $args) /** @phpstan-ignore-line */ { if (strpos($methodName, 'get') === 0) { $injectionName = lcfirst(substr($methodName, 3)); @@ -61,25 +61,25 @@ abstract class Injectable implements \Espo\Core\Interfaces\Injectable throw new \BadMethodCallException('Method ' . $methodName . ' does not exist'); } - protected function getInjection($name) + protected function getInjection($name) /** @phpstan-ignore-line */ { return $this->injections[$name] ?? $this->$name ?? null; } - protected function addDependency($name) + protected function addDependency($name) /** @phpstan-ignore-line */ { if (in_array($name, $this->dependencyList)) return; $this->dependencyList[] = $name; } - protected function addDependencyList(array $list) + protected function addDependencyList(array $list) /** @phpstan-ignore-line */ { foreach ($list as $item) { $this->addDependency($item); } } - public function getDependencyList() + public function getDependencyList() /** @phpstan-ignore-line */ { return $this->dependencyList; }