From 6cc19a52f16203c99b232e85459ed30367d5c3e2 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 5 Nov 2021 12:33:36 +0200 Subject: [PATCH] fixes --- application/Espo/Core/Formula/Parser.php | 6 ++-- .../Espo/Core/Htmlizer/TemplateRenderer.php | 2 ++ application/Espo/Core/InjectableFactory.php | 2 +- application/Espo/Core/Job/Job/Data.php | 2 ++ application/Espo/Core/Job/JobRunner.php | 5 ++-- application/Espo/Core/Job/JobScheduler.php | 2 ++ application/Espo/Core/Job/ScheduleUtil.php | 2 +- application/Espo/Core/Mail/Importer.php | 14 ++++----- .../Espo/Core/Mail/Parsers/MailMimeParser.php | 9 ++++-- application/Espo/Core/Mail/Sender.php | 14 +++------ application/Espo/Core/ORM/Helper.php | 29 +++++++++---------- 11 files changed, 41 insertions(+), 46 deletions(-) diff --git a/application/Espo/Core/Formula/Parser.php b/application/Espo/Core/Formula/Parser.php index de897ebf9d..9a1e508876 100644 --- a/application/Espo/Core/Formula/Parser.php +++ b/application/Espo/Core/Formula/Parser.php @@ -165,10 +165,8 @@ class Parser } else { if (!$isLineComment && !$isComment) { - if (!$isComment) { - if ($i && $string[$i] === '/' && $string[$i - 1] === '/') { - $isLineComment = true; - } + if ($i && $string[$i] === '/' && $string[$i - 1] === '/') { + $isLineComment = true; } if (!$isLineComment) { diff --git a/application/Espo/Core/Htmlizer/TemplateRenderer.php b/application/Espo/Core/Htmlizer/TemplateRenderer.php index 154e0734f9..2cd3d9c5bb 100644 --- a/application/Espo/Core/Htmlizer/TemplateRenderer.php +++ b/application/Espo/Core/Htmlizer/TemplateRenderer.php @@ -82,6 +82,8 @@ class TemplateRenderer */ public function setData($data): self { + /** @var mixed $data */ + if (!is_array($data) && !$data instanceof stdClass) { throw new InvalidArgumentException(); } diff --git a/application/Espo/Core/InjectableFactory.php b/application/Espo/Core/InjectableFactory.php index 56e3236498..279fa56740 100644 --- a/application/Espo/Core/InjectableFactory.php +++ b/application/Espo/Core/InjectableFactory.php @@ -343,7 +343,7 @@ class InjectableFactory $params = $class->getMethod($methodName)->getParameters(); - if (!$params || !count($params)) { + if (!count($params)) { return false; } diff --git a/application/Espo/Core/Job/Job/Data.php b/application/Espo/Core/Job/Job/Data.php index 9ca8c7af29..edc0680d2e 100644 --- a/application/Espo/Core/Job/Job/Data.php +++ b/application/Espo/Core/Job/Job/Data.php @@ -55,6 +55,8 @@ class Data */ public static function create($data = null): self { + /** @var mixed $data */ + if ($data !== null && !is_object($data) && !is_array($data)) { throw new TypeError(); } diff --git a/application/Espo/Core/Job/JobRunner.php b/application/Espo/Core/Job/JobRunner.php index 9f555973bb..2be26b342b 100644 --- a/application/Espo/Core/Job/JobRunner.php +++ b/application/Espo/Core/Job/JobRunner.php @@ -99,7 +99,7 @@ class JobRunner throw new Error(); } - /** @var JobEntity $jobEntity */ + /** @var JobEntity|null $jobEntity */ $jobEntity = $this->entityManager->getEntity(JobEntity::ENTITY_TYPE, $id); if (!$jobEntity) { @@ -118,7 +118,6 @@ class JobRunner private function runInternal(JobEntity $jobEntity, bool $throwException = false): void { $isSuccess = true; - $skipLog = false; $exception = null; @@ -172,7 +171,7 @@ class JobRunner throw new $exception($exception->getMessage()); } - if ($jobEntity->getScheduledJobId() && !$skipLog) { + if ($jobEntity->getScheduledJobId()) { $this->scheduleUtil->addLogRecord( $jobEntity->getScheduledJobId(), $status, diff --git a/application/Espo/Core/Job/JobScheduler.php b/application/Espo/Core/Job/JobScheduler.php index e0d5f0794c..ea483f6ad7 100644 --- a/application/Espo/Core/Job/JobScheduler.php +++ b/application/Espo/Core/Job/JobScheduler.php @@ -156,6 +156,8 @@ class JobScheduler */ public function setData($data): self { + /** @var mixed $data */ + if (!is_null($data) && !is_array($data) && !$data instanceof Data) { throw new TypeError(); } diff --git a/application/Espo/Core/Job/ScheduleUtil.php b/application/Espo/Core/Job/ScheduleUtil.php index 7db4a313b5..44f550e073 100644 --- a/application/Espo/Core/Job/ScheduleUtil.php +++ b/application/Espo/Core/Job/ScheduleUtil.php @@ -91,7 +91,7 @@ class ScheduleUtil $runTime = date(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT); } - /** @var ScheduledJobEntity $scheduledJob */ + /** @var ScheduledJobEntity|null $scheduledJob */ $scheduledJob = $this->entityManager->getEntity(ScheduledJobEntity::ENTITY_TYPE, $scheduledJobId); if (!$scheduledJob) { diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index 30d9281113..c9b295d9d7 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -218,11 +218,9 @@ class Importer try { $dt = new DateTime($parser->getMessageAttribute($message, 'date')); - if ($dt) { - $dateSent = $dt->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'); + $dateSent = $dt->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'); - $email->set('dateSent', $dateSent); - } + $email->set('dateSent', $dateSent); } catch (Exception $e) {} } @@ -234,11 +232,9 @@ class Importer try { $dt = new DateTime($parser->getMessageAttribute($message, 'delivery-Date')); - if ($dt) { - $deliveryDate = $dt->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'); + $deliveryDate = $dt->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'); - $email->set('delivery-Date', $deliveryDate); - } + $email->set('delivery-Date', $deliveryDate); } catch (Exception $e) {} } @@ -272,7 +268,7 @@ class Importer $inReplyTo = '<' . $inReplyTo . '>'; } - /** @var Email $replied */ + /** @var Email|null $replied */ $replied = $this->entityManager ->getRDBRepository('Email') ->where([ diff --git a/application/Espo/Core/Mail/Parsers/MailMimeParser.php b/application/Espo/Core/Mail/Parsers/MailMimeParser.php index 07620d6621..ade59dacb5 100644 --- a/application/Espo/Core/Mail/Parsers/MailMimeParser.php +++ b/application/Espo/Core/Mail/Parsers/MailMimeParser.php @@ -29,6 +29,8 @@ namespace Espo\Core\Mail\Parsers; +use Psr\Http\Message\StreamInterface; + use Espo\Entities\{ Email, Attachment, @@ -134,7 +136,7 @@ class MailMimeParser implements Parser return null; } - if ($messageId && strlen($messageId) && $messageId[0] !== '<') { + if ($messageId[0] !== '<') { $messageId = '<' . $messageId . '>'; } @@ -280,6 +282,7 @@ class MailMimeParser implements Parser $disposition = $attachmentPart->getHeaderValue('Content-Disposition'); + /** @var string|null $filename */ $filename = $attachmentPart->getHeaderParameter('Content-Disposition', 'filename', null); if ($filename === null) { @@ -295,6 +298,7 @@ class MailMimeParser implements Parser $content = ''; + /** @var StreamInterface|null $binaryContentStream */ $binaryContentStream = $attachmentPart->getBinaryContentStream(); if ($binaryContentStream) { @@ -353,7 +357,7 @@ class MailMimeParser implements Parser $email->set('body', $body); } - /* @var $textCalendarPart MessagePart */ + /** @var MessagePart|null $textCalendarPart */ $textCalendarPart = $this->getMessage($message)->getAllPartsByMimeType('text/calendar')[0] ?? $this->getMessage($message)->getAllPartsByMimeType('application/ics')[0] ?? @@ -385,6 +389,7 @@ class MailMimeParser implements Parser private function getAttachmentFilenameExtension(MimePart $part): ?string { + /** @var string|null $filename */ $filename = $part->getHeaderParameter('Content-Disposition', 'filename', null); if ($filename === null) { diff --git a/application/Espo/Core/Mail/Sender.php b/application/Espo/Core/Mail/Sender.php index 347b669dc0..1e43f349c0 100644 --- a/application/Espo/Core/Mail/Sender.php +++ b/application/Espo/Core/Mail/Sender.php @@ -338,13 +338,11 @@ class Sender if ($inboundEmail) { $service = $this->getInboundEmailService(); - if ($service) { - $params = $service->getSmtpParamsFromAccount($inboundEmail); + $params = $service->getSmtpParamsFromAccount($inboundEmail); - $this->applySmtp($params); + $this->applySmtp($params); - return; - } + return; } } @@ -398,12 +396,8 @@ class Sender return $this->systemInboundEmail; } - private function getInboundEmailService(): ?InboundEmailService + private function getInboundEmailService(): InboundEmailService { - if (!$this->serviceFactory) { - return null; - } - if (!$this->inboundEmailService) { $this->inboundEmailService = $this->serviceFactory->create('InboundEmail'); } diff --git a/application/Espo/Core/ORM/Helper.php b/application/Espo/Core/ORM/Helper.php index fe12990903..f6069c8684 100644 --- a/application/Espo/Core/ORM/Helper.php +++ b/application/Espo/Core/ORM/Helper.php @@ -107,23 +107,20 @@ class Helper } return implode(' ', $arr); - - default: - if (!$first && !$last) { - return null; - } - - if (!$first) { - return $last; - } - - if (!$last) { - return $first; - } - - return $first . ' ' . $last; } - return null; + if (!$first && !$last) { + return null; + } + + if (!$first) { + return $last; + } + + if (!$last) { + return $first; + } + + return $first . ' ' . $last; } }