type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-08 14:44:55 +02:00
parent 3166bc92b9
commit 1e9648256f
3 changed files with 55 additions and 14 deletions
+5 -1
View File
@@ -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
{
+40 -3
View File
@@ -49,16 +49,28 @@ class HookManager
{
private const DEFAULT_ORDER = 9;
private $data;
/**
* @var ?array<string,array<string,mixed>>
*/
private $data = null;
private $isDisabled;
private bool $isDisabled = false;
/**
* @var array<string,class-string[]>
*/
private $hookListHash = [];
/**
* @var array<class-string,object>
*/
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<string,mixed> $options
* @param array<string,mixed> $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<string,array<string,mixed>> $hookData
* @return array<string,array<string,mixed>>
*/
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<string,array<string,mixed>> $hooks
* @return array<string,array<string,mixed>>
*/
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<string,mixed> $hookData
*/
private function hookExists(string $className, array $hookData): bool
{
@@ -292,6 +325,10 @@ class HookManager
return false;
}
/**
* @param array<string,mixed> $a
* @param array<string,mixed> $b
*/
private function cmpHooks($a, $b): int
{
if ($a['order'] == $b['order']) {
+10 -10
View File
@@ -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;
}