Juliatzin
Juliatzin

Reputation: 19695

PhpStorm, Laravel and autocompletition

I have a method run() in TreeGen class:

class TreeGen implements TreeGenerable{

 public function run()
 {
     ...
     $this->pushEmptyGroupsToTree($numFighters);
     ...
 }
}

Thing is $this could be one of the 4 Subclasses of tree gen, and all those method implement different versions of pushEmptyGroupsToTree.

But PhpStorm is only looking for pushEmptyGroupsToTree in TreeGen class and off course, I don't have it defined in the super class, so it doesn't detect it.

Is there a way to make him recognize subclass methods?

Upvotes: 0

Views: 85

Answers (3)

Odin Thunder
Odin Thunder

Reputation: 3547

For this case you must use PHPDoc and type hinting

And don`t forget about:

  ide-helper:generate  Generate a new IDE Helper file.
  ide-helper:meta      Generate metadata for PhpStorm
  ide-helper:models    Generate autocompletion for models

Upvotes: 0

Coloured Panda
Coloured Panda

Reputation: 3467

If you dont want TreeGreen to be used directly, declare it abstract as such:

abstract class TreeGen implements TreeGenerable {
// ...

If you need the child classes to have that method declared, declare it as abstract in your superclass:

abstract class TreeGen implements TreeGenerable
{
    // ...
    abstract public function pushEmptyGroupsToTree($numFighters);
}

Now you cant extend TreeGen without implementing pushEmptyGroupsToTree as well

Upvotes: 1

Sergei Kasatkin
Sergei Kasatkin

Reputation: 385

IDE behaves correctly. You either need to declare this class abstract, or declare abstract method here or in superclass.

UPDATE

Method run of TreeGen could be called from instance of Treegen

$treeGen = new TreeGen;
$treeGen->run();

and that will cause Call to undefined method error.

If TreeGen is not supposed to be called directly it should be abstract.

Upvotes: 2

Related Questions