From 20a0ed41335b5b558cf0804f931a5fd35f9a0a93 Mon Sep 17 00:00:00 2001 From: Yurii Date: Sun, 4 Jan 2026 09:44:24 +0200 Subject: [PATCH] type fixes --- .../Espo/Core/Authentication/Oidc/Login.php | 1 + .../Espo/Core/Console/Commands/Upgrade.php | 15 ++++++++++++--- .../ExternalAccount/Clients/OAuth2Abstract.php | 6 +++--- .../Espo/Core/ExternalAccount/OAuth2/Client.php | 14 ++++++++------ application/Espo/Core/Formula/Processor.php | 2 +- application/Espo/Core/Select/SearchParams.php | 1 - .../Espo/Core/Utils/Database/Orm/Converter.php | 1 + application/Espo/Core/Utils/File/Permission.php | 3 ++- application/Espo/Core/Utils/Util.php | 6 +++--- application/Espo/EntryPoints/Image.php | 2 +- .../Espo/ORM/QueryComposer/BaseQueryComposer.php | 2 +- .../Espo/Tools/Attachment/UploadUrlService.php | 5 +++-- application/Espo/Tools/WorkingTime/Extractor.php | 3 ++- 13 files changed, 38 insertions(+), 23 deletions(-) diff --git a/application/Espo/Core/Authentication/Oidc/Login.php b/application/Espo/Core/Authentication/Oidc/Login.php index 3a9ec90773..8535f59164 100644 --- a/application/Espo/Core/Authentication/Oidc/Login.php +++ b/application/Espo/Core/Authentication/Oidc/Login.php @@ -204,6 +204,7 @@ class Login implements LoginInterface } /** + * @param non-empty-string $endpoint * @return array{?string, ?Result, ?string} */ private function requestToken( diff --git a/application/Espo/Core/Console/Commands/Upgrade.php b/application/Espo/Core/Console/Commands/Upgrade.php index 0a680f49a5..a0af48f625 100644 --- a/application/Espo/Core/Console/Commands/Upgrade.php +++ b/application/Espo/Core/Console/Commands/Upgrade.php @@ -463,6 +463,9 @@ class Upgrade implements Command return $data; } + /** + * @param non-empty-string $url + */ private function downloadFile(string $url): ?string { $localFilePath = 'data/upload/upgrades/' . Util::generateId() . '.zip'; @@ -472,8 +475,16 @@ class Upgrade implements Command if (is_file($url)) { copy($url, $localFilePath); } else { + $fp = fopen($localFilePath, 'w'); + + if ($fp === false) { + echo "\nCould not open local file for writing.\n"; + + return null; + } + $options = [ - CURLOPT_FILE => fopen($localFilePath, 'w'), + CURLOPT_FILE => $fp, CURLOPT_TIMEOUT => 3600, CURLOPT_URL => $url, ]; @@ -481,9 +492,7 @@ class Upgrade implements Command $ch = curl_init(); curl_setopt_array($ch, $options); - curl_exec($ch); - curl_close($ch); } diff --git a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php index 5f294875e7..819ddfd4fc 100644 --- a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php +++ b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php @@ -258,7 +258,7 @@ abstract class OAuth2Abstract implements IClient } /** - * @return string + * @return non-empty-string */ protected function getPingUrl() { @@ -404,9 +404,9 @@ abstract class OAuth2Abstract implements IClient } /** - * @param string $url + * @param non-empty-string $url * @param array|string|null $params - * @param string $httpMethod + * @param non-empty-string $httpMethod * @param ?string $contentType * @param bool $allowRenew * @return mixed diff --git a/application/Espo/Core/ExternalAccount/OAuth2/Client.php b/application/Espo/Core/ExternalAccount/OAuth2/Client.php index 2ae5c90a4b..bd7ab9b7ef 100644 --- a/application/Espo/Core/ExternalAccount/OAuth2/Client.php +++ b/application/Espo/Core/ExternalAccount/OAuth2/Client.php @@ -213,9 +213,9 @@ class Client } /** - * @param string $url + * @param non-empty-string $url * @param array|string|null $params - * @param string $httpMethod + * @param non-empty-string $httpMethod * @param array $httpHeaders * @return array{ * result: array|string, @@ -262,9 +262,9 @@ class Client } /** - * @param string $url + * @param non-empty-string $url * @param array|string|null $params - * @param string $httpMethod + * @param non-empty-string $httpMethod * @param array $httpHeaders * @return array{ * result: array|string, @@ -302,7 +302,9 @@ class Client $postFields = $params; } - $curlOptions[CURLOPT_POSTFIELDS] = $postFields; + if ($postFields !== '' && $postFields !== null) { + $curlOptions[CURLOPT_POSTFIELDS] = $postFields; + } break; @@ -403,7 +405,7 @@ class Client } /** - * @param string $url + * @param non-empty-string $url * @param string $grantType * @param array{ * client_id?: string, diff --git a/application/Espo/Core/Formula/Processor.php b/application/Espo/Core/Formula/Processor.php index 8bbe95a03b..3577f8be83 100644 --- a/application/Espo/Core/Formula/Processor.php +++ b/application/Espo/Core/Formula/Processor.php @@ -177,7 +177,7 @@ class Processor $evaluatedArguments = new EvaluatedArgumentList($rawEvaluatedArguments); if ($function instanceof FuncVariablesAware) { - $variables = new Variables($this->variables ?? (object) []); + $variables = new Variables($this->variables); return $function->process($evaluatedArguments, $variables); } diff --git a/application/Espo/Core/Select/SearchParams.php b/application/Espo/Core/Select/SearchParams.php index 45fb99221e..4f1ee72333 100644 --- a/application/Espo/Core/Select/SearchParams.php +++ b/application/Espo/Core/Select/SearchParams.php @@ -244,7 +244,6 @@ class SearchParams * With a primary filter. * * @param string|null $primaryFilter - * @return $this */ public function withPrimaryFilter(?string $primaryFilter): self { diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index a3db5f6aa4..c999dedea8 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -135,6 +135,7 @@ class Converter $this->entityDefs = $this->metadata->get('entityDefs'); } + /** @var array */ return $this->entityDefs; } diff --git a/application/Espo/Core/Utils/File/Permission.php b/application/Espo/Core/Utils/File/Permission.php index 5a503207a8..0817d0c50d 100644 --- a/application/Espo/Core/Utils/File/Permission.php +++ b/application/Espo/Core/Utils/File/Permission.php @@ -237,8 +237,9 @@ class Permission $pKey = $rule[$count]; } + /** @phpstan-ignore-next-line empty.variable */ if (!empty($pKey)) { - $permission[$pKey]= $val; + $permission[$pKey] = $val; } $count++; diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index a7a4fbbf65..c19aa73c02 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -890,14 +890,14 @@ class Util /** * Sanitize HTML code. * - * @param string|string[] $text A source. + * @param string|array $text A source. * @param string[] $permittedHtmlTags Allows only HTML tags without parameters like

,
, etc. - * @return string|string[] + * @return string|array */ public static function sanitizeHtml($text, $permittedHtmlTags = ['p', 'br', 'b', 'strong', 'pre']) { if (is_array($text)) { - foreach ($text as $key => &$value) { + foreach ($text as &$value) { $value = self::sanitizeHtml($value, $permittedHtmlTags); } diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index 60369984ce..fc4b99713f 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -391,7 +391,7 @@ class Image implements EntryPoint $orientation = $this->getOrientation($filePath); if ($orientation) { - $angle = [0, 0, 0, 180, 0, 0, -90, 0, 90][$orientation]; + $angle = [0, 0, 0, 180, 0, 0, -90, 0, 90][$orientation] ?? 0; $targetImage = imagerotate($targetImage, $angle, 0) ?: $targetImage; } diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index b27fa61466..5ea05fd154 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -2053,7 +2053,7 @@ abstract class BaseQueryComposer implements QueryComposer /** * @param string[]|array $select - * @param string[] $explicitJoins + * @param string[]|array[] $explicitJoins * @param array $params */ protected function getBelongsToJoinsPart( diff --git a/application/Espo/Tools/Attachment/UploadUrlService.php b/application/Espo/Tools/Attachment/UploadUrlService.php index ae7b4ec18a..90de15bd01 100644 --- a/application/Espo/Tools/Attachment/UploadUrlService.php +++ b/application/Espo/Tools/Attachment/UploadUrlService.php @@ -66,6 +66,7 @@ class UploadUrlService /** * Upload an image from and URL and store as attachment. * + * @param non-empty-string $url * @throws Forbidden * @throws Error */ @@ -111,7 +112,7 @@ class UploadUrlService } /** - * @param string $url + * @param non-empty-string $url * @return ?array{string, string} A type and contents. */ private function getImageDataByUrl(string $url): ?array @@ -127,7 +128,7 @@ class UploadUrlService $httpHeaders = []; $httpHeaders[] = 'Expect:'; - $opts[\CURLOPT_URL] = $url; + $opts[\CURLOPT_URL] = $url; $opts[\CURLOPT_HTTPHEADER] = $httpHeaders; $opts[\CURLOPT_CONNECTTIMEOUT] = 10; $opts[\CURLOPT_TIMEOUT] = 10; diff --git a/application/Espo/Tools/WorkingTime/Extractor.php b/application/Espo/Tools/WorkingTime/Extractor.php index d9991b3e8f..1801976879 100644 --- a/application/Espo/Tools/WorkingTime/Extractor.php +++ b/application/Espo/Tools/WorkingTime/Extractor.php @@ -36,6 +36,7 @@ use Espo\Tools\WorkingTime\Calendar\HavingRanges; use Espo\Core\Field\DateTime; use Espo\Core\Field\Date; +use LogicException; class Extractor { @@ -108,7 +109,7 @@ class Extractor } for ($i = count($list) - 1; $i >= 0; $i--) { - $pair = $list[$i]; + $pair = $list[$i] ?? throw new LogicException(); if ($to->isGreaterThan($pair[1]) || $to->isEqualTo($pair[1])) { break;