Vscode-intelephense: Warnings about not implementing all abstract methods while I should not have to

Created on 14 Sep 2020  路  3Comments  路  Source: bmewburn/vscode-intelephense

Describe the bug

I use this library named woohoolabs/yin and I noticed that the plugin is incorrectly suggesting to implement abstract methods when I extend this class: https://github.com/woohoolabs/yin/blob/master/src/JsonApi/Hydrator/AbstractHydrator.php

The reason for this is probably because the plugin doesn't take into consideration that one abstract method in one of the traits can already be implemented in another trait.

To Reproduce

The createHydratorTrait has an abstract method validateType. This method, however, is implemented in the Hydrator trait, seen here. Both these traits are used in the abstractHydrator class.

Expected behavior

The warning should be more like:

'DomainStandaloneProductsJsonApiStandaloneProductHydrator' does not implement methods 'getAcceptedTypes', 'getAttributeHydrator', 'getRelationshipHydrator', 'validateClientGeneratedId', 'validateRequest', 'generateId', 'setId'intelephense(1037)

Instead of:

'DomainStandaloneProductsJsonApiStandaloneProductHydrator' does not implement methods 'getAcceptedTypes', 'getAttributeHydrator', 'getRelationshipHydrator', 'validateType', 'hydrateAttributes', 'hydrateRelationships', 'doHydrateRelationship', 'validateClientGeneratedId', 'validateRequest', 'generateId', 'setId'intelephense(1037)

Screenshots

So currently, after implementing all necessary methods I still get warnings that these 3 methods aren't implemented (while I should not have to as described above):

image

Platform and version

MacOS 10.15.6
Intelephense 1.5.4 (+ I got a premium license key)

bug

Most helpful comment

Hi, I believe that I've also run into this issue on one of my projects.
I've put together a minimal example that reproduces this issue:

<?php

trait TraitRequiresAbstractMethod
{
    abstract public function myFunction(): string;
}

trait TraitImplementsAbstractMethod
{
    public function myFunction(): string
    {
        return "Hello, World!";
    }
}

class ClassUsesTraits
{
    use TraitRequiresAbstractMethod;
    use TraitImplementsAbstractMethod;
}

$instance = new ClassUsesTraits();
echo $instance->myFunction() . PHP_EOL;

Screenshot 2020-10-09 at 10 53 30

It seems that Intelephense is fine with the use of myFunction() on instances of the class, but complains at the class definition that it can't determine that the abstract method myFunction() was implemented.

For clarity, I'm also using Intelephense 1.5.4, on MacOS 10.15.7.

I hope that helps!

All 3 comments

Hi, I believe that I've also run into this issue on one of my projects.
I've put together a minimal example that reproduces this issue:

<?php

trait TraitRequiresAbstractMethod
{
    abstract public function myFunction(): string;
}

trait TraitImplementsAbstractMethod
{
    public function myFunction(): string
    {
        return "Hello, World!";
    }
}

class ClassUsesTraits
{
    use TraitRequiresAbstractMethod;
    use TraitImplementsAbstractMethod;
}

$instance = new ClassUsesTraits();
echo $instance->myFunction() . PHP_EOL;

Screenshot 2020-10-09 at 10 53 30

It seems that Intelephense is fine with the use of myFunction() on instances of the class, but complains at the class definition that it can't determine that the abstract method myFunction() was implemented.

For clarity, I'm also using Intelephense 1.5.4, on MacOS 10.15.7.

I hope that helps!

This issue is not resolved (using version v1.6.1. In my case I got a class that extends an abstract class that it self extends another abstract class. In the last ("grant-parant") class, it uses 3 traits. In one of the traits it defines a method that is implemented either by the second or third trait, but it will still report that it's missing the methods in the child (non-abstract) class.

@Ilyes512 , can you add a minimal reproducible example?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

usrnm-nk picture usrnm-nk  路  3Comments

dgunay picture dgunay  路  3Comments

mushmelty picture mushmelty  路  4Comments

aleksandervines picture aleksandervines  路  3Comments

muuvmuuv picture muuvmuuv  路  4Comments