diff --git a/application/Espo/Core/Di/EntityManagerAware.php b/application/Espo/Core/Di/EntityManagerAware.php index 9acf28f000..d0de8b9695 100644 --- a/application/Espo/Core/Di/EntityManagerAware.php +++ b/application/Espo/Core/Di/EntityManagerAware.php @@ -29,7 +29,7 @@ namespace Espo\Core\Di; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; interface EntityManagerAware { diff --git a/application/Espo/Core/Di/EntityManagerSetter.php b/application/Espo/Core/Di/EntityManagerSetter.php index afc4c6a176..f7880ad7e8 100644 --- a/application/Espo/Core/Di/EntityManagerSetter.php +++ b/application/Espo/Core/Di/EntityManagerSetter.php @@ -29,7 +29,7 @@ namespace Espo\Core\Di; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; trait EntityManagerSetter { diff --git a/application/Espo/ORM/Repository/RDBRepository.php b/application/Espo/ORM/Repository/RDBRepository.php index d5170486cf..e7f45a7c79 100644 --- a/application/Espo/ORM/Repository/RDBRepository.php +++ b/application/Espo/ORM/Repository/RDBRepository.php @@ -118,7 +118,7 @@ class RDBRepository implements Repository ]) ->build(); - /** @var T $entity */ + /** @var ?T $entity */ $entity = $this->getMapper()->selectOne($selectQuery); return $entity; @@ -126,6 +126,8 @@ class RDBRepository implements Repository /** * Get an entity. If ID is NULL, a new entity is returned. + * + * @phpstan-return ?T */ public function get(?string $id = null): ?Entity { diff --git a/application/Espo/Repositories/Attachment.php b/application/Espo/Repositories/Attachment.php index bec3a55684..07a482732e 100644 --- a/application/Espo/Repositories/Attachment.php +++ b/application/Espo/Repositories/Attachment.php @@ -30,9 +30,7 @@ namespace Espo\Repositories; use Espo\ORM\Entity; - use Espo\Entities\Attachment as AttachmentEntity; - use Espo\Core\Repositories\Database; use Espo\Core\Di; @@ -40,8 +38,7 @@ use Espo\Core\Di; use Psr\Http\Message\StreamInterface; /** - * @template T of \Espo\Entities\Attachment - * @extends Database<\Espo\Entities\Attachment> + * @extends Database */ class Attachment extends Database implements Di\FileManagerAware, @@ -105,16 +102,18 @@ class Attachment extends Database implements { parent::afterRemove($entity, $options); - $duplicateCount = $this->where([ - 'OR' => [ - [ - 'sourceId' => $entity->getSourceId() + $duplicateCount = $this + ->where([ + 'OR' => [ + [ + 'sourceId' => $entity->getSourceId() + ], + [ + 'id' => $entity->getSourceId() + ] ], - [ - 'id' => $entity->getSourceId() - ] - ], - ])->count(); + ]) + ->count(); if ($duplicateCount === 0) { $this->fileStorageManager->unlink($entity); @@ -136,10 +135,7 @@ class Attachment extends Database implements } } - /** - * @return AttachmentEntity - */ - public function getCopiedAttachment(AttachmentEntity $entity, $role = null) + public function getCopiedAttachment(AttachmentEntity $entity, $role = null): AttachmentEntity { $attachment = $this->get(); diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 521c27a5d4..0e474066ea 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -499,6 +499,7 @@ class Email extends Database implements private function getEmailAddressRepository(): EmailAddressRepository { + /** @var EmailAddressRepository */ return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE); } } diff --git a/application/Espo/Repositories/EmailAddress.php b/application/Espo/Repositories/EmailAddress.php index 30aa5f5f6c..64c4851b88 100644 --- a/application/Espo/Repositories/EmailAddress.php +++ b/application/Espo/Repositories/EmailAddress.php @@ -139,6 +139,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements public function getByAddress(string $address): ?EmailAddressEntity { + /** @var ?EmailAddressEntity */ return $this->where(['lower' => strtolower($address)])->findOne(); } diff --git a/application/Espo/Repositories/ExternalAccount.php b/application/Espo/Repositories/ExternalAccount.php index 0d6ec7601e..cf6add7cb9 100644 --- a/application/Espo/Repositories/ExternalAccount.php +++ b/application/Espo/Repositories/ExternalAccount.php @@ -31,13 +31,21 @@ namespace Espo\Repositories; use Espo\ORM\Entity; -class ExternalAccount extends \Espo\Core\Repositories\Database +use Espo\Core\Repositories\Database; + +use Espo\Entities\ExternalAccount as ExternalAccountEntity; + +/** + * @extends Database + */ +class ExternalAccount extends Database { public function getById(string $id): ?Entity { $entity = parent::getById($id); if (!$entity) { + /** @var ExternalAccountEntity */ $entity = $this->get(); $entity->set('id', $id); diff --git a/application/Espo/Repositories/Integration.php b/application/Espo/Repositories/Integration.php index 0107e3da29..1a0086846a 100644 --- a/application/Espo/Repositories/Integration.php +++ b/application/Espo/Repositories/Integration.php @@ -31,13 +31,21 @@ namespace Espo\Repositories; use Espo\ORM\Entity; -class Integration extends \Espo\Core\Repositories\Database +use Espo\Core\Repositories\Database; + +use Espo\Entities\Integration as IntegrationEntity; + +/** + * @extends Database + */ +class Integration extends Database { public function getById(string $id): ?Entity { $entity = parent::getById($id); if (!$entity) { + /** @var IntegrationEntity */ $entity = $this->get(); $entity->set('id', $id); diff --git a/application/Espo/Repositories/PhoneNumber.php b/application/Espo/Repositories/PhoneNumber.php index d8c4b239eb..566c644149 100644 --- a/application/Espo/Repositories/PhoneNumber.php +++ b/application/Espo/Repositories/PhoneNumber.php @@ -37,6 +37,10 @@ use Espo\Core\Repositories\Database; use Espo\Core\Di; +/** + * @template T of PhoneNumberEntity + * @extends Database + */ class PhoneNumber extends Database implements Di\ApplicationStateAware, @@ -131,6 +135,7 @@ class PhoneNumber extends Database implements public function getByNumber(string $number): ?PhoneNumberEntity { + /** @var ?PhoneNumberEntity */ return $this->where(['name' => $number])->findOne(); } diff --git a/application/Espo/Repositories/User.php b/application/Espo/Repositories/User.php index bd0cfbf420..dc334a12f4 100644 --- a/application/Espo/Repositories/User.php +++ b/application/Espo/Repositories/User.php @@ -168,6 +168,7 @@ class User extends Database private function getUserDataRepository(): UserDataRepository { + /** @var UserDataRepository */ return $this->entityManager->getRepository(UserData::ENTITY_TYPE); } } diff --git a/application/Espo/Repositories/UserData.php b/application/Espo/Repositories/UserData.php index bf74cdfba8..802e3897f1 100644 --- a/application/Espo/Repositories/UserData.php +++ b/application/Espo/Repositories/UserData.php @@ -35,6 +35,7 @@ class UserData extends \Espo\Core\Repositories\Database { public function getByUserId(string $userId): ?UserDataEntity { + /** @var ?UserDataEntity */ $userData = $this ->where(['userId' => $userId]) ->findOne(); @@ -51,6 +52,7 @@ class UserData extends \Espo\Core\Repositories\Database return null; } + /** @var ?UserDataEntity */ $userData = $this->getNew(); $userData->set('userId', $userId); diff --git a/application/Espo/Services/App.php b/application/Espo/Services/App.php index 0aea64207e..3539843e0c 100644 --- a/application/Espo/Services/App.php +++ b/application/Espo/Services/App.php @@ -372,7 +372,7 @@ class App private function convertPHPSizeToBytes($size) { if (is_numeric($size)) { - return $size; + return (int) $size; } if ($size === false) { @@ -569,11 +569,13 @@ class App private function getPhoneNumberRepository(): PhoneNumberRepository { + /** @var PhoneNumberRepository */ return $this->entityManager->getRepository(PhoneNumber::ENTITY_TYPE); } private function getArrayValueRepository(): ArrayValueRepository { + /** @var ArrayValueRepository */ return $this->entityManager->getRepository(ArrayValue::ENTITY_TYPE); } } diff --git a/application/Espo/Services/Attachment.php b/application/Espo/Services/Attachment.php index f75860cd3b..c0fe81c50d 100644 --- a/application/Espo/Services/Attachment.php +++ b/application/Espo/Services/Attachment.php @@ -482,6 +482,7 @@ class Attachment extends Record private function getAttachmentRepository(): AttachmentRepository { + /** @var AttachmentRepository */ return $this->getRepository(); } } diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 416e625849..1eaddea8d3 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -1032,16 +1032,19 @@ class Email extends Record implements private function getEmailAccountService(): EmailAccountService { + /** @var EmailAccountService */ return $this->injectableFactory->create(EmailAccountService::class); } private function getInboundEmailService(): InboundEmailService { + /** @var InboundEmailService */ return $this->injectableFactory->create(InboundEmailService::class); } private function getUserDataRepository(): UserDataRepository { + /** @var UserDataRepository */ return $this->entityManager->getRepository(UserData::ENTITY_TYPE); } } diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index f8e7c527c7..8f86a6b335 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -720,6 +720,7 @@ class EmailAccount extends Record implements private function getUserDataRepository(): UserDataRepository { + /** @var UserDataRepository */ return $this->entityManager->getRepository(UserData::ENTITY_TYPE); } } diff --git a/application/Espo/Services/EmailAddress.php b/application/Espo/Services/EmailAddress.php index fb8d7d6b3b..a947c03463 100644 --- a/application/Espo/Services/EmailAddress.php +++ b/application/Espo/Services/EmailAddress.php @@ -280,6 +280,7 @@ class EmailAddress extends Record private function getEmailAddressRepository(): Repository { + /** @var Repository */ return $this->entityManager->getRepository(EmailAddressEntity::ENTITY_TYPE); } } diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index b05c5221a6..c3a308ed43 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -191,6 +191,7 @@ class EmailTemplate extends Record implements private function getEmailAddressRepository(): EmailAddressRepository { + /** @var EmailAddressRepository */ return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE); } } diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php index 1d6ff184fa..9132d91371 100644 --- a/application/Espo/Services/ExternalAccount.php +++ b/application/Espo/Services/ExternalAccount.php @@ -79,6 +79,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware public function getExternalAccountEntity(string $integration, string $userId): ?ExternalAccountEntity { + /** @var ?ExternalAccountEntity */ return $this->entityManager->getEntity('ExternalAccount', $integration . '__' . $userId); } diff --git a/application/Espo/Services/Import.php b/application/Espo/Services/Import.php index fc87006620..a4c600bfcc 100644 --- a/application/Espo/Services/Import.php +++ b/application/Espo/Services/Import.php @@ -69,6 +69,7 @@ class Import extends Record ->withSearchParams($searchParams) ->build(); + /** @var iterable<\Espo\ORM\Entity> */ $collection = $this->getImportRepository()->findResultRecords($entity, $link, $query); $listLoadProcessor = $this->injectableFactory->create(ListLoadProcessor::class); @@ -87,6 +88,7 @@ class Import extends Record private function getImportRepository(): Repository { + /** @var Repository */ return $this->getRepository(); } } diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index b7dc6065fa..84eaf4e82b 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -1105,6 +1105,7 @@ class InboundEmail extends RecordService implements public function findAccountForSending(string $emailAddress): ?InboundEmailEntity { + /** @var ?InboundEmailEntity */ $inboundEmail = $this->entityManager ->getRDBRepository('InboundEmail') ->where([ @@ -1150,6 +1151,7 @@ class InboundEmail extends RecordService implements 'distinct' => true, ]; + /** @var ?InboundEmailEntity */ return $this->entityManager->getRDBRepository('InboundEmail')->findOne($selectParams);; } @@ -1163,6 +1165,7 @@ class InboundEmail extends RecordService implements ] ]; + /** @var ?InboundEmailEntity */ return $this->entityManager->getRDBRepository('InboundEmail')->findOne($selectParams); } @@ -1371,6 +1374,7 @@ class InboundEmail extends RecordService implements private function getEmailTemplateService(): EmailTemplateService { + /** @var EmailTemplateService */ return $this->injectableFactory->create(EmailTemplateService::class); } } diff --git a/application/Espo/Services/Note.php b/application/Espo/Services/Note.php index 623c82d2bc..b02bcdeede 100644 --- a/application/Espo/Services/Note.php +++ b/application/Espo/Services/Note.php @@ -354,6 +354,7 @@ class Note extends Record private function getUserRepository(): UserRepository { + /** @var UserRepository */ return $this->entityManager->getRepository(UserEntity::ENTITY_TYPE); } } diff --git a/application/Espo/Services/Portal.php b/application/Espo/Services/Portal.php index 8a7c25aed3..b6499e0712 100644 --- a/application/Espo/Services/Portal.php +++ b/application/Espo/Services/Portal.php @@ -75,6 +75,7 @@ class Portal extends Record implements private function getPortalRepository(): Repository { + /** @var Repository */ return $this->getRepository(); } } diff --git a/application/Espo/Services/Preferences.php b/application/Espo/Services/Preferences.php index 50283f4909..a70baa787c 100644 --- a/application/Espo/Services/Preferences.php +++ b/application/Espo/Services/Preferences.php @@ -134,6 +134,7 @@ class Preferences $user = $this->entityManager->getEntity('User', $userId); + /** @var PreferencesEntity */ $entity = $this->entityManager->getEntity('Preferences', $userId); if (!$entity || !$user) { @@ -213,6 +214,7 @@ class Preferences private function getRepository(): Repository { + /** @var Repository */ return $this->entityManager->getRepository(PreferencesEntity::ENTITY_TYPE); } } diff --git a/application/Espo/Services/Settings.php b/application/Espo/Services/Settings.php index 7a4f7ca4fd..1f75b234f3 100644 --- a/application/Espo/Services/Settings.php +++ b/application/Espo/Services/Settings.php @@ -297,6 +297,7 @@ class Settings private function getPortalRepository(): PortalRepository { + /** @var PortalRepository */ return $this->entityManager->getRepository(Portal::ENTITY_TYPE); } } diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 9da4a619dd..d5dff98e0c 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -2245,6 +2245,7 @@ class Stream private function getEmailAddressRepository(): EmailAddressRepository { + /** @var EmailAddressRepository */ return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE); } } diff --git a/application/Espo/Services/UserSecurity.php b/application/Espo/Services/UserSecurity.php index 689f926630..17f8f93714 100644 --- a/application/Espo/Services/UserSecurity.php +++ b/application/Espo/Services/UserSecurity.php @@ -263,6 +263,7 @@ class UserSecurity private function getUserDataRepository(): UserDataRepository { + /** @var UserDataRepository */ return $this->entityManager->getRepository(UserData::ENTITY_TYPE); } } diff --git a/application/Espo/Tools/EmailNotification/Processor.php b/application/Espo/Tools/EmailNotification/Processor.php index 389f459cfe..91387fdcc1 100644 --- a/application/Espo/Tools/EmailNotification/Processor.php +++ b/application/Espo/Tools/EmailNotification/Processor.php @@ -887,6 +887,7 @@ class Processor private function getPortalRepository(): PortalRepository { + /** @var PortalRepository */ return $this->entityManager->getRepository('Portal'); } } diff --git a/application/Espo/Tools/EmailTemplate/Processor.php b/application/Espo/Tools/EmailTemplate/Processor.php index 8aaa5c2326..88c9255816 100644 --- a/application/Espo/Tools/EmailTemplate/Processor.php +++ b/application/Espo/Tools/EmailTemplate/Processor.php @@ -420,6 +420,7 @@ class Processor private function getEmailAddressRepository(): EmailAddressRepository { + /** @var EmailAddressRepository */ return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE); } } diff --git a/application/Espo/Tools/Export/Export.php b/application/Espo/Tools/Export/Export.php index fd1094b240..5b13825ebe 100644 --- a/application/Espo/Tools/Export/Export.php +++ b/application/Espo/Tools/Export/Export.php @@ -64,7 +64,7 @@ class Export private $params; /** - * @var Collection + * @phpstan-var (Collection&iterable)|null $collection */ private $collection = null; @@ -115,6 +115,9 @@ class Export return $this; } + /** + * @phpstan-param Collection&iterable $collection + */ public function setCollection(Collection $collection): self { $this->collection = $collection; @@ -337,6 +340,9 @@ class Export return true; } + /** + * @phpstan-return Collection&iterable + */ private function getCollection(Params $params): Collection { if ($this->collection) { @@ -358,8 +364,9 @@ class Export $query = $builder->build(); + /** @phpstan-var Collection&iterable */ return $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->clone($query) ->sth() ->find(); diff --git a/application/Espo/Tools/Notification/NoteHookProcessor.php b/application/Espo/Tools/Notification/NoteHookProcessor.php index acdc49c123..e931fa1fec 100644 --- a/application/Espo/Tools/Notification/NoteHookProcessor.php +++ b/application/Espo/Tools/Notification/NoteHookProcessor.php @@ -401,11 +401,12 @@ class NoteHookProcessor } /** - * @phpstan-return Collection + * @phpstan-return Collection&iterable * @return User[] */ private function getSubscriberList(string $parentType, string $parentId, bool $isInternal = false): Collection { + /** @var Collection&iterable */ return $this->streamService->getSubscriberList($parentType, $parentId, $isInternal); } } diff --git a/application/Espo/Tools/Pdf/Tcpdf/TcpdfCollectionPrinter.php b/application/Espo/Tools/Pdf/Tcpdf/TcpdfCollectionPrinter.php index ab7eeb9bef..c567692c79 100644 --- a/application/Espo/Tools/Pdf/Tcpdf/TcpdfCollectionPrinter.php +++ b/application/Espo/Tools/Pdf/Tcpdf/TcpdfCollectionPrinter.php @@ -49,6 +49,8 @@ class TcpdfCollectionPrinter implements CollectionPrinter public function print(Template $template, Collection $collection, Params $params, IdDataMap $dataMap): Contents { + /** @var iterable<\Espo\ORM\Entity> $collection */ + $pdf = new Tcpdf(); $pdf->setUseGroupNumbers(true);