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

Specified array and callback docblock types #708

Merged
merged 3 commits into from
Sep 21, 2015

Conversation

scato
Copy link
Contributor

@scato scato commented Sep 17, 2015

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.)

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) === '[]') {
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good.

@gsherwood
Copy link
Member

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.

@scato
Copy link
Contributor Author

scato commented Sep 21, 2015

Thanks!

I had already started on a rebase, so I'd thought I just finish it real quick. So here it is. :)

@scato
Copy link
Contributor Author

scato commented Sep 21, 2015

I see I have a merge commit, do you want me to fix that?

@gsherwood gsherwood merged commit 28bdf31 into squizlabs:master Sep 21, 2015
@scato
Copy link
Contributor Author

scato commented Sep 21, 2015

never mind :)

@gsherwood
Copy link
Member

Thanks a lot for doing that, and for the PR, and for the tests!

@scato
Copy link
Contributor Author

scato commented Sep 21, 2015

No problem!

@scato scato deleted the specified-array-docblock branch September 21, 2015 06:08
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.

Expected type hint int[]; found array in Squiz FunctionCommentSniff
3 participants