Skip to content

Mark objects returned in controllers (to Twig templates) as used #154

@ruudk

Description

@ruudk

Let's say you have the following:

final readonly class SomeModel
{
    public function __construct(
        private string $name,
    ) {}

    public function getName() : string
    {
        return $this->name;
    }
}

And you return it inside a controller to a Twig template like this:

#[AsController]
final class SomeController extends AbstractController
{
    #[Route(path: '/some', name: 'some')]
    #[Template('some.html.twig')]
    public function __invoke() : array
    {
        return [
            'some' => new SomeModel('Ruud')
        ];
    }
}

It will report that getName is unused. But it might be, we have no idea if it is used or not since it goes to Twig.

Would it be possible to do something similar to MemberUsageExcluder, but then for Inclusion?

I want all ClassMemberUsages that originate from a Controller Action, and go to a Template, marked as used.

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