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

False positive for variable parameter hints #683

Closed
CodeDuck42 opened this issue Dec 8, 2017 · 2 comments · Fixed by mockery/mockery#828
Closed

False positive for variable parameter hints #683

CodeDuck42 opened this issue Dec 8, 2017 · 2 comments · Fixed by mockery/mockery#828

Comments

@CodeDuck42
Copy link

The PHPDoc tag of foo[] should equal array<int, foo> and not array<foo>

 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ----------------------------------------------------------------------------------------------------------
  Line   baz.php
 ------ ----------------------------------------------------------------------------------------------------------
  10     PHPDoc tag @param for parameter $foos with type array<foo> is not subtype of native type array<int, foo>
 ------ ----------------------------------------------------------------------------------------------------------


 [ERROR] Found 1 error

foo.php

<?php

class foo
{
    public function bar(): void
    {
    }
}

baz.php

<?php

require_once __DIR__ . '/foo.php';

class baz
{
    /**
     * @param foo[] $foos
     */
    public function test(foo ...$foos): void
    {
        // ...
    }
}
@JanTvrdik
Copy link
Contributor

The PHPDoc tag of foo[] should equal array<int, foo> and not array

No, the behavior is correct, although the error message should be improved to make it easier to understand where to problem is.

The correct way to document types of variadic parameters is

class baz
{
    /**
     * @param Foo ...$foos
     */
    public function test(Foo ...$foos): void
    {
        // ...
    }
}

i.e. the syntax in PHPDoc needs to match the native syntax.

@CodeDuck42
Copy link
Author

CodeDuck42 commented Dec 8, 2017

Interesting so its more or less a problem of the IDE (PHPStorm), that doesn't handle variable parameter counts. A bit of a bummer, cause there is no declaration i can use to satisfy PHPStorm and phpstan at the moment.

Just for future reference: https://youtrack.jetbrains.com/issue/WI-29429

@lock lock bot locked as resolved and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants