Skip to content

@(phpstan|psalm)-require-(extends|implements) for trait #837

Description

@ging-dev
<?php

interface A {
    public function test1();
}

class B {
    public function test2() {

    }
}

/**
 * @phpstan-require-extends B
 * @phpstan-require-implements A
 */
trait C {
    public function test3() {
        $this->test // shoud suggest test1(), test2() from A, B
    }
}

https://phpstan.org/r/1d8da70d-b8f0-4d3a-b519-76ab2f8c6c95

Bug:

<?php

/**
 * @phpstan-require-extends B --> `@extends tag specifies B type, but the corresponding class does not extends type by that name`, this is a wrong diagnosis.
 */
interface A {
    public function test1();
}

class B {
    public function test2() {

    }
}

class C implements A { // shoud add problem here: Interface A requires implementing class to extend B, but C does not.

    /**
     * @inheritDoc
     */
    public function test1() {
    }
}

Note: PHPDoc tag @phpstan-require-(extends|implements) is only valid on trait or interface.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions