Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a psalm type for field mapping #9198

Merged
merged 1 commit into from
Nov 23, 2021

Conversation

laryjulien
Copy link
Contributor

Field mapping have different definitions
in property definition and method return.
As suggested in issue and to avoid further desynchronization,
a psalm type has been created.
Fixes #9193

@greg0ire
Copy link
Member

@laryjulien thanks! Both Psalm and Phpstan now detect 7 issues with keys that are accessed without checking first if they might be null… for each of them, I see 3 possibilities:

  • we assert that it is not null;
  • we check that it is not null, throw a custom exception if it is;
  • we ignore the error in the baseline of both tools.

I'm not sure what's best, but I think it mostly depends on whether the issue could actually happen or not.

* columnName?: string,
* columnDefinition?: string
* }
* @psalm-return FieldMapping
Copy link
Contributor

@azjezz azjezz Nov 22, 2021

Choose a reason for hiding this comment

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

this is a BC break IMHO, previous type states that fieldName, type, scale, length, unique, nullable, and precision are always available, while the new type states that they might not exist in the returned array.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, didn't catch that, why did you change this @laryjulien ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed my PR to only use FieldMapping type in the initial context of issue.
I suggest to open an other PR to use this type in a wider context. Indeed, there are small variations on field mapping definition which appear to be more complex than I thought at first glance.

@@ -1534,7 +1532,7 @@ private function validateAndCompleteTypedAssociationMapping(array $mapping): arr
/**
* Validates & completes the given field mapping.
*
* @psalm-param array<string, mixed> $mapping The field mapping to validate & complete.
* @psalm-param FieldMapping $mapping The field mapping to validate & complete.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually the BC break, as the other method is private.

@laryjulien laryjulien force-pushed the fix-fieldmapping-definition branch from 2002d46 to 444b5a5 Compare November 22, 2021 20:28
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Thank you very much for working on this issue. Just today I performed an ORM update on a codebase and I suddenly had lots of false-positive Psalm errors because of those inconsitently documented array shapes. Looking forward to seeing this merged. 👍🏻

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php Outdated Show resolved Hide resolved
Field mapping have different definitions
in property definition and method return.
As suggested in issue and to avoid further desynchronization,
a psalm type has been created.
Fixes doctrine#9193
@laryjulien laryjulien force-pushed the fix-fieldmapping-definition branch from 444b5a5 to 5aba762 Compare November 23, 2021 17:06
@greg0ire greg0ire added the Bug label Nov 23, 2021
@greg0ire greg0ire added this to the 2.10.3 milestone Nov 23, 2021
@greg0ire greg0ire merged commit 146b465 into doctrine:2.10.x Nov 23, 2021
@greg0ire
Copy link
Member

Thanks @laryjulien !

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

Successfully merging this pull request may close these issues.

Field mapping definitions are different in ClassMetadataInfo
4 participants