From beb51081d301eff773264e45ed4f348ffbfd4d2e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 5 Nov 2021 10:55:41 +0200 Subject: [PATCH] type fixes --- application/Espo/Repositories/Preferences.php | 2 +- .../Espo/Services/DashboardTemplate.php | 2 +- application/Espo/Services/Email.php | 18 ++++++++---------- application/Espo/Services/EmailAccount.php | 10 ++++------ application/Espo/Services/ExternalAccount.php | 2 +- application/Espo/Services/InboundEmail.php | 2 +- application/Espo/Services/Notification.php | 6 +++--- application/Espo/Services/Preferences.php | 8 ++++---- application/Espo/Services/Stream.php | 2 +- application/Espo/Services/User.php | 8 ++++---- application/Espo/Services/UserSecurity.php | 6 +++--- application/Espo/Services/Webhook.php | 2 +- .../EmailNotification/AssignmentProcessor.php | 2 +- 13 files changed, 33 insertions(+), 37 deletions(-) diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index c0d7d51128..33338842c6 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -258,7 +258,7 @@ class Preferences implements Repository, $this->entityManager->getQueryExecutor()->execute($insert); - /** @var User $user */ + /** @var User|null $user */ $user = $this->entityManager->getEntity('User', $entity->getId()); if ($user && !$user->isPortal()) { diff --git a/application/Espo/Services/DashboardTemplate.php b/application/Espo/Services/DashboardTemplate.php index 87624d8555..63aa22f846 100644 --- a/application/Espo/Services/DashboardTemplate.php +++ b/application/Espo/Services/DashboardTemplate.php @@ -96,7 +96,7 @@ class DashboardTemplate extends Record } foreach ($userIdList as $userId) { - /** @var User $user */ + /** @var User|null $user */ $user = $this->getEntityManager()->getEntity('User', $userId); if ($user) { diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 1eaddea8d3..1614c6d832 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -117,7 +117,7 @@ class Email extends Record implements $fromAddress = strtolower($fromAddress); } - /** @var Preferences $preferences */ + /** @var Preferences|null $preferences */ $preferences = $this->entityManager->getEntity('Preferences', $user->getId()); if (!$preferences) { @@ -190,7 +190,7 @@ class Email extends Record implements $primaryUserAddress = strtolower($user->get('emailAddress')); if ($primaryUserAddress === $fromAddress) { - /** @var Preferences $preferences */ + /** @var Preferences|null $preferences */ $preferences = $this->entityManager->getEntity('Preferences', $user->getId()); if ($preferences) { @@ -221,9 +221,7 @@ class Email extends Record implements if ($user) { if ($smtpParams) { - if ($fromAddress) { - $this->applySmtpHandler($user->getId(), $fromAddress, $smtpParams); - } + $this->applySmtpHandler($user->getId(), $fromAddress, $smtpParams); $emailSender->withSmtpParams($smtpParams); } @@ -434,7 +432,7 @@ class Email extends Record implements { $entity = parent::create($data, $params); - if ($entity && $entity->get('status') === EmailEntity::STATUS_SENDING) { + if ($entity->get('status') === EmailEntity::STATUS_SENDING) { $this->sendEntity($entity, $this->getUser()); } @@ -452,7 +450,7 @@ class Email extends Record implements protected function afterUpdateEntity(Entity $entity, $data) { - if ($entity && $entity->get('status') === EmailEntity::STATUS_SENDING) { + if ($entity->get('status') === EmailEntity::STATUS_SENDING) { $this->sendEntity($entity, $this->getUser()); } @@ -773,7 +771,7 @@ class Email extends Record implements throw new BadRequest(); } - /** @var EmailEntity $email */ + /** @var EmailEntity|null $email */ $email = $this->entityManager->getEntity(EmailEntity::ENTITY_TYPE, $id); if (!$email) { @@ -789,7 +787,7 @@ class Email extends Record implements $attachmentsIds = $email->get('attachmentsIds'); foreach ($attachmentsIds as $attachmentId) { - /** @var Attachment $source */ + /** @var Attachment|null $source */ $source = $this->entityManager->getEntity('Attachment', $attachmentId); if ($source) { @@ -1014,7 +1012,7 @@ class Email extends Record implements return null; } - /** @var EmailEntity $replied */ + /** @var EmailEntity|null $replied */ $replied = $this->entityManager ->getRDBRepository('Email') ->select(['messageId']) diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 8f86a6b335..65c6c7c56f 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -252,14 +252,12 @@ class EmailAccount extends Record implements $entity = parent::create($data, $params); - if ($entity) { - if (!$this->getUser()->isAdmin()) { - $entity->set('assignedUserId', $this->getUser()->getId()); - } - - $this->entityManager->saveEntity($entity); + if (!$this->getUser()->isAdmin()) { + $entity->set('assignedUserId', $this->getUser()->getId()); } + $this->entityManager->saveEntity($entity); + return $entity; } diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php index 9132d91371..10c1a32542 100644 --- a/application/Espo/Services/ExternalAccount.php +++ b/application/Espo/Services/ExternalAccount.php @@ -54,7 +54,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware protected function getClient(string $integration, string $id) { - /** @var IntegrationEntity $integrationEntity */ + /** @var IntegrationEntity|null $integrationEntity */ $integrationEntity = $this->entityManager->getEntity('Integration', $integration); if (!$integrationEntity) { diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index 84eaf4e82b..53d3951a1e 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -371,7 +371,7 @@ class InboundEmail extends RecordService implements if (preg_match('/MAILER-DAEMON|POSTMASTER/i', $fromString)) { try { - $toSkip = $this->processBouncedMessage($message) || $toSkip; + $toSkip = $this->processBouncedMessage($message); } catch (Throwable $e) { $this->log->error( diff --git a/application/Espo/Services/Notification.php b/application/Espo/Services/Notification.php index 96e6501bd0..134860670e 100644 --- a/application/Espo/Services/Notification.php +++ b/application/Espo/Services/Notification.php @@ -159,7 +159,7 @@ class Notification extends \Espo\Services\Record switch ($entity->get('type')) { case 'Note': case 'MentionInPost': - /** @var Note $note */ + /** @var ?Note $note */ $note = $this->entityManager->getEntity('Note', $data->noteId); if (!$note) { @@ -242,11 +242,11 @@ class Notification extends \Espo\Services\Record $scopes = $this->metadata->get('scopes', []); foreach ($scopes as $scope => $d) { - if (empty($d['entity']) || !$d['entity']) { + if (empty($d['entity'])) { continue; } - if (empty($d['object']) || !$d['object']) { + if (empty($d['object'])) { continue; } diff --git a/application/Espo/Services/Preferences.php b/application/Espo/Services/Preferences.php index a70baa787c..1bb2d90bcb 100644 --- a/application/Espo/Services/Preferences.php +++ b/application/Espo/Services/Preferences.php @@ -88,9 +88,9 @@ class Preferences { $this->processAccessCheck($userId); - /** @var PreferencesEntity $entity */ + /** @var ?PreferencesEntity $entity */ $entity = $this->entityManager->getEntity('Preferences', $userId); - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $userId); if (!$entity || !$user) { @@ -134,7 +134,7 @@ class Preferences $user = $this->entityManager->getEntity('User', $userId); - /** @var PreferencesEntity */ + /** @var ?PreferencesEntity */ $entity = $this->entityManager->getEntity('Preferences', $userId); if (!$entity || !$user) { @@ -172,7 +172,7 @@ class Preferences throw new Forbidden(); } - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $userId); $preferences = $this->entityManager->getEntity('Preferences', $userId); diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index d5dff98e0c..6251a9325b 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -380,7 +380,7 @@ class Stream $user = $this->user; } else { - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $userId); if (!$user) { diff --git a/application/Espo/Services/User.php b/application/Espo/Services/User.php index 46586e9a0e..be9a5380e5 100644 --- a/application/Espo/Services/User.php +++ b/application/Espo/Services/User.php @@ -81,7 +81,7 @@ class User extends Record implements throw new Forbidden(); } - /** @var UserEntity $entity */ + /** @var ?UserEntity $entity */ $entity = parent::getEntity($id); if ($entity && $entity->isSuperAdmin() && !$this->getUser()->isSuperAdmin()) { @@ -102,7 +102,7 @@ class User extends Record implements ?string $currentPassword = null ): void { - /** @var UserEntity $user */ + /** @var ?UserEntity $user */ $user = $this->getEntityManager()->getEntity('User', $userId); if (!$user) { @@ -374,7 +374,7 @@ class User extends Record implements public function generateNewApiKeyForEntity(string $id): Entity { - /** @var UserEntity $entity */ + /** @var ?UserEntity $entity */ $entity = $this->getEntity($id); if (!$entity) { @@ -414,7 +414,7 @@ class User extends Record implements } } - /** @var UserEntity $user */ + /** @var ?UserEntity $user */ $user = $this->getEntity($id); if (!$user) { diff --git a/application/Espo/Services/UserSecurity.php b/application/Espo/Services/UserSecurity.php index 17f8f93714..caad430123 100644 --- a/application/Espo/Services/UserSecurity.php +++ b/application/Espo/Services/UserSecurity.php @@ -87,7 +87,7 @@ class UserSecurity throw new Forbidden(); } - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $id); if (!$user) { @@ -114,7 +114,7 @@ class UserSecurity $isReset = $data->reset ?? false; - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $id); if (!$user) { @@ -163,7 +163,7 @@ class UserSecurity throw new Forbidden(); } - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $id); if (!$user) { diff --git a/application/Espo/Services/Webhook.php b/application/Espo/Services/Webhook.php index 429e4b8e6d..f6781311c8 100644 --- a/application/Espo/Services/Webhook.php +++ b/application/Espo/Services/Webhook.php @@ -123,7 +123,7 @@ class Webhook extends Record implements return; } - /** @var User $user */ + /** @var ?User $user */ $user = $this->getEntityManager()->getEntity('User', $userId); if (!$user || !$user->isApi()) { diff --git a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php index 962828b61d..d4c9d5ae4d 100644 --- a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php +++ b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php @@ -106,7 +106,7 @@ class AssignmentProcessor throw new LogicException(); } - /** @var User $user */ + /** @var ?User $user */ $user = $this->entityManager->getEntity('User', $userId); if (!$user) {