Phpinspectionsea: [type, number -> int|float] Makes no sense, because this type is not defined in annotations

Created on 15 Sep 2017  路  10Comments  路  Source: kalessil/phpinspectionsea

I have the following function:

/**
 * @param number|string $amount
 */
function add($amount)
{
    if (is_int($amount)) {

    }
}

The is_int() function is highlighted with the following warning:

Makes no sense, because this type is not defined in annotations.

Actually, the int type is defined in the annotation, but implicitly: number is a synonym for int|float!

enhancement fixed

Most helpful comment

All 10 comments

Hm, https://docs.phpdoc.org/guides/types.html#primitives doesn't have type number.
Let me check how often the type is used in OSS projects - if so I'll add the type translation or at least mapping to int if restricted by our APIs.

Thanks for hands on!

PHPDoc is often cited as the de-facto standard, but the fact is, there is no such standard yet. I'm personally using number in my docs as a shortcut for int|float, and my IDE, PHPStorm, does seem to understand it.

This is subject to debate, though, I can appreciate that.

(...) at least mapping to int if restricted by our APIs.

I'd have the same problem with is_float() then... :wink:

Voted as well, added support on our side.

Thanks for the support! I'm still having the same warning with 2.3.10.2, though?

Ah sorry, just realized that the commit happened after the release. Will wait for the next one then ;-)

The next release =) Or if I discovered/get reported new java exceptions, then in 2.3.10.3.

@BenMorel : it'll be 2.3.10.3 tomorrow evening, so the change will be there =)

I can confirm it works perfectly now, thanks!

You are welcome =)

Was this page helpful?
0 / 5 - 0 ratings