Skip to content

Friend functions #3565

@malarzm

Description

@malarzm

Feature request

It'd be nice to be able to achieve friend functions with PHPStan. An example of such usage that just popped up in our project:

class Product
{
    public function addCategory(Category $category): void;
}

class Category
{
    /**
     * @internal
     * @see Product::addCategory
     */
    public function addProduct(Product $product): void;
}

Category::addProduct should never be called directly but needs to be public so it might be called from Product::addCategory. It would be amazing to have a rule that forbids calls to methods marked as @internal unless a @friend FQCN::method (or something alike) is specified and the call is made from specified context.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions