diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php b/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php index b073edc91..61c3ace6c 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php @@ -11,8 +11,11 @@ final class ArrayContentDetector { + private readonly int $uniqueValuesCount; + public function __construct(private readonly Types $uniqueKeysType, private readonly Types $uniqueValuesType) { + $this->uniqueValuesCount = $this->uniqueValuesType->without(ArrayType::empty(), new NullType())->count(); } public function firstKeyType() : ?ScalarType @@ -37,21 +40,20 @@ public function isList() : bool return false; } - return 1 === $this->uniqueValuesType->without(ArrayType::empty(), new NullType())->count(); + return 1 === $this->uniqueValuesCount; } public function isMap() : bool { - if (1 === $this->uniqueValuesType->without(ArrayType::empty(), new NullType())->count()) { - if ($this->isList()) { - return false; - } + if (!$this->firstKeyType()?->isValidArrayKey()) { + return false; + } - if (!$this->firstKeyType()?->isValidArrayKey()) { - return false; + if (1 === $this->uniqueValuesCount) { + /** @psalm-suppress PossiblyNullReference */ + if (!$this->firstKeyType()->isInteger()) { + return 1 === $this->uniqueKeysType->count(); } - - return 1 === $this->uniqueKeysType->count(); } return false; @@ -65,6 +67,6 @@ public function isStructure() : bool return $this->firstKeyType()?->isString() && 1 === $this->uniqueKeysType->count() - && 0 !== $this->uniqueValuesType->without(ArrayType::empty(), new NullType())->count(); + && 0 !== $this->uniqueValuesCount; } }