From 094f6e2f50eb72233cca5c3d8fdace9b64124117 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 5 Nov 2021 12:53:54 +0200 Subject: [PATCH] fixes --- .../Espo/Classes/AssignmentNotificators/Email.php | 6 +----- application/Espo/Classes/Jobs/Cleanup.php | 8 -------- application/Espo/Controllers/EntityManager.php | 7 +------ application/Espo/Controllers/Preferences.php | 4 ---- application/Espo/Core/Acl/ScopeData.php | 8 +++++--- application/Espo/Core/AclManager.php | 1 + application/Espo/Core/Action/Service.php | 8 ++------ application/Espo/Core/Api/ErrorOutput.php | 7 +------ application/Espo/Core/Binding/BindingContainer.php | 4 +--- application/Espo/Core/Console/Commands/Upgrade.php | 5 +++++ .../Espo/Core/EntryPoint/EntryPointManager.php | 8 +++++++- .../Espo/Core/ExternalAccount/ClientManager.php | 8 ++++---- .../Espo/Core/ExternalAccount/OAuth2/Client.php | 2 +- .../Espo/Core/FieldProcessing/PhoneNumber/Saver.php | 2 +- .../Espo/Core/FieldProcessing/Reminder/Saver.php | 4 ---- application/Espo/Core/Formula/AttributeFetcher.php | 2 +- .../ExtGroup/EmailGroup/ApplyTemplateType.php | 2 +- .../Formula/Functions/ExtGroup/SmsGroup/SendType.php | 2 +- .../Core/Formula/Functions/LogicalGroup/AndType.php | 6 +++++- .../Core/Formula/Functions/LogicalGroup/OrType.php | 6 +++++- .../Core/Formula/Functions/RecordGroup/CreateType.php | 11 ++++++----- .../Espo/Core/Formula/Functions/VariableType.php | 2 +- 22 files changed, 50 insertions(+), 63 deletions(-) diff --git a/application/Espo/Classes/AssignmentNotificators/Email.php b/application/Espo/Classes/AssignmentNotificators/Email.php index d5f93983e9..8b410fb0f1 100644 --- a/application/Espo/Classes/AssignmentNotificators/Email.php +++ b/application/Espo/Classes/AssignmentNotificators/Email.php @@ -113,10 +113,6 @@ class Email implements AssignmentNotificator return; } - if (!$dt) { - return; - } - if ($dt->diff(new DateTime())->days > self::DAYS_THRESHOLD) { return; } @@ -235,7 +231,7 @@ class Email implements AssignmentNotificator } } - /** @var User $user */ + /** @var User|null $user */ $user = $this->entityManager->getEntity('User', $userId); if (!$user) { diff --git a/application/Espo/Classes/Jobs/Cleanup.php b/application/Espo/Classes/Jobs/Cleanup.php index 625e9879c6..26646024a7 100644 --- a/application/Espo/Classes/Jobs/Cleanup.php +++ b/application/Espo/Classes/Jobs/Cleanup.php @@ -569,10 +569,6 @@ class Cleanup implements JobDataLess $repository = $this->entityManager->getRepository($scope); - if (!$repository) { - return; - } - if (!$repository instanceof RDBRepository) { return; } @@ -728,10 +724,6 @@ class Cleanup implements JobDataLess $repository = $this->entityManager->getRepository($scope); - if (!$repository) { - continue; - } - if (!$repository instanceof RDBRepository) { continue; } diff --git a/application/Espo/Controllers/EntityManager.php b/application/Espo/Controllers/EntityManager.php index c331690d3b..4f18e94030 100644 --- a/application/Espo/Controllers/EntityManager.php +++ b/application/Espo/Controllers/EntityManager.php @@ -235,19 +235,14 @@ class EntityManager 'labelForeign', ]; - $additionalParamList = []; - $params = []; + foreach ($paramList as $item) { if (array_key_exists($item, $data)) { $params[$item] = filter_var($data[$item], \FILTER_SANITIZE_STRING); } } - foreach ($additionalParamList as $item) { - $params[$item] = filter_var($data[$item], \FILTER_SANITIZE_STRING); - } - if (array_key_exists('linkMultipleField', $data)) { $params['linkMultipleField'] = $data['linkMultipleField']; } diff --git a/application/Espo/Controllers/Preferences.php b/application/Espo/Controllers/Preferences.php index c7128bcf1e..3314682d52 100644 --- a/application/Espo/Controllers/Preferences.php +++ b/application/Espo/Controllers/Preferences.php @@ -83,10 +83,6 @@ class Preferences $data = $request->getParsedBody(); - if (!$userId) { - throw new BadRequest(); - } - return $this->service ->update($userId, $data) ->getValueMap(); diff --git a/application/Espo/Core/Acl/ScopeData.php b/application/Espo/Core/Acl/ScopeData.php index b79ce90ff8..77e0773c0f 100644 --- a/application/Espo/Core/Acl/ScopeData.php +++ b/application/Espo/Core/Acl/ScopeData.php @@ -29,7 +29,7 @@ namespace Espo\Core\Acl; -use StdClass; +use stdClass; use InvalidArgumentException; use RuntimeException; @@ -150,14 +150,16 @@ class ScopeData /** * Create from a raw table value. * - * @param StdClass|bool $raw + * @param stdClass|bool $raw * @return self */ public static function fromRaw($raw): self { + /** @var mixed $raw */ + $obj = new self(); - if ($raw instanceof StdClass) { + if ($raw instanceof stdClass) { $obj->isBoolean = false; $obj->actionData = get_object_vars($raw); diff --git a/application/Espo/Core/AclManager.php b/application/Espo/Core/AclManager.php index 43b433d2e1..2f5103a404 100644 --- a/application/Espo/Core/AclManager.php +++ b/application/Espo/Core/AclManager.php @@ -265,6 +265,7 @@ class AclManager return $this->checkScope($user, $subject, $action); } + /** @var mixed */ $entity = $subject; if ($entity instanceof Entity) { diff --git a/application/Espo/Core/Action/Service.php b/application/Espo/Core/Action/Service.php index 66e493ea84..a1ab63f3ad 100644 --- a/application/Espo/Core/Action/Service.php +++ b/application/Espo/Core/Action/Service.php @@ -41,7 +41,7 @@ use Espo\Core\{ use Espo\ORM\Entity; -use StdClass; +use stdClass; class Service { @@ -68,7 +68,7 @@ class Service * @throws BadRequest * @throws NotFound */ - public function process(string $entityType, string $action, string $id, StdClass $data): Entity + public function process(string $entityType, string $action, string $id, stdClass $data): Entity { if (!$this->acl->checkScope($entityType)) { throw new ForbiddenSilent(); @@ -91,10 +91,6 @@ class Service $entity = $service->read($id, ReadParams::create()); - if (!$entity) { - throw new NotFound(); - } - return $entity; } } diff --git a/application/Espo/Core/Api/ErrorOutput.php b/application/Espo/Core/Api/ErrorOutput.php index 7b088efc96..3dee6002c1 100644 --- a/application/Espo/Core/Api/ErrorOutput.php +++ b/application/Espo/Core/Api/ErrorOutput.php @@ -34,8 +34,6 @@ use Espo\Core\Exceptions\HasBody; use Espo\Core\{ Api\Request, Api\Response, - Exceptions\Conflict, - Exceptions\Error, Utils\Log, Utils\Config, }; @@ -137,10 +135,7 @@ class ErrorOutput } $logMessageItemList[] = $request->getMethod() . ' ' . $request->getResourcePath(); - - if ($messageLineFile) { - $logMessageItemList[] = $messageLineFile; - } + $logMessageItemList[] = $messageLineFile; $logMessage = "($statusCode) " . implode("; ", $logMessageItemList); diff --git a/application/Espo/Core/Binding/BindingContainer.php b/application/Espo/Core/Binding/BindingContainer.php index 9780abd2ea..1ab3563d35 100644 --- a/application/Espo/Core/Binding/BindingContainer.php +++ b/application/Espo/Core/Binding/BindingContainer.php @@ -95,9 +95,7 @@ class BindingContainer if ($dependencyClassName) { $key = $dependencyClassName; - if ($key) { - $keyWithParamName = $key . ' $' . $param->getName(); - } + $keyWithParamName = $key . ' $' . $param->getName(); } if ($keyWithParamName) { diff --git a/application/Espo/Core/Console/Commands/Upgrade.php b/application/Espo/Core/Console/Commands/Upgrade.php index dc17f6ee89..bebeef3fdc 100644 --- a/application/Espo/Core/Console/Commands/Upgrade.php +++ b/application/Espo/Core/Console/Commands/Upgrade.php @@ -224,6 +224,11 @@ class Upgrade implements Command return $params; } + /** + * @param \stdClass $params + * @param \stdClass|null $versionInfo + * @return string|null + */ protected function getPackageFile(object $params, ?object $versionInfo) { $packageFile = $params->file ?? null; diff --git a/application/Espo/Core/EntryPoint/EntryPointManager.php b/application/Espo/Core/EntryPoint/EntryPointManager.php index 66411b2011..4761888e04 100644 --- a/application/Espo/Core/EntryPoint/EntryPointManager.php +++ b/application/Espo/Core/EntryPoint/EntryPointManager.php @@ -61,7 +61,13 @@ class EntryPointManager throw new NotFound("Entry point '{$name}' not found."); } - if ($className::$noAuth ?? false) { + $noAuth = false; + + if (isset($className::$noAuth)) { + $noAuth = $className::$noAuth; + } + + if ($noAuth) { return false; } diff --git a/application/Espo/Core/ExternalAccount/ClientManager.php b/application/Espo/Core/ExternalAccount/ClientManager.php index 2972e8acc1..1a5d910eec 100644 --- a/application/Espo/Core/ExternalAccount/ClientManager.php +++ b/application/Espo/Core/ExternalAccount/ClientManager.php @@ -126,10 +126,10 @@ class ClientManager throw new Error(); } - /** @var IntegrationEntity $integrationEntity */ + /** @var IntegrationEntity|null $integrationEntity */ $integrationEntity = $this->entityManager->getEntity('Integration', $integration); - /** @var ExternalAccountEntity $externalAccountEntity */ + /** @var ExternalAccountEntity|null $externalAccountEntity */ $externalAccountEntity = $this->entityManager->getEntity('ExternalAccount', $integration . '__' . $userId); if (!$externalAccountEntity) { @@ -162,10 +162,10 @@ class ClientManager protected function createOAuth2(string $integration, string $userId): ?object { - /** @var IntegrationEntity $integrationEntity */ + /** @var IntegrationEntity|null $integrationEntity */ $integrationEntity = $this->entityManager->getEntity('Integration', $integration); - /** @var ExternalAccountEntity $externalAccountEntity */ + /** @var ExternalAccountEntity|null $externalAccountEntity */ $externalAccountEntity = $this->entityManager->getEntity('ExternalAccount', $integration . '__' . $userId); $className = $this->metadata->get("integrations.{$integration}.clientClassName"); diff --git a/application/Espo/Core/ExternalAccount/OAuth2/Client.php b/application/Espo/Core/ExternalAccount/OAuth2/Client.php index aab96c76f0..a359e9a6e6 100644 --- a/application/Espo/Core/ExternalAccount/OAuth2/Client.php +++ b/application/Espo/Core/ExternalAccount/OAuth2/Client.php @@ -211,7 +211,7 @@ class Client $curlOptHttpHeader = []; foreach ($httpHeaders as $key => $value) { - if (is_int($key) && !is_string($key)) { + if (is_int($key)) { $curlOptHttpHeader[] = $value; continue; diff --git a/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php b/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php index bbd87eb6fd..4a3fec92ed 100644 --- a/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php +++ b/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php @@ -180,7 +180,7 @@ class Saver implements SaverInterface if ($phoneNumberValue) { $key = $phoneNumberValue; - if ($key && isset($hash->$key)) { + if (isset($hash->$key)) { $hash->{$key}['optOut'] = $entity->get('phoneNumberIsOptedOut'); } } diff --git a/application/Espo/Core/FieldProcessing/Reminder/Saver.php b/application/Espo/Core/FieldProcessing/Reminder/Saver.php index ee5f1e8e25..cbb42ede87 100644 --- a/application/Espo/Core/FieldProcessing/Reminder/Saver.php +++ b/application/Espo/Core/FieldProcessing/Reminder/Saver.php @@ -158,10 +158,6 @@ class Saver implements SaverInterface $dateValueObj = new DateTime($dateValue); - if (!$dateValueObj) { - return; - } - foreach ($reminderList as $item) { $remindAt = clone $dateValueObj; $seconds = intval($item->seconds); diff --git a/application/Espo/Core/Formula/AttributeFetcher.php b/application/Espo/Core/Formula/AttributeFetcher.php index 87b5c951ef..f1529aa54f 100644 --- a/application/Espo/Core/Formula/AttributeFetcher.php +++ b/application/Espo/Core/Formula/AttributeFetcher.php @@ -58,7 +58,7 @@ class AttributeFetcher if ( $relatedEntity && ($relatedEntity instanceof Entity) && - count($arr) > 0 + count($arr) > 1 ) { return $this->fetch($relatedEntity, $arr[1]); } diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php index e5b4699d23..a6310320b6 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php @@ -76,7 +76,7 @@ class ApplyTemplateType extends BaseFunction implements $em = $this->entityManager; - /** @var Email $email */ + /** @var Email|null $email */ $email = $em->getEntity('Email', $id); $emailTemplate = $em->getEntity('EmailTemplate', $templateId); diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php index 5c1c508dba..7dc36652cd 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php @@ -60,7 +60,7 @@ class SendType extends BaseFunction implements $this->throwBadArgumentType(1, 'string'); } - /** @var Sms $sms */ + /** @var Sms|null $sms */ $sms = $this->entityManager->getEntity(Sms::ENTITY_TYPE, $id); if (!$sms) { diff --git a/application/Espo/Core/Formula/Functions/LogicalGroup/AndType.php b/application/Espo/Core/Formula/Functions/LogicalGroup/AndType.php index f352afa20c..270063ca6e 100644 --- a/application/Espo/Core/Formula/Functions/LogicalGroup/AndType.php +++ b/application/Espo/Core/Formula/Functions/LogicalGroup/AndType.php @@ -41,8 +41,12 @@ class AndType extends BaseFunction $result = true; foreach ($args as $item) { + /** @phpstan-ignore-next-line */ $result = $result && $this->evaluate($item); - if (!$result) break; + + if (!$result) { + break; + } } return $result; diff --git a/application/Espo/Core/Formula/Functions/LogicalGroup/OrType.php b/application/Espo/Core/Formula/Functions/LogicalGroup/OrType.php index a84a97051e..1d6ce241db 100644 --- a/application/Espo/Core/Formula/Functions/LogicalGroup/OrType.php +++ b/application/Espo/Core/Formula/Functions/LogicalGroup/OrType.php @@ -41,8 +41,12 @@ class OrType extends BaseFunction $result = false; foreach ($args as $item) { + /** @phpstan-ignore-next-line */ $result = $result || $this->evaluate($item); - if ($result) break; + + if ($result) { + break; + } } return $result; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php index d66b5fb715..bfbc510fbd 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php @@ -58,22 +58,23 @@ class CreateType extends BaseFunction implements $data = []; $i = 1; + while ($i < count($args) - 1) { $attribute = $args[$i]; + if (!is_string($entityType)) { $this->throwBadArgumentType($i + 1, 'string'); } + $value = $args[$i + 1]; + $data[$attribute] = $value; + $i = $i + 2; } $entity = $this->entityManager->createEntity($entityType, $data); - if ($entity) { - return $entity->getId(); - } - - return null; + return $entity->getId(); } } diff --git a/application/Espo/Core/Formula/Functions/VariableType.php b/application/Espo/Core/Formula/Functions/VariableType.php index d8ca43beff..38a935beaf 100644 --- a/application/Espo/Core/Formula/Functions/VariableType.php +++ b/application/Espo/Core/Formula/Functions/VariableType.php @@ -50,7 +50,7 @@ class VariableType extends BaseFunction throw new Error("Bad variable name."); } - if (is_null($name) && $name === '') { + if ($name === '') { throw new Error("Empty variable name."); }