Skip to content

NoPublicNonActionMethodInControllerRule reports attribute-routed actions (#[Route]) #368

Closed

Description

@M-arcus

Version: symplify/phpstan-rules 14.18.3

NoPublicNonActionMethodInControllerRule treats a public controller method as a route action only if its name ends in Action or it is __invoke(). Methods that carry a #[Route] attribute are not recognised, so every attribute-routed controller with conventional method names gets reported:

use Symfony\Component\Routing\Attribute\Route;

final class LeadLayerController extends AbstractController
{
    #[Route(path: '/lead-layer/submit', name: 'lead_layer_submit', methods: ['POST'])]
    public function submit(Request $request): JsonResponse
    {
        // ...
    }
}
Controller method "submit()" is not a route action, so it cannot be public. Make it protected or private
🪪  symfony.noPublicNonActionMethodInController

Making the method private breaks the route, and the *Action suffix has not been the Symfony convention since attribute routing became the default. In our project the upgrade from 14.17.0 produced 63 errors, all of them on #[Route] methods.

Expected: methods with a Symfony\Component\Routing\Attribute\Route (or the legacy Symfony\Component\Routing\Annotation\Route) attribute are skipped, the same way #[Required] setters already are.

Suggested fix: extend hasRequiredAttribute() (or add a sibling check) to also return early for the two Route attribute classes. I can open a PR with a fixture if that helps.

Activity

  1. TomasVotruba commented on Oct 14, 2026

    @TomasVotruba
    Member

    Can you send a failing PR with test fixture here?

  2. TomasVotruba commented on Oct 14, 2026

    @TomasVotruba
    Member

    Thank you 👍

    Fixed in #371

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions