Phpinspectionsea: False-Positive "Function result is unused" with constructor calls

Created on 20 Oct 2018  路  6Comments  路  Source: kalessil/phpinspectionsea

| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Issue type | False-Positive |
| Plugin | Php Inspections (EA Ultimate), 2.0.9 |
| Language level | PHP 7.2 |

Current behaviour:

Here is some example code:

<?php

declare(strict_types=1);

class A
{
    /** @var string */
    private $foo;

    public function __construct(string $foo)
    {
        $this->foo = $foo;
    }
}

class B extends A
{
    /** @var string */
    private $bar;

    public function __construct(string $foo, string $bar)
    {
        parent::__construct($foo);
        $this->bar = $bar;
    }
}

class C extends B
{
    /** @var string */
    private $fooBar;

    public function __construct(string $foo, string $bar, string $fooBar)
    {
        parent::__construct($foo, $bar);
        $this->fooBar = $fooBar;
    }
}

I get a warning "Function result is not used" in class C in the line parent::__construct($foo, $bar); now. The weird thing is, if class C extends from class A directly instead of class B, this false-positive does not happen.

Expected behaviour:

Do not report this. The constructor can't return anything.

bug / false-positive fixed

Most helpful comment

Fixed!

All 6 comments

  • fluid interfaces (returning self, static or this)

Fixed!

Thank you a lot, that bug was really annoying. :+1:

@kalessil was it released for EA Ultimate?

The reported one yes. I had reworked the settings though, so in the next update inspection will be more usable.

False positive is still there for me in the current version. It's reporting that constructor return result isn't used.

Was this page helpful?
0 / 5 - 0 ratings