type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-10 18:29:14 +02:00
parent 1578ed8d8f
commit 593bf44b29
4 changed files with 70 additions and 27 deletions
+31 -5
View File
@@ -71,15 +71,18 @@ class Import
private const DEFAULT_TIME_FORMAT = 'HH:mm';
/**
* @var string[]
*/
private $attributeList = [];
private $params;
private Params $params;
private $id = null;
private ?string $id = null;
private $attachmentId = null;
private ?string $attachmentId = null;
private $entityType = null;
private ?string $entityType = null;
private $aclManager;
@@ -165,6 +168,8 @@ class Import
/**
* Set an attribute list to parse from CSV rows.
*
* @param string[] $attributeList
*/
public function setAttributeList(array $attributeList): self
{
@@ -386,6 +391,11 @@ class Import
->withCountUpdated(count($result->updatedIds));
}
/**
* @param string[] $attributeList
* @param mixed[] $row
* @throws Error
*/
private function importRow(array $attributeList, array $row): ?stdClass
{
$params = $this->params;
@@ -627,6 +637,9 @@ class Import
}
}
/**
* @param mixed $value
*/
private function processRowItem(Entity $entity, string $attribute, $value, stdClass $valueMap): void
{
$params = $this->params;
@@ -801,6 +814,7 @@ class Import
}
/**
* @param mixed $value
* @return mixed
*/
private function parseValue(Entity $entity, string $attribute, $value)
@@ -894,6 +908,7 @@ class Import
}
/**
* @param mixed $value
* @return mixed
*/
private function prepareAttributeValue(Entity $entity, string $attribute, $value)
@@ -909,7 +924,14 @@ class Import
return $value;
}
private function parsePersonName($value, string $format): array
/**
* @return array{
* firstName: ?string,
* lastName: ?string,
* middleName?: ?string,
* }
*/
private function parsePersonName(string $value, string $format): array
{
$firstName = null;
$lastName = $value;
@@ -929,6 +951,7 @@ class Import
case 'l f':
$pos = strpos($value, ' ');
if ($pos) {
$lastName = trim(substr($value, 0, $pos));
$firstName = trim(substr($value, $pos + 1));
@@ -1002,6 +1025,9 @@ class Import
];
}
/**
* @return string[]
*/
private function readCsvString(
string &$string,
string $separator = ';',
+30 -18
View File
@@ -40,39 +40,42 @@ class Params
public const ACTION_UPDATE = 'update';
private $action = null;
private ?string $action = null;
private $delimiter = null;
private ?string $delimiter = null;
private $textQualifier = null;
private ?string $textQualifier = null;
private $personNameFormat = null;
private ?string $personNameFormat = null;
private $idleMode = false;
private bool $idleMode = false;
private $manualMode = false;
private bool $manualMode = false;
private $silentMode = false;
private bool $silentMode = false;
private $headerRow = false;
private bool $headerRow = false;
private $skipDuplicateChecking = false;
private bool $skipDuplicateChecking = false;
private $startFromLastIndex = false;
private bool $startFromLastIndex = false;
/**
* @var int[]
*/
private $updateBy = [];
private $defaultValues;
private stdClass $defaultValues;
private $dateFormat = null;
private ?string $dateFormat = null;
private $timeFormat = null;
private ?string $timeFormat = null;
private $currency = null;
private ?string $currency = null;
private $timezone = null;
private ?string $timezone = null;
private $decimalMark = null;
private ?string $decimalMark = null;
private function __construct()
{
@@ -129,6 +132,9 @@ class Params
return $this->startFromLastIndex;
}
/**
* @return int[]
*/
public function getUpdateBy(): array
{
return $this->updateBy;
@@ -249,6 +255,9 @@ class Params
return $obj;
}
/**
* @param int[] $updateBy
*/
public function withUpdateBy(array $updateBy): self
{
$obj = clone $this;
@@ -258,7 +267,7 @@ class Params
}
/**
* @param stdClass|array|null $defaultValues
* @param stdClass|array<string,mixed>|null $defaultValues
*/
public function withDefaultValues($defaultValues): self
{
@@ -323,7 +332,7 @@ class Params
}
/**
* @param stdClass|array|null $params
* @param stdClass|array<string,mixed>|null $params
*/
public static function fromRaw($params): self
{
@@ -355,6 +364,9 @@ class Params
return $obj;
}
/**
* @return array<string,mixed>
*/
public function getRaw(): array
{
return [
+4 -4
View File
@@ -33,13 +33,13 @@ use stdClass;
class Result
{
private $id = null;
private ?string $id = null;
private $countCreated = 0;
private int $countCreated = 0;
private $countUpdated = 0;
private int $countUpdated = 0;
private $manualMode = false;
private bool $manualMode = false;
public function getId(): ?string
{
@@ -68,6 +68,11 @@ class Service
$this->acl = $acl;
}
/**
* @param string[] $attributeList
* @param string $attachmentId
* @throws Forbidden
*/
public function import(
string $entityType,
array $attributeList,