diff --git a/application/Espo/Tools/Export/Export.php b/application/Espo/Tools/Export/Export.php index 5e0b9f42ee..3976e9bf88 100644 --- a/application/Espo/Tools/Export/Export.php +++ b/application/Espo/Tools/Export/Export.php @@ -64,12 +64,12 @@ class Export /** * @var ?Params */ - private $params; + private ?Params $params = null; /** - * @phpstan-var (Collection&iterable)|null $collection + * @var ?Collection */ - private $collection = null; + private ?Collection $collection = null; private $processorFactory; @@ -123,7 +123,7 @@ class Export } /** - * @phpstan-param Collection&iterable $collection + * @param Collection $collection */ public function setCollection(Collection $collection): self { @@ -237,6 +237,9 @@ class Export return new Result($attachment->getId()); } + /** + * @return mixed + */ protected function getAttributeFromEntity(Entity $entity, string $attribute) { $methodName = 'getAttribute' . ucfirst($attribute). 'FromEntity'; @@ -351,7 +354,7 @@ class Export } /** - * @phpstan-return Collection&iterable + * @return Collection */ private function getCollection(Params $params): Collection { @@ -375,7 +378,7 @@ class Export $query = $builder->build(); - /** @phpstan-var Collection&iterable */ + /** @var Collection */ return $this->entityManager ->getRDBRepository($entityType) ->clone($query) @@ -383,11 +386,14 @@ class Export ->find(); } + /** + * @return string[] + */ private function getAttributeList(Params $params): array { - $list = []; + $list = []; - $entityType = $params->getEntityType(); + $entityType = $params->getEntityType(); $entityDefs = $this->entityManager ->getDefs() @@ -430,6 +436,10 @@ class Export return $list; } + /** + * @return string[] + * @throws RuntimeException + */ private function getAttributeListFromFieldList(Params $params): array { $entityType = $params->getEntityType(); @@ -452,6 +462,9 @@ class Export return $attributeList; } + /** + * @return ?string[] + */ private function getFieldList(Params $params, Processor $processor): ?array { $entityDefs = $this->entityManager diff --git a/application/Espo/Tools/Export/Params.php b/application/Espo/Tools/Export/Params.php index de0041a584..3df67e68d0 100644 --- a/application/Espo/Tools/Export/Params.php +++ b/application/Espo/Tools/Export/Params.php @@ -38,27 +38,37 @@ use RuntimeException; class Params { - private $entityType; + private string $entityType; + /** + * @var ?string[] + */ private $attributeList = null; + /** + * @var ?string[] + */ private $fieldList = null; - private $fileName = null; + private ?string $fileName = null; - private $format = null; + private ?string $format = null; - private $name = null; + private ?string $name = null; - private $searchParams = null; + private ?SearchParams $searchParams = null; - private $applyAccessControl = true; + private bool $applyAccessControl = true; public function __construct(string $entityType) { $this->entityType = $entityType; } + /** + * @param array $params + * @throws RuntimeException + */ public static function fromRaw(array $params): self { $entityType = $params['entityType'] ?? null; @@ -172,6 +182,9 @@ class Params return $obj; } + /** + * @param ?string[] $fieldList + */ public function withFieldList(?array $fieldList): self { $obj = clone $this; @@ -181,6 +194,9 @@ class Params return $obj; } + /** + * @param ?string[] $attributeList + */ public function withAttributeList(?array $attributeList): self { $obj = clone $this; @@ -245,6 +261,8 @@ class Params /** * Get attributes to be exported. + * + * @return ?string[] */ public function getAttributeList(): ?array { @@ -253,6 +271,8 @@ class Params /** * Get fields to be exported. + * + * @return ?string[] */ public function getFieldList(): ?array { diff --git a/application/Espo/Tools/Export/Processor/Data.php b/application/Espo/Tools/Export/Processor/Data.php index 3135f74bb6..9dcdfaeef0 100644 --- a/application/Espo/Tools/Export/Processor/Data.php +++ b/application/Espo/Tools/Export/Processor/Data.php @@ -31,13 +31,23 @@ namespace Espo\Tools\Export\Processor; class Data { + /** + * @var resource + */ private $resource; + /** + * @param resource $resource + */ public function __construct($resource) { $this->resource = $resource; } + /** + * + * @return ?mixed[] + */ public function readRow(): ?array { $line = fgets($this->resource); diff --git a/application/Espo/Tools/Export/Processor/Params.php b/application/Espo/Tools/Export/Processor/Params.php index 84398a64a0..f55e534725 100644 --- a/application/Espo/Tools/Export/Processor/Params.php +++ b/application/Espo/Tools/Export/Processor/Params.php @@ -31,16 +31,26 @@ namespace Espo\Tools\Export\Processor; class Params { - private $fileName; + private string $fileName; - private $attributeList = null; + /** + * @var string[] + */ + private $attributeList; + /** + * @var ?string[] + */ private $fieldList = null; - private $name = null; + private ?string $name = null; - private $entityType = null; + private ?string $entityType = null; + /** + * @param string[] $attributeList + * @param ?string[] $fieldList + */ public function __construct(string $fileName, array $attributeList, ?array $fieldList) { $this->fileName = $fileName; @@ -71,11 +81,17 @@ class Params return $this->fileName; } + /** + * @return string[] + */ public function getAttributeList(): array { return $this->attributeList; } + /** + * @return ?string[] + */ public function getFieldList(): ?array { return $this->fieldList; diff --git a/application/Espo/Tools/Export/ProcessorFactory.php b/application/Espo/Tools/Export/ProcessorFactory.php index 5e84bb3559..e5336621fd 100644 --- a/application/Espo/Tools/Export/ProcessorFactory.php +++ b/application/Espo/Tools/Export/ProcessorFactory.php @@ -38,9 +38,9 @@ use LogicException; class ProcessorFactory { - private $injectableFactory; + private InjectableFactory $injectableFactory; - private $metadata; + private Metadata $metadata; public function __construct(InjectableFactory $injectableFactory, Metadata $metadata) { @@ -54,6 +54,7 @@ class ProcessorFactory throw new LogicException("Not supported export format '{$format}'."); } + /** @var ?class-string */ $className = $this->metadata->get(['app', 'export', 'processorClassNameMap', $format]); if (!$className) { diff --git a/application/Espo/Tools/Export/Processors/Csv.php b/application/Espo/Tools/Export/Processors/Csv.php index 6b8bdec10f..2f1481f814 100644 --- a/application/Espo/Tools/Export/Processors/Csv.php +++ b/application/Espo/Tools/Export/Processors/Csv.php @@ -92,6 +92,10 @@ class Csv implements Processor return new Stream($fp); } + /** + * @param mixed[] $row + * @return mixed[] + */ protected function prepareRow(array $row): array { $preparedRow = []; @@ -107,6 +111,9 @@ class Csv implements Processor return $preparedRow; } + /** + * @param string[] $fieldList + */ public function loadAdditionalFields(Entity $entity, array $fieldList): void { if (!$entity instanceof CoreEntity) { diff --git a/application/Espo/Tools/Export/Processors/Xlsx.php b/application/Espo/Tools/Export/Processors/Xlsx.php index a98ad15616..0b440e1aec 100644 --- a/application/Espo/Tools/Export/Processors/Xlsx.php +++ b/application/Espo/Tools/Export/Processors/Xlsx.php @@ -357,6 +357,12 @@ class Xlsx implements Processor return $stream; } + /** + * @param mixed[] $row + * @param string[] $fieldList + * @param string[] $azRange + * @param array $typesCache + */ private function processRow( string $entityType, array $row, @@ -745,6 +751,9 @@ class Xlsx implements Processor return '[$'.$currencySymbol.'-409]#,##0.00;-[$'.$currencySymbol.'-409]#,##0.00'; } + /** + * @param string[] $fieldList + */ public function loadAdditionalFields(Entity $entity, array $fieldList): void { if (!$entity instanceof CoreEntity) { @@ -789,6 +798,10 @@ class Xlsx implements Processor } } + /** + * @param string[] $fieldList + * @return string[] + */ public function filterFieldList(string $entityType, array $fieldList, bool $exportAllFields): array { if ($exportAllFields) { @@ -804,6 +817,10 @@ class Xlsx implements Processor return array_values($fieldList); } + /** + * @param string[] $attributeList + * @param string[] $fieldList + */ public function addAdditionalAttributes(string $entityType, array &$attributeList, array $fieldList): void { $linkList = []; @@ -886,6 +903,10 @@ class Xlsx implements Processor return $value; } + /** + * @param mixed[] $row + * @return mixed[] + */ private function sanitizeRow(array $row): array { return array_map(