diff --git a/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/AvroLoader.php b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/AvroLoader.php index 93194095b..1b57a1415 100644 --- a/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/AvroLoader.php +++ b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/AvroLoader.php @@ -10,7 +10,8 @@ use Flow\ETL\FlowContext; use Flow\ETL\Loader; use Flow\ETL\Loader\Closure; -use Flow\ETL\PHP\Type\ObjectType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\Row; use Flow\ETL\Row\Entry\DateTimeEntry; use Flow\ETL\Row\Schema; @@ -98,10 +99,11 @@ public function load(Rows $rows, FlowContext $context) : void private function listEntryToValues(Row\Entry\ListEntry $entry) : array { + /** @var ListElement $listType */ $listType = $entry->definition()->metadata()->get(Schema\FlowMetadata::METADATA_LIST_ENTRY_TYPE); - if ($listType instanceof ObjectType) { - if (\is_a($listType->class, Row\Entry\Type\Uuid::class, true)) { + if ($listType->value() instanceof ObjectType) { + if (\is_a($listType->value()->class, Row\Entry\Type\Uuid::class, true)) { /** @var array $data */ $data = []; @@ -112,7 +114,7 @@ private function listEntryToValues(Row\Entry\ListEntry $entry) : array return $data; } - if (\is_a($listType->class, \DateTimeInterface::class, true)) { + if (\is_a($listType->value()->class, \DateTimeInterface::class, true)) { /** @var array $data */ $data = []; diff --git a/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/SchemaConverter.php b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/SchemaConverter.php index b8d5b7581..03d328504 100644 --- a/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/SchemaConverter.php +++ b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/SchemaConverter.php @@ -5,8 +5,9 @@ namespace Flow\ETL\Adapter\Avro\FlixTech; use Flow\ETL\Exception\RuntimeException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Native\ObjectType; +use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry; use Flow\ETL\Row\Entry\ArrayEntry; use Flow\ETL\Row\Entry\BooleanEntry; @@ -55,10 +56,11 @@ private function convert(Definition $definition) : array $type = $this->typeFromDefinition($definition); if ($type === ListEntry::class) { + /** @var ListElement $listType */ $listType = $definition->metadata()->get(Schema\FlowMetadata::METADATA_LIST_ENTRY_TYPE); - if ($listType instanceof ScalarType) { - return match ($listType) { + if ($listType->value() instanceof ScalarType) { + return match ($listType->value()) { ScalarType::string => ['name' => $definition->entry()->name(), 'type' => ['type' => 'array', 'items' => \AvroSchema::STRING_TYPE]], ScalarType::integer => ['name' => $definition->entry()->name(), 'type' => ['type' => 'array', 'items' => \AvroSchema::INT_TYPE]], ScalarType::float => ['name' => $definition->entry()->name(), 'type' => ['type' => 'array', 'items' => \AvroSchema::FLOAT_TYPE]], @@ -66,12 +68,12 @@ private function convert(Definition $definition) : array }; } - if ($listType instanceof ObjectType) { - if (\is_a($listType->class, \DateTimeInterface::class, true)) { + if ($listType->value() instanceof ObjectType) { + if (\is_a($listType->value()->class, \DateTimeInterface::class, true)) { return ['name' => $definition->entry()->name(), 'type' => ['type' => 'array', 'items' => 'long', \AvroSchema::LOGICAL_TYPE_ATTR => 'timestamp-micros']]; } - throw new RuntimeException("List of {$listType->class} is not supported yet supported."); + throw new RuntimeException("List of {$listType->toString()} is not supported yet supported."); } } diff --git a/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php index 35d52ed43..7c8de4931 100644 --- a/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php +++ b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php @@ -3,8 +3,9 @@ namespace Flow\ETL\Adapter\Parquet; use Flow\ETL\Exception\RuntimeException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Native\ObjectType; +use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry; use Flow\ETL\Row\Entry\ArrayEntry; use Flow\ETL\Row\Entry\BooleanEntry; @@ -25,7 +26,7 @@ use Flow\Parquet\ParquetFile\Schema as ParquetSchema; use Flow\Parquet\ParquetFile\Schema\Column; use Flow\Parquet\ParquetFile\Schema\FlatColumn; -use Flow\Parquet\ParquetFile\Schema\ListElement; +use Flow\Parquet\ParquetFile\Schema\ListElement as ParquetListElement; use Flow\Parquet\ParquetFile\Schema\NestedColumn; final class SchemaConverter @@ -64,26 +65,27 @@ private function convertEntry(Definition $definition) : Column private function listEntryToParquet(Definition $definition) : NestedColumn { + /** @var ListElement $listType */ $listType = $definition->metadata()->get(FlowMetadata::METADATA_LIST_ENTRY_TYPE); - if ($listType instanceof ScalarType) { + if ($listType->value() instanceof ScalarType) { return NestedColumn::list( $definition->entry()->name(), - match ($listType) { - ScalarType::string => ListElement::string(), - ScalarType::integer => ListElement::int64(), - ScalarType::float => ListElement::float(), - ScalarType::boolean => ListElement::boolean() + match ($listType->value()) { + ScalarType::string => ParquetListElement::string(), + ScalarType::integer => ParquetListElement::int64(), + ScalarType::float => ParquetListElement::float(), + ScalarType::boolean => ParquetListElement::boolean() } ); } - if ($listType instanceof ObjectType) { - if (\is_a($listType->class, \DateTimeInterface::class, true)) { - return NestedColumn::list($definition->entry()->name(), ListElement::datetime()); + if ($listType->value() instanceof ObjectType) { + if (\is_a($listType->value()->class, \DateTimeInterface::class, true)) { + return NestedColumn::list($definition->entry()->name(), ParquetListElement::datetime()); } - throw new RuntimeException("List of {$listType->class} is not supported yet supported."); + throw new RuntimeException("List of {$listType->toString()} is not supported yet supported."); } /** @phpstan-ignore-next-line */ diff --git a/src/core/etl/src/Flow/ETL/DSL/Entry.php b/src/core/etl/src/Flow/ETL/DSL/Entry.php index ab3ade84f..f70fb55d2 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Entry.php +++ b/src/core/etl/src/Flow/ETL/DSL/Entry.php @@ -5,8 +5,7 @@ namespace Flow\ETL\DSL; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\Row\Entries; use Flow\ETL\Row\Entry as RowEntry; use Flow\ETL\Row\Entry\Type\Uuid; @@ -158,7 +157,7 @@ final public static function json_string(string $name, string $data) : RowEntry */ final public static function list_of_boolean(string $name, array $value) : RowEntry { - return new RowEntry\ListEntry($name, ScalarType::boolean, $value); + return new RowEntry\ListEntry($name, ListElement::boolean(), $value); } /** @@ -170,7 +169,7 @@ final public static function list_of_boolean(string $name, array $value) : RowEn */ final public static function list_of_datetime(string $name, array $value) : RowEntry { - return new RowEntry\ListEntry($name, new ObjectType(\DateTimeInterface::class), $value); + return new RowEntry\ListEntry($name, ListElement::object(\DateTimeInterface::class), $value); } /** @@ -182,7 +181,7 @@ final public static function list_of_datetime(string $name, array $value) : RowE */ final public static function list_of_float(string $name, array $value) : RowEntry { - return new RowEntry\ListEntry($name, ScalarType::float, $value); + return new RowEntry\ListEntry($name, ListElement::float(), $value); } /** @@ -194,7 +193,7 @@ final public static function list_of_float(string $name, array $value) : RowEntr */ final public static function list_of_int(string $name, array $value) : RowEntry { - return new RowEntry\ListEntry($name, ScalarType::integer, $value); + return new RowEntry\ListEntry($name, ListElement::integer(), $value); } /** @@ -207,7 +206,7 @@ final public static function list_of_int(string $name, array $value) : RowEntry */ final public static function list_of_objects(string $name, string $class, array $value) : RowEntry { - return new RowEntry\ListEntry($name, new ObjectType($class), $value); + return new RowEntry\ListEntry($name, ListElement::object($class), $value); } /** @@ -219,7 +218,7 @@ final public static function list_of_objects(string $name, string $class, array */ final public static function list_of_string(string $name, array $value) : RowEntry { - return new RowEntry\ListEntry($name, ScalarType::string, $value); + return new RowEntry\ListEntry($name, ListElement::string(), $value); } /** diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php new file mode 100644 index 000000000..a9f6004df --- /dev/null +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php @@ -0,0 +1,66 @@ +value->isEqual($value); + } + + public function isValid(mixed $value) : bool + { + return $this->value->isValid($value); + } + + public function toString() : string + { + return $this->value->toString(); + } + + public function value() : ScalarType|ObjectType + { + return $this->value; + } +} diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/ListType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/ListType.php new file mode 100644 index 000000000..18182701b --- /dev/null +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/ListType.php @@ -0,0 +1,65 @@ + + */ +final class ListType implements Serializable, Type +{ + public function __construct(private readonly List\ListElement $element) + { + } + + public function __serialize() : array + { + return ['element' => $this->element]; + } + + public function __unserialize(array $data) : void + { + $this->element = $data['element']; + } + + public function element() : ListElement + { + return $this->element; + } + + public function isEqual(Type $type) : bool + { + if (!$type instanceof self) { + return false; + } + + return $this->element->toString() === $type->element()->toString(); + } + + public function isValid(mixed $value) : bool + { + if (!\is_array($value)) { + return false; + } + + if ([] !== $value && !\array_is_list($value)) { + return false; + } + + foreach ($value as $item) { + if (!$this->element->isValid($item)) { + return false; + } + } + + return true; + } + + public function toString() : string + { + return $this->element->toString(); + } +} diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/ObjectType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php similarity index 71% rename from src/core/etl/src/Flow/ETL/PHP/Type/ObjectType.php rename to src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php index c67adfcb8..9d522dbcf 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/ObjectType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace Flow\ETL\PHP\Type; +namespace Flow\ETL\PHP\Type\Native; use Flow\ETL\Exception\InvalidArgumentException; +use Flow\ETL\PHP\Type\Type; final class ObjectType implements Type { @@ -13,21 +14,11 @@ final class ObjectType implements Type */ public function __construct(public readonly string $class) { - if (!\class_exists($class) && !\interface_exists($this->class)) { + if (!\class_exists($class) && !\interface_exists($class)) { throw new InvalidArgumentException("Class {$class} not found"); } } - /** - * @psalm-suppress MoreSpecificImplementedParamType - * - * @param class-string $value - */ - public static function fromString(string $value) : self - { - return new self($value); - } - /** * @param class-string $class */ diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/ScalarType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ScalarType.php similarity index 95% rename from src/core/etl/src/Flow/ETL/PHP/Type/ScalarType.php rename to src/core/etl/src/Flow/ETL/PHP/Type/Native/ScalarType.php index c2223a819..ca203cc7c 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/ScalarType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ScalarType.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace Flow\ETL\PHP\Type; +namespace Flow\ETL\PHP\Type\Native; use Flow\ETL\Exception\InvalidArgumentException; +use Flow\ETL\PHP\Type\Type; enum ScalarType : string implements Type { diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Type.php b/src/core/etl/src/Flow/ETL/PHP/Type/Type.php index 9921ef1d4..98ace3d8e 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Type.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Type.php @@ -6,8 +6,6 @@ interface Type { - public static function fromString(string $value) : self; - public function isEqual(self $type) : bool; public function isValid(mixed $value) : bool; diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/ListEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/ListEntry.php index 86931eab6..fcb2dd8b2 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/ListEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/ListEntry.php @@ -6,7 +6,8 @@ use Flow\ArrayComparison\ArrayComparison; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\Type; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\Row\Entry; use Flow\ETL\Row\Reference; use Flow\ETL\Row\Schema\Definition; @@ -16,36 +17,32 @@ /** * @template T * - * @implements Entry, array{name: string, type: Type, value: array}> + * @implements Entry, array{name: string, type: ListType, value: array}> */ final class ListEntry implements Entry, TypedCollection { use EntryRef; + private readonly ListType $type; + /** - * @param string $name - * @param Type $type * @param array $value * * @throws InvalidArgumentException */ public function __construct( private readonly string $name, - private readonly Type $type, + ListElement $element, private readonly array $value ) { if ('' === $name) { throw InvalidArgumentException::because('Entry name cannot be empty'); } - if ([] !== $value && !\array_is_list($value)) { - throw new InvalidArgumentException('Expected list of ' . $type->toString() . ' got array with not sequential integer indexes'); - } + $this->type = new ListType($element); - foreach ($value as $item) { - if (!$type->isValid($item)) { - throw new InvalidArgumentException('Expected list of ' . $type->toString() . ' got different types.'); - } + if (!$this->type->isValid($value)) { + throw InvalidArgumentException::because('Expected list of ' . $element->toString() . ' got different types.'); } } @@ -70,7 +67,7 @@ public function definition() : Definition { return Definition::list( $this->name, - $this->type, + $this->type->element(), metadata: Metadata::with(FlowMetadata::METADATA_LIST_ENTRY_TYPE, $this->type()) ); } @@ -87,13 +84,14 @@ public function is(string|Reference $name) : bool public function isEqual(Entry $entry) : bool { return $this->is($entry->name()) - && $entry instanceof self && (new ArrayComparison())->equals($this->value(), $entry->value()) + && $entry instanceof self + && (new ArrayComparison())->equals($this->value, $entry->value()) && $this->type->isEqual($entry->type); } public function map(callable $mapper) : Entry { - return new self($this->name, $this->type, $mapper($this->value)); + return new self($this->name, $this->type->element(), $mapper($this->value)); } public function name() : string @@ -103,7 +101,7 @@ public function name() : string public function rename(string $name) : Entry { - return new self($name, $this->type, $this->value); + return new self($name, $this->type->element(), $this->value); } public function toString() : string @@ -111,7 +109,7 @@ public function toString() : string return \json_encode($this->value(), JSON_THROW_ON_ERROR); } - public function type() : Type + public function type() : ListType { return $this->type; } diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/TypedCollection.php b/src/core/etl/src/Flow/ETL/Row/Entry/TypedCollection.php index 7e7feb13d..a4049d22a 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/TypedCollection.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/TypedCollection.php @@ -2,9 +2,9 @@ namespace Flow\ETL\Row\Entry; -use Flow\ETL\PHP\Type\Type; +use Flow\ETL\PHP\Type\Logical\ListType; interface TypedCollection { - public function type() : Type; + public function type() : ListType; } diff --git a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php index 319336215..a518c235a 100644 --- a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php +++ b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php @@ -6,9 +6,8 @@ use Flow\ETL\DSL\Entry as EntryDSL; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; -use Flow\ETL\PHP\Type\Type; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\Row; use Flow\ETL\Row\Entry; use Flow\ETL\Row\EntryFactory; @@ -143,10 +142,10 @@ public function create(string $entryName, mixed $value, ?Schema $schema = null) $class = \DOMNode::class; } - return new Entry\ListEntry($entryName, ObjectType::fromString($class), $value); + return new Entry\ListEntry($entryName, ListElement::object($class), $value); } - return new Entry\ListEntry($entryName, ScalarType::fromString($type), $value); + return new Entry\ListEntry($entryName, ListElement::scalar($type), $value); } if (null === $value) { @@ -249,7 +248,7 @@ private function fromDefinition(Schema\Definition $definition, mixed $value) : E if ($type === Entry\ListEntry::class && \is_array($value) && \array_is_list($value)) { try { - /** @var Type $listType */ + /** @var ListElement $listType */ $listType = $definition->metadata()->get(Schema\FlowMetadata::METADATA_LIST_ENTRY_TYPE); if (!\count($value)) { @@ -260,11 +259,11 @@ private function fromDefinition(Schema\Definition $definition, mixed $value) : E ); } - if ($listType instanceof ObjectType) { + if ($listType->value() instanceof ObjectType) { /** @var mixed $firstValue */ $firstValue = \current($value); - if (\is_a($listType->class, \DateTimeInterface::class, true) && \is_string($firstValue)) { + if (\is_a($listType->value()->class, \DateTimeInterface::class, true) && \is_string($firstValue)) { return new Entry\ListEntry( $definition->entry()->name(), $listType, diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/CollectionType.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/CollectionType.php index 9790b3465..b69fb923a 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/CollectionType.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/CollectionType.php @@ -33,6 +33,6 @@ public function isSatisfiedBy(Entry $entry) : bool return false; } - return $entry->type() === $this->type; + return $entry->type()->element()->isEqual($this->type); } } diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Definition.php b/src/core/etl/src/Flow/ETL/Row/Schema/Definition.php index f987f2351..350062ea0 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Definition.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema/Definition.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Row\Schema; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\Type; +use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\Row\Entry; use Flow\ETL\Row\Entry\ArrayEntry; use Flow\ETL\Row\Entry\BooleanEntry; @@ -116,7 +116,7 @@ public static function json(string|EntryReference $entry, bool $nullable = false return new self($entry, ($nullable) ? [JsonEntry::class, NullEntry::class] : [JsonEntry::class], $constraint, $metadata); } - public static function list(string|EntryReference $entry, Type $type, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function list(string|EntryReference $entry, ListElement $type, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self { return new self( $entry, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php index 81aadaa0d..a8bd91253 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php @@ -6,8 +6,8 @@ use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\Row\Entry\ListEntry; use Flow\ETL\Row\Schema\Definition; use PHPUnit\Framework\TestCase; @@ -27,7 +27,7 @@ public function test_creating_boolean_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list of boolean got different types'); - new ListEntry('list', ScalarType::boolean, ['string', false]); + new ListEntry('list', ListElement::boolean(), ['string', false]); } public function test_creating_datetime_list_from_wrong_value_types() : void @@ -35,7 +35,7 @@ public function test_creating_datetime_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list of object got different types.'); - new ListEntry('list', new ObjectType(\DateTimeInterface::class), ['string', new \DateTimeImmutable()]); + new ListEntry('list', ListElement::object(\DateTimeInterface::class), ['string', new \DateTimeImmutable()]); } public function test_creating_float_list_from_wrong_value_types() : void @@ -43,7 +43,7 @@ public function test_creating_float_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list of float got different types'); - new ListEntry('list', ScalarType::float, ['string', 1.3]); + new ListEntry('list', ListElement::float(), ['string', 1.3]); } public function test_creating_integer_list_from_wrong_value_types() : void @@ -51,15 +51,15 @@ public function test_creating_integer_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list of integer got different types'); - new ListEntry('list', ScalarType::integer, ['string', 1]); + new ListEntry('list', ListElement::integer(), ['string', 1]); } public function test_creating_list_from_not_list_array() : void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Expected list of integer got array with not sequential integer indexes'); + $this->expectExceptionMessage('Expected list of integer got different types'); - new ListEntry('list', ScalarType::integer, ['a' => 1, 'b' => 2]); + new ListEntry('list', ListElement::integer(), ['a' => 1, 'b' => 2]); } public function test_creating_string_list_from_wrong_value_types() : void @@ -67,13 +67,13 @@ public function test_creating_string_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list of string got different types'); - new ListEntry('list', ScalarType::string, ['string', 1]); + new ListEntry('list', ListElement::string(), ['string', 1]); } public function test_definition() : void { $this->assertEquals( - Definition::list('strings', ScalarType::string, false), + Definition::list('strings', ListElement::string()), Entry::list_of_string('strings', ['one', 'two', 'three'])->definition() ); } @@ -129,7 +129,7 @@ public function test_to_string_date_time() : void public function test_type() : void { $this->assertEquals( - ScalarType::string, + new ListType(ListElement::string()), Entry::list_of_string('strings', ['one', 'two', 'three'])->type() ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php index 3b094e0cb..2069a53a7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php @@ -6,8 +6,7 @@ use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ObjectType; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\Row\Factory\NativeEntryFactory; use Flow\ETL\Row\Schema; use Flow\ETL\Tests\Fixtures\Enum\BackedIntEnum; @@ -205,7 +204,7 @@ public function test_list_int_with_schema() : void { $this->assertEquals( Entry::list_of_int('e', [1, 2, 3]), - (new NativeEntryFactory())->create('e', [1, 2, 3], new Schema(Schema\Definition::list('e', ScalarType::integer))) + (new NativeEntryFactory())->create('e', [1, 2, 3], new Schema(Schema\Definition::list('e', ListElement::integer()))) ); } @@ -214,7 +213,7 @@ public function test_list_int_with_schema_but_string_list() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Field "e" conversion exception. Expected list of integer got different types.'); - (new NativeEntryFactory())->create('e', ['1', '2', '3'], new Schema(Schema\Definition::list('e', ScalarType::integer))); + (new NativeEntryFactory())->create('e', ['1', '2', '3'], new Schema(Schema\Definition::list('e', ListElement::integer()))); } public function test_list_of_datetime_with_schema() : void @@ -222,7 +221,7 @@ public function test_list_of_datetime_with_schema() : void $this->assertEquals( Entry::list_of_datetime('e', $list = [new \DateTimeImmutable('now'), new \DateTimeImmutable('tomorrow')]), (new NativeEntryFactory()) - ->create('e', $list, new Schema(Schema\Definition::list('e', ObjectType::fromString(\DateTimeInterface::class)))) + ->create('e', $list, new Schema(Schema\Definition::list('e', ListElement::object(\DateTimeInterface::class)))) ); } @@ -250,7 +249,7 @@ public function test_list_of_string_datetime_with_schema() : void ->create( 'e', ['2022-01-01 00:00:00 UTC', '2022-01-01 00:00:00 UTC'], - new Schema(Schema\Definition::list('e', ObjectType::fromString(\DateTimeInterface::class))) + new Schema(Schema\Definition::list('e', ListElement::object(\DateTimeInterface::class))) ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/CollectionTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/CollectionTypeTest.php index e8aa1b747..a68c5a7f1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/CollectionTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/CollectionTypeTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Tests\Unit\Row\Schema\Constraint; use Flow\ETL\DSL\Entry; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Schema\Constraint\CollectionType; use PHPUnit\Framework\TestCase; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php index 0fd0c1d33..e03eca9da 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Tests\Unit\Row\Schema\Constraint; use Flow\ETL\DSL\Entry; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entries; use Flow\ETL\Row\Schema\Constraint\NotEmpty; use PHPUnit\Framework\TestCase; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php index 63d941c57..a45e55240 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php @@ -6,7 +6,7 @@ use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\Row\Entry\IntegerEntry; use Flow\ETL\Row\Entry\ListEntry; use Flow\ETL\Row\Entry\NullEntry; @@ -46,22 +46,22 @@ public function test_equals() : void public function test_equals_but_different_constraints() : void { - $def = Definition::list('list', ScalarType::integer); + $def = Definition::list('list', ListElement::integer()); $this->assertFalse( $def->isEqual( - Definition::list('list', ScalarType::string) + Definition::list('list', ListElement::string()) ) ); } public function test_equals_types_and_constraints() : void { - $def = Definition::list('list', ScalarType::integer); + $def = Definition::list('list', ListElement::integer()); $this->assertTrue( $def->isEqual( - Definition::list('list', ScalarType::integer) + Definition::list('list', ListElement::integer()) ) ); } @@ -147,10 +147,10 @@ public function test_merging_two_different_lists_should_give_an_array() : void 'list', [ListEntry::class, NullEntry::class], null, - Metadata::empty()->add(FlowMetadata::METADATA_LIST_ENTRY_TYPE, ScalarType::string) + Metadata::empty()->add(FlowMetadata::METADATA_LIST_ENTRY_TYPE, ListElement::string()) ), - Definition::list('list', ScalarType::integer) - ->merge(Definition::list('list', ScalarType::string, true)) + Definition::list('list', ListElement::integer()) + ->merge(Definition::list('list', ListElement::string(), true)) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php index ca72f9856..afe86ef42 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Schema\Metadata; use PHPUnit\Framework\TestCase; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php index 360aefbf7..9c6515840 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php @@ -10,7 +10,7 @@ use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Partition; use Flow\ETL\PartitionedRows; -use Flow\ETL\PHP\Type\ScalarType; +use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\Row; use Flow\ETL\Row\Comparator\NativeComparator; use Flow\ETL\Row\Entry\BooleanEntry; @@ -733,7 +733,7 @@ public function test_rows_schema() : void Definition::integer('id'), Definition::union('name', [StringEntry::class, NullEntry::class, IntegerEntry::class]), Definition::array('tags', true), - Definition::list('list', ScalarType::integer, true) + Definition::list('list', ListElement::integer(), true) ), $rows->schema() ); @@ -747,7 +747,7 @@ public function test_rows_schema_when_rows_have_different_list_types() : void ); $this->assertEquals( - new Schema(Definition::list('list', ScalarType::integer)), + new Schema(Definition::list('list', ListElement::integer())), $rows->schema() ); }