Skip to content

Commit

Permalink
Added template to Types that defines underlying data type (#1326)
Browse files Browse the repository at this point in the history
* Added template to Types that defines underlying data type

* CS Fixes
  • Loading branch information
norberttech authored Jan 4, 2025
1 parent 972da37 commit 257e7f4
Show file tree
Hide file tree
Showing 41 changed files with 107 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function supports(Type $type) : bool
return $type instanceof ArrayType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : array
{
try {
if (\is_array($value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function supports(Type $type) : bool
return $type instanceof BooleanType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : bool
{
if (\is_bool($value)) {
return $value;
Expand Down
7 changes: 7 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Caster/CastingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ interface CastingHandler
{
public function supports(Type $type) : bool;

/**
* @template T
*
* @param Type<T> $type
*
* @return T
*/
public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof DateType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : \DateTimeImmutable
{
if ($value instanceof \DateTimeImmutable) {
return $value->setTime(0, 0, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function supports(Type $type) : bool
return $type instanceof DateTimeType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : \DateTimeImmutable
{
if ($value instanceof \DateTimeImmutable) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof EnumType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : \UnitEnum
{
/** @var EnumType $type */
if ($value instanceof $type->class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function supports(Type $type) : bool
return $type instanceof FloatType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : float
{
/**
* @var FloatType $type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function supports(Type $type) : bool
return $type instanceof IntegerType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : int
{
if (\is_int($value)) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof ListType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : array
{
/** @var ListType $type */
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof MapType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : array
{
/** @var MapType $type */
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function supports(Type $type) : bool
return $type instanceof NullType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : null
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function supports(Type $type) : bool
return $type instanceof ObjectType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : object
{
if (\is_object($value)) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof StringType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : string
{
if (\is_string($value)) {
return $value;
Expand All @@ -38,11 +38,11 @@ public function value(mixed $value, Type $type, Caster $caster, Options $options
}

if ($value instanceof \DOMDocument) {
return $value->saveXML() ?: null;
return $value->saveXML() ?: '';
}

if ($value instanceof \DOMElement) {
return dom_element_to_string($value);
return (string) dom_element_to_string($value);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof StructureType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : array
{
/** @var StructureType $type */
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function supports(Type $type) : bool
return $type instanceof TimeType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : \DateInterval
{
if ($value instanceof \DateTimeInterface) {
return $value->diff(new \DateTimeImmutable($value->format('Y-m-d')), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function supports(Type $type) : bool
return $type instanceof UuidType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : Uuid
{
if ($value instanceof Uuid) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function supports(Type $type) : bool
return $type instanceof XMLType;
}

public function value(mixed $value, Type $type, Caster $caster, Options $options) : mixed
public function value(mixed $value, Type $type, Caster $caster, Options $options) : \DOMDocument
{
if ($value instanceof \DOMDocument) {
return $value;
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<\DateTimeInterface>
*/
final class DateTimeType implements LogicalType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<\DateTimeInterface>
*/
final class DateType implements LogicalType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<string>
*/
final class JsonType implements LogicalType
{
public function __construct(private readonly bool $nullable)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<array>
*/
final class ListType implements LogicalType
{
public function __construct(private readonly ListElement $element, private readonly bool $nullable = false)
Expand Down
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/LogicalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

use Flow\ETL\PHP\Type\Type;

/**
* @template TType
*
* @extends Type<TType>
*/
interface LogicalType extends Type
{
}
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/MapType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<array>
*/
final class MapType implements LogicalType
{
public function __construct(private readonly MapKey $key, private readonly MapValue $value, private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/StructureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<array>
*/
final class StructureType implements LogicalType
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<\DateInterval>
*/
final class TimeType implements LogicalType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/UuidType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Flow\ETL\PHP\Type\Type;
use Flow\ETL\PHP\Value\Uuid;

/**
* @implements LogicalType<\Ramsey\Uuid\UuidInterface|\Symfony\Component\Uid\Uuid|Uuid>
*/
final class UuidType implements LogicalType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/XMLElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<\DOMDocument>
*/
final class XMLElementType implements LogicalType
{
public function __construct(private readonly bool $nullable)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/XMLType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\PHP\Type\Native\NullType;
use Flow\ETL\PHP\Type\Type;

/**
* @implements LogicalType<\DOMDocument>
*/
final class XMLType implements LogicalType
{
public function __construct(private readonly bool $nullable)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<array>
*/
final class ArrayType implements NativeType
{
public function __construct(private readonly bool $empty = false, private readonly bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<boolean>
*/
final readonly class BooleanType implements NativeType
{
public function __construct(private bool $nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<callable>
*/
final class CallableType implements NativeType
{
public function __construct(private readonly bool $nullable)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<\UnitEnum>
*/
final class EnumType implements NativeType
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<float>
*/
final readonly class FloatType implements NativeType
{
public function __construct(private readonly bool $nullable = false, public readonly int $precision = 6)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/IntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<integer>
*/
final readonly class IntegerType implements NativeType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/NativeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

use Flow\ETL\PHP\Type\Type;

/**
* @template TType
*
* @extends Type<TType>
*/
interface NativeType extends Type
{
}
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/NullType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<null>
*/
final class NullType implements NativeType
{
public static function fromArray(array $data) : self
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<object>
*/
final class ObjectType implements NativeType
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/ResourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<resource>
*/
final class ResourceType implements NativeType
{
public function __construct(private readonly bool $nullable)
Expand Down
3 changes: 3 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Native/StringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\PHP\Type\Type;

/**
* @implements NativeType<string>
*/
final readonly class StringType implements NativeType
{
public function __construct(private readonly bool $nullable = false)
Expand Down
Loading

0 comments on commit 257e7f4

Please sign in to comment.