Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 5, 2025

Closes #682

@VincentLanglet VincentLanglet marked this pull request as ready for review October 5, 2025 14:54
whataboutpereira added a commit to whataboutpereira/phpstan-doctrine that referenced this pull request Oct 6, 2025
@whataboutpereira
Copy link

Thank you, works nicely here.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same points apply to UuidTypeDescriptor.

@ondrejmirtes
Copy link
Member

Coding standard failures here

@ondrejmirtes ondrejmirtes merged commit 4a761b6 into phpstan:2.0.x Oct 6, 2025
35 of 37 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@wjzijderveld
Copy link

wjzijderveld commented Oct 7, 2025

How would you recommend dealing with the different subtypes?
type mapping mismatch: database can contain Symfony\Component\Uid\Uuid but property expects Symfony\Component\Uid\UuidV7
In essence the error isn't wrong, the database could contain anything in theory, but it feels a bit weird having to specify a less specific typehint on my entity if I know its v7

@VincentLanglet
Copy link
Contributor Author

Is there a benefit to typing to Uuid7 rather than Uuid ?
Extra methods ?

Is it sure to be an Uuid7 ? Even if you migrate manually a value in database directly ?

So far I would say an easy way is to ignore it in the baseline.

@wjzijderveld
Copy link

The benefits of uuidv7 are in (time) sortability and indexability. Hence we want to be strict about it, as it's important in our systems. But it's a bit of a grey area, we obviously validate its v7 in our domain code where we generate it, so there's an argument to be made that the persistence layer only cares about the fact its a UUID and not about the specific version.

The argument about manually migrated data seems irrelevant to me, that's exactly what these doctrine types are for, to be able to verify that during persistence/fetching. With the generic UUID type it also wouldn't guarantee that the database doesn't contain random strings.

@VincentLanglet
Copy link
Contributor Author

The argument about manually migrated data seems irrelevant to me, that's exactly what these doctrine types are for, to be able to verify that during persistence/fetching.

But the purpose of the EntityColumn rule from PHPStan is to avoid possible crash. PHPStan has right to say you could have manually inserted a non-uuid7 in the database and it will be loaded as another Uuid.

The same way if you type a nullable field with private string $myNullableField PHPStan report the possibly null error even if the doctrine type will always be a string. So it's more an issue about Symfony only exposing one doctrine type uuid rather explicit uuid7 etc (which could be a good feature).

And again if you think this error is unrelevant, the pattern is easy to ignore.

@ondrejmirtes
Copy link
Member

Unless the Doctrine type guarantees UUIDv7 will be assigned to the property, this reported error is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doctrine type "uuid" does not have any registered descriptor using Symfony UUID
4 participants