From a164c33829a5a64192e0f950c192858bb3451024 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 13 Mar 2022 14:19:38 +0200 Subject: [PATCH] type fixes --- application/Espo/Tools/Pdf/ContentsString.php | 8 +++++++- application/Espo/Tools/Pdf/Data/DataLoaderManager.php | 4 ++-- application/Espo/Tools/Pdf/PrinterController.php | 4 ++-- application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php | 3 ++- application/Espo/Tools/Pdf/Tcpdf/Tcpdf.php | 4 +++- application/Espo/Tools/Pdf/Tcpdf/TcpdfContents.php | 6 ++++++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/application/Espo/Tools/Pdf/ContentsString.php b/application/Espo/Tools/Pdf/ContentsString.php index 2a8d90a6a4..cd19ea759e 100644 --- a/application/Espo/Tools/Pdf/ContentsString.php +++ b/application/Espo/Tools/Pdf/ContentsString.php @@ -33,9 +33,11 @@ use Psr\Http\Message\StreamInterface; use GuzzleHttp\Psr7\Stream; +use RuntimeException; + class ContentsString implements Contents { - private $contents; + private string $contents; private function __construct(string $contents) { @@ -46,6 +48,10 @@ class ContentsString implements Contents { $resource = fopen('php://temp', 'r+'); + if ($resource === false) { + throw new RuntimeException("Could not open temp."); + } + fwrite($resource, $this->getString()); rewind($resource); diff --git a/application/Espo/Tools/Pdf/Data/DataLoaderManager.php b/application/Espo/Tools/Pdf/Data/DataLoaderManager.php index 291cb29d02..befb38a72b 100644 --- a/application/Espo/Tools/Pdf/Data/DataLoaderManager.php +++ b/application/Espo/Tools/Pdf/Data/DataLoaderManager.php @@ -59,7 +59,7 @@ class DataLoaderManager $data = Data::create(); } - /** @var class-string[] */ + /** @var class-string[] */ $classNameList = $this->metadata->get(['pdfDefs', $entity->getEntityType(), 'dataLoaderClassNameList']) ?? []; foreach ($classNameList as $className) { @@ -74,7 +74,7 @@ class DataLoaderManager } /** - * @param class-string $className + * @param class-string $className */ private function createLoader(string $className): DataLoader { diff --git a/application/Espo/Tools/Pdf/PrinterController.php b/application/Espo/Tools/Pdf/PrinterController.php index 11e7ca820b..1e90bd188d 100644 --- a/application/Espo/Tools/Pdf/PrinterController.php +++ b/application/Espo/Tools/Pdf/PrinterController.php @@ -84,7 +84,7 @@ class PrinterController private function createEntityPrinter(): EntityPrinter { - /** @var ?class-string */ + /** @var ?class-string */ $className = $this->metadata ->get(['app', 'pdfEngines', $this->engine, 'implementationClassNameMap', 'entity']) ?? null; @@ -97,7 +97,7 @@ class PrinterController private function createCollectionPrinter(): CollectionPrinter { - /** @var ?class-string */ + /** @var ?class-string */ $className = $this->metadata ->get(['app', 'pdfEngines', $this->engine, 'implementationClassNameMap', 'collection']) ?? null; diff --git a/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php b/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php index da80b9f880..ee3d98cada 100644 --- a/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php +++ b/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php @@ -30,6 +30,7 @@ namespace Espo\Tools\Pdf\Tcpdf; use Espo\Core\Utils\Config; +use Espo\Core\Utils\Json; use Espo\Core\Htmlizer\TemplateRendererFactory; use Espo\Core\Htmlizer\TemplateRenderer; @@ -225,7 +226,7 @@ class EntityProcessor ]; } - $paramsString = urlencode(json_encode($params)); + $paramsString = urlencode(Json::encode($params)); return ""; } diff --git a/application/Espo/Tools/Pdf/Tcpdf/Tcpdf.php b/application/Espo/Tools/Pdf/Tcpdf/Tcpdf.php index 0ab077805c..994fc6458f 100644 --- a/application/Espo/Tools/Pdf/Tcpdf/Tcpdf.php +++ b/application/Espo/Tools/Pdf/Tcpdf/Tcpdf.php @@ -35,6 +35,8 @@ use Espo\Core\Utils\Util; use TCPDF_STATIC; +use Espo\Core\Utils\Json; + class Tcpdf extends TcpdfOriginal { /** @@ -64,7 +66,7 @@ class Tcpdf extends TcpdfOriginal public function serializeTCPDFtagParameters($data) /** @phpstan-ignore-line */ { - return urlencode(json_encode($data)); + return urlencode(Json::encode($data)); } protected function unserializeTCPDFtagParameters($data) /** @phpstan-ignore-line */ diff --git a/application/Espo/Tools/Pdf/Tcpdf/TcpdfContents.php b/application/Espo/Tools/Pdf/Tcpdf/TcpdfContents.php index 45876a1e7f..81a796249f 100644 --- a/application/Espo/Tools/Pdf/Tcpdf/TcpdfContents.php +++ b/application/Espo/Tools/Pdf/Tcpdf/TcpdfContents.php @@ -36,6 +36,8 @@ use Psr\Http\Message\StreamInterface; use GuzzleHttp\Psr7\Stream; +use RuntimeException; + class TcpdfContents implements Contents { private $pdf; @@ -49,6 +51,10 @@ class TcpdfContents implements Contents { $resource = fopen('php://temp', 'r+'); + if ($resource === false) { + throw new RuntimeException("Could not open temp."); + } + fwrite($resource, $this->getString()); rewind($resource);