Vscode-intelephense: Implement all methods from interfaces and or base class

Created on 8 Dec 2017  路  7Comments  路  Source: bmewburn/vscode-intelephense

code actions enhancement premium

Most helpful comment

What I also miss is a warning, if not all interface methods are implemented yet.

All 7 comments

Something that's extremely handy from the php-integrator in Atom is the icons on the side by the line numbers which would show when a method has been overridden, or when an interface method has been implemented. (This might be a separate feature?)

I think this is very important and I hope to achieve it as soon as possible

What I also miss is a warning, if not all interface methods are implemented yet.

Interfaces in intelephense are mostly silent now, at least compiler will throw errors.
Implement all method wouldn't be as necessary if there would be an error about not implemented method, existing autocomplete is enough for implementing methods one by one.

Test code (no intelephense warnings):

interface IAbc
{
    function testMe(int $i): bool;
}

class Abc implements IAbc
{}
// results with:
// E_ERROR: Class Abc contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (IAbc::testMe) (in [...])

class Def implements IAbc
{
    function testMe(int $i): int
    {
        return 1;
    }
}
// results with:
// E_COMPILE_ERROR: Declaration of Def::testMe(int $i): int must be compatible with IAbc::testMe(int $i): bool (in [...])

Same story is with abstract

abstract class AB
{
    abstract public function testMe(int $i): bool;
}

class CD extends AB
{
    public function testMe(int $i): int
    {
        return 1;
    }
}
// results with:
// E_COMPILE_ERROR: Declaration of CD::testMe(int $i): int must be compatible with AB::testMe(int $i): bool (in [...])

This one is high on the agenda. Diagnostics for the missing implementations will be in 1.3

@bmewburn Do you expect this to be enforced based on the entire method signature including arg types, or just the method name (and perhaps param count)? Hit a case recently where the former would have been a huge help in preventing a bug. Example:

interface Foo {
  function bar(MyClass $arg);
}

class MyFoo implements Foo {
  function bar(string $arg) { // <-- runtime error on $arg type; catching it statically would be great!
  }
}

@nickcabral , yes the complete signature as found on the interface or abstract class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgunay picture dgunay  路  3Comments

vanasis picture vanasis  路  4Comments

mushmelty picture mushmelty  路  4Comments

swashata picture swashata  路  3Comments

ghnp5 picture ghnp5  路  3Comments