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

Expected type hint int[]; found array in Squiz FunctionCommentSniff #601

Closed
JDGrimes opened this issue May 23, 2015 · 9 comments · Fixed by #708
Closed

Expected type hint int[]; found array in Squiz FunctionCommentSniff #601

JDGrimes opened this issue May 23, 2015 · 9 comments · Fixed by #708

Comments

@JDGrimes
Copy link
Contributor

Example code:

    /**
     * Does foo with IDs.
     *
     * @param int[] $ids List of IDs.
     */
    function foo( array $ids ) {}

Expected result:
This should be OK.

Actual result:

 4   | ERROR | Expected type hint "int[]"; found "array" for $ids
     |       | (Squiz.Commenting.FunctionComment.IncorrectTypeHint)

The error comes from https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php#L386.

@aik099
Copy link
Contributor

aik099 commented May 23, 2015

Because it expects integer[] to be used. Not short int form.

@aik099
Copy link
Contributor

aik099 commented May 23, 2015

Maybe we need to make error message more intelligent.

@JDGrimes
Copy link
Contributor Author

Yeah, I think int is OK in the PHPDoc spec.

@aik099
Copy link
Contributor

aik099 commented May 23, 2015

It is, but Squiz standard specifically requires long type names.

@JDGrimes
Copy link
Contributor Author

It is, but Squiz standard specifically requires long type names.

I see. But I guess there is a separate error for that? I think it should take int (and bool) into account here so that it is more configurable.

Also, this actually isn't limited to short types. The same error would be given for integer[] (or string[] or object[] etc.).

@aik099
Copy link
Contributor

aik099 commented May 23, 2015

Then this is surely a bug.

@NikolaySl
Copy link

The same for

    /**
     * Does foo with MyClass objects.
     *
     * @param MyClass[] $list List of objects.
     */
    function foo( array $list ) {}

gives

 4 | ERROR | Expected type hint "MyClass[]"; found "array" for $list

@aik099
Copy link
Contributor

aik099 commented Jun 17, 2015

That is another non-related bug with forcing user to use typehint, that will end up with syntax error in PHP. Please report it separately.

@NikolaySl
Copy link

#624

@gsherwood gsherwood changed the title Expected type hint "int[]"; found "array" Expected type hint int[]; found array in Squiz FunctionCommentSniff Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants