0
<?php

interface iFoo {
    public function print(): iFoo;
}

class Foo implements iFoo {
    public function print(): iFoo {
        return $this;
    }

    public function chain(): iFoo {
        return $this;
    }
}

$foo = new Foo();
$foo->print()
    ->chain() // Method 'chain' not found in iFoo
    ->print();

How can I make PhpStorm recognize the chain method, even though it's not in the contract?

2 Answers2

1

It's because you're telling PHPStorm that you're going to have a return type of iFoo which doesn't have the class chain() if your return type is Foo I would guess this would work.

Jez Emery
  • 676
  • 4
  • 18
1

print() method returns iFoo instance:

public function print(): iFoo {

iFoo does not contain chain() method, that's why you see "method not found". You can change the return type to Foo or add chain() method to iFoo.

Yury Fedorov
  • 14,508
  • 6
  • 50
  • 66