-
Notifications
You must be signed in to change notification settings - Fork 1.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
Specified array and callback docblock types #708
Conversation
Pull master from squizlabs
@@ -650,10 +650,12 @@ protected function processParams($commentStart, $commentEnd) | |||
} else if (count($typeNames) === 1) { | |||
// Check type hint for array and custom type. | |||
$suggestedTypeHint = ''; | |||
if (strpos($suggestedName, 'array') !== false) { | |||
if (strpos($suggestedName, 'array') !== false || substr($suggestedName, -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.
This does cover basic ClassName[]
format, but doesn't cover more complex ones, like integer[]|string
or (classA|classB)|(classC[])
. I personally don't use such complex types in DocBlocks, but PhpDoc supports them.
Supporting them might be bad for performance reasons (because you need to parse whole type string).
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 there is a | in the type, count($typeNames) will be greater than 1, and no type hint will be suggested. In other words: this piece of code doesn't have to cover composite 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.
Good.
I can't merge this in because you've made a PR from the old unsupported 1.x version. As the changes are so small, I can apply them manually, but I thought I'd let you know in case you want to create a new PR based on the current supported code. Let me know if you'd prefer me to manually apply the changes. |
2f76282
to
28bdf31
Compare
Thanks! I had already started on a rebase, so I'd thought I just finish it real quick. So here it is. :) |
I see I have a merge commit, do you want me to fix that? |
never mind :) |
Thanks a lot for doing that, and for the PR, and for the tests! |
No problem! |
In reaction to #685, I've looked around the code base, but I haven't found any other sniffs that relate to array type hints.
I have found another inconsistency in callable/callback. I've asked the phpDocumenter team for clarification: phpDocumentor/phpDocumentor#1645
On top of that, I've added tests.
(This PR would also fix #601 and #642.)