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
Crumble removed TypeHintDeclaration sniff #139
Conversation
@simPod You should set option “enableNativeTypeHint” for PropertyTypeHint to false |
@kukulich did the trick, thanks! |
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"> | ||
<properties> | ||
<property name="traversableTypeHints" type="array"> | ||
<element value="Doctrine\Common\Collections\Collection"/> |
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.
It isn't fully clear to me why we are targeting Collection
as a specific type here.
Would need:
- an example (before/after test)
- to know how this copes with
@var Collection<TKey, TVar>
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.
It isn't fully clear to me why we are targeting
Collection
as a specific type here.
Same reason why all other sniffs of this kind add this: to ensure that a parameter with a Collection
type hint also gets a proper @param
or @return
annotation that clarifies its type (as is done with array
).
+1 on adding tests for this.
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.
Yeah, but shouldn't this be done with any Traversable
then?
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.
It was migrated from deprecated sniff.
According to docs, this forces to write \Doctrine\Common\Collections\Collection|Foo[]
.
Personally, I always write \Doctrine\Common\Collections\Collection<Foo>
. If it was on me, I'd throw it away.
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.
array
and iterable
are always treated as such. This list is in addition to the ones where the sniff requires it by default.
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.
@alcaeus Only iterable
and array
are covered by default. You can use DisallowArrayTypeHintSyntaxSniff and use always generic.
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 really like the idea of enabling DisallowArrayTypeHintSyntaxSniff
WDY-all-T?
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.
Please create a separate PR for that so the deciders can vote on it. Thanks!
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.
If I add only Traversable there it is not applied to eg. Iterator. So we have to explicitly name everything, that implements Traversable
Disable TypeHintDeclaration Enable - ParameterTypeHint - PropertyTypeHint - ReturnTypeHint - UselessFunctionDocComment
Superseded by #144 |
Introduced in slevomat/coding-standard@7db89be
Disable TypeHintDeclaration
Enable
Build currently fails, there are some features on by default for PHP 7.4. Have to investigate what's the cause and if I can fix it yet.