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

Allow specified arrays in docblock type hints #685

Closed
wants to merge 1 commit into from
Closed

Allow specified arrays in docblock type hints #685

wants to merge 1 commit into from

Conversation

nicwortel
Copy link

Example:

/**
 * @param Item[] $items
 */
public function foo(array $items)
{
    // do something
}

Should be fine but currently returns an error: Expected type hint "Item[]"; found "array" for $items

This fixes #601 and #624

@aik099
Copy link
Contributor

aik099 commented Aug 21, 2015

Nice catch.

There might be other sniffs, that verify function parameter types against DocBlock as well. Please check them if you find any.

@nicwortel
Copy link
Author

To be honest, I'm not very familiar with the internals of code sniffer yet. Do you mean other sniffs within the Squiz standard? Or in other standards?

@aik099
Copy link
Contributor

aik099 commented Aug 21, 2015

All sniffs in all standards. I guess you can search for array or callable find find these places.

@gsherwood
Copy link
Member

This issue is being fixed in PR #708 , along with another issue. The fix is almost the same, but just checks if the last two chars are [] rather than looking for them anywhere in the type hint. Both ways looks to work fine.

Thanks a lot for sending in the PR.

@gsherwood gsherwood closed this Sep 21, 2015
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