diff --git a/application/Espo/Core/Authentication/Oidc/KeysProvider.php b/application/Espo/Core/Authentication/Oidc/KeysProvider.php index 0116f46c4a..e05b10bf6a 100644 --- a/application/Espo/Core/Authentication/Oidc/KeysProvider.php +++ b/application/Espo/Core/Authentication/Oidc/KeysProvider.php @@ -128,7 +128,7 @@ class KeysProvider /** @var string|false $response */ $response = curl_exec($curl); $error = curl_error($curl); - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE) ?? 0; + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); diff --git a/application/Espo/Core/Authentication/Oidc/Login.php b/application/Espo/Core/Authentication/Oidc/Login.php index 3bbe451e52..e592b65e7c 100644 --- a/application/Espo/Core/Authentication/Oidc/Login.php +++ b/application/Espo/Core/Authentication/Oidc/Login.php @@ -226,7 +226,7 @@ class Login implements LoginInterface /** @var string|false $response */ $response = curl_exec($curl); $error = curl_error($curl); - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE) ?? 0; + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); diff --git a/application/Espo/Core/Currency/CalculatorUtil.php b/application/Espo/Core/Currency/CalculatorUtil.php index 0080b72b4b..3b85507fe3 100644 --- a/application/Espo/Core/Currency/CalculatorUtil.php +++ b/application/Espo/Core/Currency/CalculatorUtil.php @@ -88,6 +88,7 @@ class CalculatorUtil ); } + /** @var ?string $result */ $result = bcdiv( $arg1, $arg2, diff --git a/application/Espo/Core/ExternalAccount/OAuth2/Client.php b/application/Espo/Core/ExternalAccount/OAuth2/Client.php index 53a3aed600..244257982a 100644 --- a/application/Espo/Core/ExternalAccount/OAuth2/Client.php +++ b/application/Espo/Core/ExternalAccount/OAuth2/Client.php @@ -216,7 +216,7 @@ class Client * @return array{ * result: array|string, * code: int, - * contentType: string, + * contentType: string|false, * header: string, * } * @throws Exception @@ -258,9 +258,9 @@ class Client * @param string $httpMethod * @param array $httpHeaders * @return array{ - * result: array|string, + * result: array|string, * code: int, - * contentType: string, + * contentType: string|false, * header: string, * } * @throws Exception @@ -353,25 +353,27 @@ class Client $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $responceHeader = substr($response, 0, $headerSize); - $responceBody = substr($response, $headerSize); - - $resultArray = null; + $responseHeader = substr($response, 0, $headerSize); + $responseBody = substr($response, $headerSize); if ($curlError = curl_error($ch)) { throw new Exception($curlError); } - else { - $resultArray = json_decode($responceBody, true); - } + + $resultArray = json_decode($responseBody, true); curl_close($ch); + /** @var array|string $result */ + $result = ($resultArray !== null) ? + $resultArray : + $responseBody; + return [ - 'result' => (null !== $resultArray) ? $resultArray : $responceBody, + 'result' => $result, 'code' => intval($httpCode), 'contentType' => $contentType, - 'header' => $responceHeader, + 'header' => $responseHeader, ]; } @@ -383,9 +385,9 @@ class Client * client_secret?: string, * } $params * @return array{ - * result: array|string, + * result: array|string, * code: int, - * contentType: string, + * contentType: string|false, * header: string, * } * @throws Exception diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php index f168512baa..66cbb31e38 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php @@ -31,7 +31,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; use Espo\Core\Di; diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php index 12734330d4..ec43554f98 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php @@ -31,7 +31,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; use Espo\Core\Di; diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php index 065b9f197e..df37bdf63e 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php @@ -31,7 +31,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; use Espo\Core\Di; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php b/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php index 3d205c7fc8..f59ab05ce5 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php @@ -29,7 +29,7 @@ namespace Espo\Core\Formula\Functions\RecordGroup; -use Espo\Core\ORM\EntityManager; +use Espo\ORM\EntityManager; use Espo\Core\Formula\{ Functions\BaseFunction, diff --git a/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php b/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php index 22a9fba27d..2780bc34dd 100644 --- a/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php +++ b/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php @@ -105,13 +105,13 @@ class EspoRotatingFileHandler extends EspoFileHandler $fileInfo = pathinfo($this->filename); $timedFilename = str_replace( - array('{filename}', '{date}'), - array($fileInfo['filename'], date($this->dateFormat)), - $fileInfo['dirname'] . '/' . $this->filenameFormat + ['{filename}', '{date}'], + [$fileInfo['filename'], date($this->dateFormat)], + ($fileInfo['dirname'] ?? '') . '/' . $this->filenameFormat ); if (!empty($fileInfo['extension'])) { - $timedFilename .= '.'.$fileInfo['extension']; + $timedFilename .= '.' . $fileInfo['extension']; } return $timedFilename; diff --git a/application/Espo/Core/Mail/Parsers/MailMimeParser.php b/application/Espo/Core/Mail/Parsers/MailMimeParser.php index c299a127e4..be242843d1 100644 --- a/application/Espo/Core/Mail/Parsers/MailMimeParser.php +++ b/application/Espo/Core/Mail/Parsers/MailMimeParser.php @@ -66,7 +66,6 @@ class MailMimeParser implements Parser ]; private EntityManager $entityManager; - private ?WrappeeParser $parser = null; /** @@ -337,11 +336,12 @@ class MailMimeParser implements Parser $contentId = trim($contentId, '<>'); } - if ($disposition == 'inline') { + if ($disposition === 'inline') { $attachment->set('role', Attachment::ROLE_INLINE_ATTACHMENT); } else { $disposition = 'attachment'; + $attachment->set('role', Attachment::ROLE_ATTACHMENT); } @@ -349,23 +349,27 @@ class MailMimeParser implements Parser $this->entityManager->saveEntity($attachment); - if ($disposition == 'attachment') { + if ($disposition === 'attachment') { $email->addLinkMultipleId('attachments', $attachment->getId()); if ($contentId) { $inlineIds[$contentId] = $attachment->getId(); } - } - else if ($disposition == 'inline') { - if ($contentId) { - $inlineIds[$contentId] = $attachment->getId(); - $inlineAttachmentList[] = $attachment; - } - else { - $email->addLinkMultipleId('attachments', $attachment->getId()); - } + continue; } + + // inline + + if ($contentId) { + $inlineIds[$contentId] = $attachment->getId(); + + $inlineAttachmentList[] = $attachment; + + continue; + } + + $email->addLinkMultipleId('attachments', $attachment->getId()); } $body = $email->get('body'); diff --git a/application/Espo/Core/Utils/DataUtil.php b/application/Espo/Core/Utils/DataUtil.php index 86bbb5bba2..81b08c4e99 100644 --- a/application/Espo/Core/Utils/DataUtil.php +++ b/application/Espo/Core/Utils/DataUtil.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils; use InvalidArgumentException; use LogicException; +use stdClass; class DataUtil { @@ -114,9 +115,9 @@ class DataUtil } /** - * @param array|\stdClass $data + * @param array|stdClass $data * @param mixed $needle - * @return array|\stdClass + * @return array|stdClass */ public static function unsetByValue(&$data, $needle) { @@ -150,25 +151,25 @@ class DataUtil } /** - * - * @param array|\stdClass $data - * @param array|\stdClass $overrideData - * @return array|\stdClass + * @param array|stdClass $data + * @param array|stdClass $overrideData + * @return array|stdClass */ public static function merge($data, $overrideData) { $appendIdentifier = '__APPEND__'; + if ( + is_object($data) && + is_object($overrideData) && + get_object_vars($data) === [] && + get_object_vars($overrideData) === [] + ) { + return (object) []; + } + if (empty($data) && empty($overrideData)) { - if (is_object($data) || is_object($overrideData)) { - return (object) []; - } - else if (is_array($data) || is_array($overrideData)) { - return []; - } - else { - return $overrideData; - } + return []; } if (is_object($overrideData)) { @@ -188,7 +189,8 @@ class DataUtil return $data; } - else if (is_array($overrideData)) { + + if (is_array($overrideData)) { if (empty($data)) { $data = []; } @@ -203,15 +205,13 @@ class DataUtil $data[] = $item; } - } - else { - $data = $overrideData; + + return $data; } - return $data; - } - else { return $overrideData; } + + return $overrideData; } } diff --git a/application/Espo/Core/Utils/Database/Orm/Relations/Base.php b/application/Espo/Core/Utils/Database/Orm/Relations/Base.php index 3284dab403..bf5d1960e7 100644 --- a/application/Espo/Core/Utils/Database/Orm/Relations/Base.php +++ b/application/Espo/Core/Utils/Database/Orm/Relations/Base.php @@ -205,7 +205,7 @@ class Base extends \Espo\Core\Utils\Database\Orm\Base /** * @param string $allowedItemName - * @return ?array' + * @return ?array */ private function getAllowedAdditionalParam($allowedItemName) { @@ -219,20 +219,23 @@ class Base extends \Espo\Core\Utils\Database\Orm\Base $additionalParam = null; - $linkName = $this->getLinkName(); - $entityName = $this->getEntityName(); - if (isset($itemLinkParams) && isset($itemForeignLinkParams)) { if (!empty($itemLinkParams) && !is_array($itemLinkParams)) { $additionalParam = $itemLinkParams; - } else if (!empty($itemForeignLinkParams) && !is_array($itemForeignLinkParams)) { + } + else if (!empty($itemForeignLinkParams) && !is_array($itemForeignLinkParams)) { $additionalParam = $itemForeignLinkParams; - } else { + } + else { + /** @var array $itemLinkParams */ + /** @var array $itemForeignLinkParams */ $additionalParam = Util::merge($itemLinkParams, $itemForeignLinkParams); } - } else if (isset($itemLinkParams)) { + } + else if (isset($itemLinkParams)) { $additionalParam = $itemLinkParams; - } else if (isset($itemForeignLinkParams)) { + } + else if (isset($itemForeignLinkParams)) { $additionalParam = $itemForeignLinkParams; } diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.php index 8a4a0efd16..76952c737f 100644 --- a/application/Espo/Core/Utils/File/Manager.php +++ b/application/Espo/Core/Utils/File/Manager.php @@ -55,11 +55,8 @@ class Manager protected string $tmpDir = 'data/tmp'; protected const RENAME_RETRY_NUMBER = 10; - protected const RENAME_RETRY_INTERVAL = 0.1; - protected const GET_SAFE_CONTENTS_RETRY_NUMBER = 10; - protected const GET_SAFE_CONTENTS_RETRY_INTERVAL = 0.1; /** @@ -127,41 +124,49 @@ class Manager $cdir = scandir($path) ?: []; - foreach ($cdir as $key => $value) { - if (!in_array($value, [".", ".."])) { - $add = false; + foreach ($cdir as $value) { + if (in_array($value, [".", ".."])) { + continue; + } - if (is_dir($path . Util::getSeparator() . $value)) { - if ($recursively || (is_int($recursively) && $recursively!=0)) { - $nextRecursively = is_int($recursively) ? ($recursively-1) : $recursively; + $add = false; - $result[$value] = $this->getFileList( - $path . Util::getSeparator() . $value, - $nextRecursively, - $filter, - $onlyFileType - ); - } - else if (!isset($onlyFileType) || !$onlyFileType){ /*save only directories*/ - $add = true; - } + if (is_dir($path . Util::getSeparator() . $value)) { + /** @var mixed $recursively */ + if ( + !is_int($recursively) && $recursively || + is_int($recursively) && $recursively !== 0 + ) { + $nextRecursively = is_int($recursively) ? ($recursively - 1) : $recursively; + + $result[$value] = $this->getFileList( + $path . Util::getSeparator() . $value, + $nextRecursively, + $filter, + $onlyFileType + ); } - else if (!isset($onlyFileType) || $onlyFileType) { /*save only files*/ + else if (!isset($onlyFileType) || !$onlyFileType) { /* save only directories */ $add = true; } + } + else if (!isset($onlyFileType) || $onlyFileType) { /* save only files */ + $add = true; + } - if ($add) { - if (!empty($filter)) { - if (preg_match('/'.$filter.'/i', $value)) { - $result[] = $value; - } - } - else { - $result[] = $value; - } + if (!$add) { + continue; + } + + if (!empty($filter)) { + if (preg_match('/'.$filter.'/i', $value)) { + $result[] = $value; } + continue; } + + $result[] = $value; } if ($returnSingleArray) { @@ -677,17 +682,18 @@ class Manager $pathParts = pathinfo($filePath); - if (!file_exists($pathParts['dirname'])) { + /** @var string $dirname */ + $dirname = $pathParts['dirname'] ?? null; + + if (!file_exists($dirname)) { $dirPermissionOriginal = $defaultPermissions['dir']; $dirPermission = is_string($dirPermissionOriginal) ? (int) base_convert($dirPermissionOriginal, 8, 10) : $dirPermissionOriginal; - if (!$this->mkdir($pathParts['dirname'], $dirPermission)) { - throw new PermissionError( - 'Permission denied: unable to create a folder on the server ' . $pathParts['dirname'] - ); + if (!$this->mkdir($dirname, $dirPermission)) { + throw new PermissionError('Permission denied: unable to create a folder on the server ' . $dirname); } } diff --git a/application/Espo/Core/Utils/File/Permission.php b/application/Espo/Core/Utils/File/Permission.php index 97a07214cb..888502f6a0 100644 --- a/application/Espo/Core/Utils/File/Permission.php +++ b/application/Espo/Core/Utils/File/Permission.php @@ -591,7 +591,8 @@ class Permission foreach ($fileList as $fileName) { $pathInfo = pathinfo($fileName); - $dirname = $pathInfo['dirname']; + /** @var string $dirname */ + $dirname = $pathInfo['dirname'] ?? null; $currentPath = $fileName; diff --git a/application/Espo/Core/Utils/Language.php b/application/Espo/Core/Utils/Language.php index 8c60060e90..0d67f1e796 100644 --- a/application/Espo/Core/Utils/Language.php +++ b/application/Espo/Core/Utils/Language.php @@ -398,7 +398,7 @@ class Language private function getLanguageData(string $language, bool $reload = false): array { if (!$reload && isset($this->data[$language])) { - return $this->data[$language] ?? []; + return $this->data[$language]; } $cacheKey = $this->getCacheKey($language);