-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Migrate to Doctrine CS 10 on 3.0.x #9886
Conversation
fb41afc
to
505b4b4
Compare
@simPod Apparently, the introduction of the
|
@derrabus I think I've already did. Try disabling |
505b4b4
to
6c5a61a
Compare
Indeed, that did the trick, thanks. Is this a bug we need to report to PHPCS or would we rather deactivate that rule in the Doctrine CS? |
I plan to investigate the conflict and then will see what to do about it. Either report origin lib or/and send PR to Doctrine CS. |
/** | ||
* @var Train | ||
* @OneToOne(targetEntity="Train", fetch="EAGER") | ||
*/ | ||
public $train |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is a bit unfortunate. SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
is triggered here although it's not just a parameter type that is being added here, but also a property type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe v8.2 does the trick https://github.com/slevomat/coding-standard/releases/tag/8.2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these changes have been produced with version 8.2.0 already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at this again and I don't think I understand what the issue is 🤔.
The @var
seems redundant so it's added as a native TH.
@derrabus the issue has been there for a long time so I don't think it's relevant for our CS v10. squizlabs/PHP_CodeSniffer#3477 There are two squizlabs sniffs conflicting because they have never understood trailing commas. |
Okay, but by introducing more trailing comma rules, we create a footgun if we don't deactivate that conflicting rule in Doctrine CS, don't we? |
@derrabus both sniffs are useful I think, it will require a fix in squizlabs/PHP_CodeSniffer |
@@ -88,7 +88,7 @@ abstract class AbstractQuery | |||
/** | |||
* The user-specified ResultSetMapping to use. | |||
*/ | |||
protected ?ResultSetMapping $_resultSetMapping = null; | |||
protected ResultSetMapping|null $_resultSetMapping = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale behind enforcing the usage of union types instead of nullable types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I believe arbitrary union types (e.g. getValue(sting $key): int|string|false
) often reflect poor API design while nullable types are fine (e.g. findUser(int $id): ?User
).
I think that enforcing a feature introduced primarily to support the existing poor design of the PHP's own API and the type system as a one-size-fits-all solution is not the right move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Union types are fine. I must disagree that union types often reflect poor API design. I think the premise is too simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two ways of expressing the same thing: a union of a type and null
. Normalizing that is reasonable imho. Whether we use the old nullable syntax or the new union syntax does not matter that much to me, as long as we agree on a single way to do it.
And I don't follow that "poor API design" argument either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, so how do you suggest to proceed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not forbid nullable types in the coding standard: doctrine/coding-standard#266 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not forbid nullable types in the coding standard
That means, we would allow both ways of expressing nullable types? Or would we let the fixer change Foo|null
to ?Foo
?
Do you want to open a PR on the coding-standards repo that makes the necessary config adjustments? I think, this change should be discussed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think different topic is discussed here. The sniff is not about whether or not it is ok to design API with unions. It's not about API at all.
The sniff is about consistent usage of union types. If there are no unions, the sniff does not apply.
If there's union of Type
and null
, it should be written as union: Type|null
. The archaic ?Type
was introduced because of absence of union types in the language. Since there's unions support now, there's no reason to use ?
because it's inconsistent. We already have null
value and will have null
standalone type in 8.2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means, we would allow both ways of expressing nullable types? Or would we let the fixer change Foo|null to ?Foo?
If the latter is possible, I would prefer that. Otherwise, the former is fine.
Do you want to open a PR on the coding-standards repo that makes the necessary config adjustments?
No.
6c5a61a
to
582d319
Compare
Replaced by #10011 |
This is #9866 on 3.0.x. I'd like to keep track of what the new CS standard would do to our precious codebase. 😬