Skip to content

[Bug]: Inconsistent Behavior of EntryFactory with Uuid #1926

@norberttech

Description

@norberttech

What happened?

DataFactory::create() method is covering something that it shouldn't.

If we want to create an Entry from a passed value without passing Type EntryFactory will use TypeDetector to figure out what type it is.

$valueType = (new TypeDetector())->detectType($value);

Then when returned type is string, it will also use StringTypeChecker to narrow the type based on string shape, so for example 2025-01-01 will be detected as type_date.
That type is later passed to EntryFactory::createAs() method which creates entry.

But there is additional condition in create method.

if ($valueType instanceof InstanceOfType) {

from which all conditions except the last one are redundant (TypeDetector covers them anyway).

The problem starts here:

foreach (['Ramsey\Uuid\UuidInterface', Uuid::class, 'Symfony\Component\Uid\Uuid'] as $uuidClass) {
    if (\is_a($valueType->class, $uuidClass, true)) {
        $valueType = type_uuid();

        break;
    }
}

So what it does is very similar behavior to StringTypeChecker (which btw should probably be called StringTypeNarrower). Meaning that when it gets TypeInstanceOf (object) it will try to narrow the type to one of 'Ramsey\Uuid\UuidInterface', Uuid::class, 'Symfony\Component\Uid\Uuid' (where Uuid::class is redundant, type checker covers that)

How to reproduce?

Remove that whole if ($valueType instanceof InstanceOfType) { from EntryFactory and run this test

Data required to reproduce bug locally

No response

Version

0.10.0+

Relevant error output

Copy and paste any relevant error output (no backticks needed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions