From 6beaa730ea28006bd32dc0f09cf33ad5ce4ae529 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 18 Mar 2022 19:39:58 +0200 Subject: [PATCH] type fixes --- application/Espo/Core/Container.php | 6 +++++- .../Espo/Core/Container/Configuration.php | 4 ++-- .../Espo/Core/Container/ContainerBuilder.php | 19 +++++++++++-------- application/Espo/Core/Controllers/Base.php | 8 ++++++++ application/Espo/Core/Controllers/Record.php | 12 ++++++++---- .../Core/Duplicate/WhereBuilderFactory.php | 3 ++- application/Espo/Core/Portal/Application.php | 8 +++++++- 7 files changed, 43 insertions(+), 17 deletions(-) diff --git a/application/Espo/Core/Container.php b/application/Espo/Core/Container.php index ce77b7c2be..de2a11fbd0 100644 --- a/application/Espo/Core/Container.php +++ b/application/Espo/Core/Container.php @@ -91,7 +91,10 @@ class Container implements ContainerInterface $this->bindingContainer = $bindingContainer; - $this->injectableFactory = $this->get('injectableFactory'); + /** @var InjectableFactory */ + $injectableFactory = $this->get('injectableFactory'); + + $this->injectableFactory = $injectableFactory; $this->configuration = $this->injectableFactory->create($configurationClassName); } @@ -208,6 +211,7 @@ class Container implements ContainerInterface throw new RuntimeException("Loader method for service '{$name}' does not have a named return type."); } + /** @var class-string */ $className = $returnType->getName(); $this->classCache[$name] = new ReflectionClass($className); diff --git a/application/Espo/Core/Container/Configuration.php b/application/Espo/Core/Container/Configuration.php index 65b1ed947d..bdbfc38c83 100644 --- a/application/Espo/Core/Container/Configuration.php +++ b/application/Espo/Core/Container/Configuration.php @@ -32,12 +32,12 @@ namespace Espo\Core\Container; interface Configuration { /** - * @return ?class-string + * @return ?class-string */ public function getLoaderClassName(string $name): ?string; /** - * @return ?class-string + * @return ?class-string */ public function getServiceClassName(string $name): ?string; diff --git a/application/Espo/Core/Container/ContainerBuilder.php b/application/Espo/Core/Container/ContainerBuilder.php index 8c0942eeb2..ddafe571c6 100644 --- a/application/Espo/Core/Container/ContainerBuilder.php +++ b/application/Espo/Core/Container/ContainerBuilder.php @@ -31,6 +31,7 @@ namespace Espo\Core\Container; use Espo\Core\Container; use Espo\Core\Container\ContainerConfiguration; +use Espo\Core\Container\Container as ContainerInterface; use Espo\Core\Binding\BindingContainer; use Espo\Core\Binding\BindingLoader; @@ -52,12 +53,12 @@ use Espo\Core\Loaders\Metadata as MetadataLoader; class ContainerBuilder { /** - * @var class-string + * @var class-string<\Espo\Core\Container\Container> */ private string $containerClassName = Container::class; /** - * @var class-string + * @var class-string<\Espo\Core\Container\Configuration> */ private string $containerConfigurationClassName = ContainerConfiguration::class; @@ -77,7 +78,7 @@ class ContainerBuilder private string $dataCacheClassName = DataCache::class; /** - * @var class-string + * @var class-string */ private string $moduleClassName = Module::class; @@ -89,7 +90,7 @@ class ContainerBuilder private $services = []; /** - * @var array + * @var array> */ protected $loaderClassNames = [ 'log' => LogLoader::class, @@ -117,7 +118,7 @@ class ContainerBuilder } /** - * @param array $classNames + * @param array> $classNames */ public function withLoaderClassNames(array $classNames): self { @@ -129,7 +130,7 @@ class ContainerBuilder } /** - * @param class-string $containerClassName + * @param class-string<\Espo\Core\Container\Container> $containerClassName */ public function withContainerClassName(string $containerClassName): self { @@ -139,7 +140,7 @@ class ContainerBuilder } /** - * @param class-string $containerConfigurationClassName + * @param class-string<\Espo\Core\Container\Configuration> $containerConfigurationClassName */ public function withContainerConfigurationClassName(string $containerConfigurationClassName): self { @@ -178,8 +179,9 @@ class ContainerBuilder return $this; } - public function build(): Container + public function build(): ContainerInterface { + /** @var Config */ $config = $this->services['config'] ?? ( new $this->configClassName( new ConfigFileManager() @@ -198,6 +200,7 @@ class ContainerBuilder $useCache = $config->get('useCache') ?? false; + /** @var Module */ $module = $this->services['module'] ?? ( new $this->moduleClassName($fileManager, $dataCache, $useCache) ); diff --git a/application/Espo/Core/Controllers/Base.php b/application/Espo/Core/Controllers/Base.php index 5c95341c7c..b57347277d 100644 --- a/application/Espo/Core/Controllers/Base.php +++ b/application/Espo/Core/Controllers/Base.php @@ -150,6 +150,7 @@ abstract class Base */ protected function getName(): string { + /** @var string */ return $this->name; } @@ -197,6 +198,7 @@ abstract class Base */ protected function getUser() { + /** @var User */ return $this->container->get('user'); } @@ -207,6 +209,7 @@ abstract class Base */ protected function getAcl() { + /** @var Acl */ return $this->container->get('acl'); } @@ -217,6 +220,7 @@ abstract class Base */ protected function getAclManager() { + /** @var AclManager */ return $this->container->get('aclManager'); } @@ -227,6 +231,7 @@ abstract class Base */ protected function getConfig() { + /** @var Config */ return $this->container->get('config'); } @@ -236,6 +241,7 @@ abstract class Base */ protected function getPreferences() { + /** @var Preferences */ return $this->container->get('preferences'); } @@ -246,6 +252,7 @@ abstract class Base */ protected function getMetadata() { + /** @var Metadata */ return $this->container->get('metadata'); } @@ -256,6 +263,7 @@ abstract class Base */ protected function getServiceFactory() { + /** @var ServiceFactory */ return $this->container->get('serviceFactory'); } } diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index d921c26a67..409fb6b100 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -32,6 +32,7 @@ namespace Espo\Core\Controllers; use Espo\Core\Exceptions\BadRequest; use Espo\Core\Api\Request; use Espo\Core\Select\SearchParams; +use Espo\Core\Utils\Json; use stdClass; @@ -166,12 +167,15 @@ class Record extends RecordBase $where = $data->where ?? null; if ($where !== null) { - $where = json_decode(json_encode($where), true); + $where = json_decode(Json::encode($where), true); } - $params = json_decode(json_encode( - $data->searchParams ?? $data->selectData ?? (object) [] - ), true); + $params = json_decode( + Json::encode( + $data->searchParams ?? $data->selectData ?? (object) [] + ), + true + ); if ($where !== null && !is_array($where)) { throw new BadRequest("Bad 'where."); diff --git a/application/Espo/Core/Duplicate/WhereBuilderFactory.php b/application/Espo/Core/Duplicate/WhereBuilderFactory.php index 2e1c19a045..40ce00b5b8 100644 --- a/application/Espo/Core/Duplicate/WhereBuilderFactory.php +++ b/application/Espo/Core/Duplicate/WhereBuilderFactory.php @@ -69,10 +69,11 @@ class WhereBuilderFactory } /** - * @return ?class-string + * @return ?class-string> */ private function getClassName(string $entityType): ?string { + /** @var ?class-string> */ return $this->metadata ->get(['recordDefs', $entityType, 'duplicateWhereBuilderClassName']); } diff --git a/application/Espo/Core/Portal/Application.php b/application/Espo/Core/Portal/Application.php index 1919aa87ea..4345c180d9 100644 --- a/application/Espo/Core/Portal/Application.php +++ b/application/Espo/Core/Portal/Application.php @@ -61,11 +61,17 @@ class Application extends BaseApplication protected function initContainer(): void { - $this->container = (new ContainerBuilder()) + $container = (new ContainerBuilder()) ->withConfigClassName(Config::class) ->withContainerClassName(PortalContainer::class) ->withContainerConfigurationClassName(PortalContainerConfiguration::class) ->build(); + + if (!$container instanceof PortalContainer) { + throw new Error("Wrong container created."); + } + + $this->container = $container; } protected function initPortal(?string $portalId): void