Skip to content

Support __invoke methods #261

@darthf1

Description

@darthf1

Hi!

Thanks a lot for this great phpstan plugin, i was able to cleanup a lot of stuff in my repository.

I would like to be able to mark certain classes as not used, or skip marking certain classes as used, when certain conditions apply.

<?php

final readonly class MyDomainEvent {};
final readonly class MyDomainEvent2 {};

final readonly class MyDomainEventHandler()
{
  public function __invoke(MyDomainEvent $event): void
  {}
}

public function doSomething(): void
{
    $this->raise(new MyDomainEvent()); // class is used inside the raise method call, and inside the invoke method call inside the event handler
    $this->raise(new MyDomainEvent2()); // class is only used inside the raise method call
}

Specifically, I want to mark domain events which are raised (through ->raise(...)) but not handled through an event handler, as unused. Or, i dont want to count the "raise" method as usage for any event class.

I tried overriding the getUsages for this but i dont have any luck so far. Since there is only the MemberUsageProvider interface, this was the only location i could think of to do this.

Question: is the above do-able with the current way things work with dead-code-detector?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions