From d34c8d19189040e86a32d2bbff337431cb8f500b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 11 Mar 2022 14:09:17 +0200 Subject: [PATCH] type fixes --- application/Espo/Services/EmailAddress.php | 22 ++++++++++--- application/Espo/Services/EmailFolder.php | 10 ++++-- application/Espo/Services/EmailTemplate.php | 15 +++++++-- application/Espo/Services/ExternalAccount.php | 7 +++- application/Espo/Services/GlobalSearch.php | 4 +-- application/Espo/Services/InboundEmail.php | 9 ++++- application/Espo/Services/Integration.php | 3 ++ application/Espo/Services/Language.php | 19 +++++++---- application/Espo/Services/LastViewed.php | 6 ++++ application/Espo/Services/Layout.php | 33 +++++++++++++++---- application/Espo/Services/LeadCapture.php | 11 +++++-- 11 files changed, 111 insertions(+), 28 deletions(-) diff --git a/application/Espo/Services/EmailAddress.php b/application/Espo/Services/EmailAddress.php index 7d1c75ea22..40b4deb336 100644 --- a/application/Espo/Services/EmailAddress.php +++ b/application/Espo/Services/EmailAddress.php @@ -38,13 +38,16 @@ class EmailAddress extends Record { const ERASED_PREFIX = 'ERASED:'; + /** + * @param array> $result + */ protected function findInAddressBookByEntityType( string $filter, int $limit, string $entityType, array &$result, bool $onlyActual = false - ) { + ): void { $whereClause = [ 'OR' => [ @@ -161,7 +164,7 @@ class EmailAddress extends Record } } - protected function handleQueryBuilderUser(string $filter, QueryBuilder $queryBuilder) + protected function handleQueryBuilderUser(string $filter, QueryBuilder $queryBuilder): void { if ($this->acl->get('portalPermission') === 'no') { $queryBuilder->where([ @@ -174,10 +177,13 @@ class EmailAddress extends Record ]); } - protected function findInInboundEmail(string $query, int $limit, array &$result) + /** + * @param array> $result + */ + protected function findInInboundEmail(string $query, int $limit, array &$result): void { if ($this->user->isPortal()) { - return []; + return; } $list = $this->entityManager @@ -199,6 +205,9 @@ class EmailAddress extends Record } } + /** + * @return array> + */ public function searchInAddressBook(string $query, int $limit, bool $onlyActual = false): array { $result = []; @@ -259,7 +268,10 @@ class EmailAddress extends Record return $finalResult; } - protected function getHavingEmailAddressEntityTypeList() + /** + * @return string[] + */ + protected function getHavingEmailAddressEntityTypeList(): array { $list = ['Account', 'Contact', 'Lead', 'User']; diff --git a/application/Espo/Services/EmailFolder.php b/application/Espo/Services/EmailFolder.php index 59d881918c..32a7f0469c 100644 --- a/application/Espo/Services/EmailFolder.php +++ b/application/Espo/Services/EmailFolder.php @@ -42,8 +42,14 @@ class EmailFolder extends Record implements Di\LanguageAware { use Di\LanguageSetter; + /** + * @var string[] + */ protected $systemFolderList = ['inbox', 'important', 'sent']; + /** + * @var string[] + */ protected $systemFolderEndList = ['drafts', 'trash']; protected function beforeCreateEntity(Entity $entity, $data) @@ -58,7 +64,7 @@ class EmailFolder extends Record implements Di\LanguageAware } } - public function moveUp(string $id) + public function moveUp(string $id): void { $entity = $this->entityManager->getEntity('EmailFolder', $id); if (!$entity) { @@ -95,7 +101,7 @@ class EmailFolder extends Record implements Di\LanguageAware $this->entityManager->saveEntity($previousEntity); } - public function moveDown(string $id) + public function moveDown(string $id): void { $entity = $this->entityManager->getEntity('EmailFolder', $id); diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index 3df8e1ca25..55e1c8767d 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -51,11 +51,15 @@ class EmailTemplate extends Record implements { use Di\FieldUtilSetter; + /** + * @param array $params + * @return array + */ public function parseTemplate( EmailTemplateEntity $emailTemplate, array $params = [], - $copyAttachments = false, - $skipAcl = false + bool $copyAttachments = false, + bool $skipAcl = false ): array { $paramsInternal = Params::create() @@ -77,6 +81,10 @@ class EmailTemplate extends Record implements return get_object_vars($result->getValueMap()); } + /** + * @param array $params + * @return array + */ public function parse(string $id, array $params = [], bool $copyAttachments = false): array { /** @var EmailTemplateEntity|null */ @@ -89,6 +97,9 @@ class EmailTemplate extends Record implements return $this->parseTemplate($emailTemplate, $params, $copyAttachments); } + /** + * @param array $params + */ public function getInsertFieldData(array $params): stdClass { $to = $params['to'] ?? null; diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php index 9270088ae2..9bea909f69 100644 --- a/application/Espo/Services/ExternalAccount.php +++ b/application/Espo/Services/ExternalAccount.php @@ -52,7 +52,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware { use Di\HookManagerSetter; - protected function getClient(string $integration, string $id) + protected function getClient(string $integration, string $id): ?object { /** @var IntegrationEntity|null $integrationEntity */ $integrationEntity = $this->entityManager->getEntity('Integration', $integration); @@ -102,6 +102,11 @@ class ExternalAccount extends Record implements Di\HookManagerAware return false; } + /** + * @return bool + * @throws NotFound + * @throws Error + */ public function authorizationCode(string $integration, string $userId, string $code) { $entity = $this->getExternalAccountEntity($integration, $userId); diff --git a/application/Espo/Services/GlobalSearch.php b/application/Espo/Services/GlobalSearch.php index ac39af1e5c..0204364ee2 100644 --- a/application/Espo/Services/GlobalSearch.php +++ b/application/Espo/Services/GlobalSearch.php @@ -55,9 +55,9 @@ class GlobalSearch implements use Di\AclSetter; use Di\ConfigSetter; - protected $fullTextSearchDataComposerFactory; + private $fullTextSearchDataComposerFactory; - protected $selectBuilderFactory; + private $selectBuilderFactory; public function __construct( FullTextSearchDataComposerFactory $fullTextSearchDataComposerFactory, diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index 367527c368..d9afa97c71 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -151,6 +151,9 @@ class InboundEmail extends RecordService implements $service->storeSentMessage($emailAccount->getId(), $message); } + /** + * @return ?array + */ public function getSmtpParamsFromAccount(InboundEmailEntity $emailAccount): ?array { $smtpParams = []; @@ -187,8 +190,12 @@ class InboundEmail extends RecordService implements return null; } - public function applySmtpHandler(InboundEmailEntity $emailAccount, array &$params) + /** + * @param array $params + */ + public function applySmtpHandler(InboundEmailEntity $emailAccount, array &$params): void { + /** @var ?class-string */ $handlerClassName = $emailAccount->get('smtpHandler'); if (!$handlerClassName) { diff --git a/application/Espo/Services/Integration.php b/application/Espo/Services/Integration.php index 3a14e14e5d..b9adbd56ca 100644 --- a/application/Espo/Services/Integration.php +++ b/application/Espo/Services/Integration.php @@ -75,6 +75,9 @@ class Integration $this->configWriter = $configWriter; } + /** + * @return void + */ protected function processAccessCheck() { if (!$this->user->isAdmin()) { diff --git a/application/Espo/Services/Language.php b/application/Espo/Services/Language.php index ed3822310b..672c840467 100644 --- a/application/Espo/Services/Language.php +++ b/application/Espo/Services/Language.php @@ -29,6 +29,8 @@ namespace Espo\Services; +use Espo\Core\Utils\Language as LanguageUtil; + use Espo\Core\{ Acl, Container, @@ -39,13 +41,13 @@ use Espo\Entities\User; class Language { - protected $metadata; + private $metadata; - protected $acl; + private $acl; - protected $user; + private $user; - protected $container; + private $container; public function __construct( Metadata $metadata, @@ -60,17 +62,20 @@ class Language } // TODO use proxy - protected function getDefaultLanguage() + protected function getDefaultLanguage(): LanguageUtil { return $this->container->get('defaultLanguage'); } - protected function getLanguage() + protected function getLanguage(): LanguageUtil { return $this->container->get('language'); } - public function getDataForFrontend(bool $default = false) + /** + * @return array + */ + public function getDataForFrontend(bool $default = false): array { if ($default) { $languageObj = $this->getDefaultLanguage(); diff --git a/application/Espo/Services/LastViewed.php b/application/Espo/Services/LastViewed.php index 0954654264..bf1022fdde 100644 --- a/application/Espo/Services/LastViewed.php +++ b/application/Espo/Services/LastViewed.php @@ -60,6 +60,12 @@ class LastViewed $this->listLoadProcessor = $listLoadProcessor; } + /** + * @param array{ + * offset: int, + * maxSize: int, + * } $params + */ public function getList(array $params): object { $repository = $this->entityManager->getRDBRepository('ActionHistoryRecord'); diff --git a/application/Espo/Services/Layout.php b/application/Espo/Services/Layout.php index fe86d02dbd..357941723d 100644 --- a/application/Espo/Services/Layout.php +++ b/application/Espo/Services/Layout.php @@ -29,6 +29,8 @@ namespace Espo\Services; +use Espo\Entities\LayoutRecord; + use Espo\Core\{ Exceptions\NotFound, Exceptions\Forbidden, @@ -46,6 +48,8 @@ use Espo\{ Tools\LayoutManager\LayoutManager, }; +use stdClass; + class Layout { /** @@ -102,7 +106,7 @@ class Layout } /** - * @return array|object|null + * @return array|stdClass|null */ public function getOriginal(string $scope, string $name, ?string $setId = null) { @@ -133,6 +137,11 @@ class Layout return $result; } + /** + * @return mixed + * @throws Forbidden + * @throws NotFound + */ public function getForFrontend(string $scope, string $name) { try { @@ -243,8 +252,13 @@ class Layout return $data; } - protected function getRecordFromSet(string $scope, string $name, string $setId, bool $skipCheck = false) - { + protected function getRecordFromSet( + string $scope, + string $name, + string $setId, + bool $skipCheck = false + ): ?LayoutRecord { + $em = $this->entityManager; $layoutSet = $em->getEntity('LayoutSet', $setId); @@ -276,6 +290,10 @@ class Layout return $layout; } + /** + * @param mixed $data + * @return mixed + */ public function update(string $scope, string $name, ?string $setId, $data) { if ($setId) { @@ -310,6 +328,9 @@ class Layout return $layoutManager->get($scope, $name); } + /** + * @return array|stdClass|null + */ public function resetToDefault(string $scope, string $name, ?string $setId = null) { $this->dataManager->updateCacheTimestamp(); @@ -336,7 +357,7 @@ class Layout return $this->getOriginal($scope, $name); } - protected function getOriginalBottomPanelsDetail(string $scope, ?string $setId = null) + protected function getOriginalBottomPanelsDetail(string $scope, ?string $setId = null): stdClass { $relationships = $this->getOriginal($scope, 'relationships') ?? []; @@ -366,12 +387,12 @@ class Layout return $result; } - protected function getForFrontendBottomPanelsDetail(string $scope) + protected function getForFrontendBottomPanelsDetail(string $scope): stdClass { return $this->getOriginalBottomPanelsDetail($scope); } - protected function resetToDefaultBottomPanelsDetail(string $scope) + protected function resetToDefaultBottomPanelsDetail(string $scope): void { $this->layoutManager->resetToDefault($scope, 'relationships'); } diff --git a/application/Espo/Services/LeadCapture.php b/application/Espo/Services/LeadCapture.php index 92402b9406..ca05750052 100644 --- a/application/Espo/Services/LeadCapture.php +++ b/application/Espo/Services/LeadCapture.php @@ -45,6 +45,9 @@ use stdClass; class LeadCapture extends Record { + /** + * @var string[] + */ protected $readOnlyAttributeList = ['apiKey']; public function prepareEntityForOutput(Entity $entity) @@ -164,12 +167,12 @@ class LeadCapture extends Record return $this->injectableFactory->create(Tool::class); } - public function leadCapture(string $apiKey, stdClass $data) + public function leadCapture(string $apiKey, stdClass $data): void { $this->createTool()->capture($apiKey, $data); } - public function jobOptInConfirmation(stdClass $data) + public function jobOptInConfirmation(stdClass $data): void { if (empty($data->id)) { throw new Error(); @@ -183,6 +186,10 @@ class LeadCapture extends Record return $this->createTool()->confirmOptIn($id); } + /** + * @return stdClass[] + * @throws Forbidden + */ public function getSmtpAccountDataList(): array { if (!$this->getUser()->isAdmin()) {