Skip to content

Hook form_alter parameter dropping #1022

Description

@neclimdul

Bug report

Doing some maintenance I ran into bunch of these errors:

  Form alter hook "form_node_foobar_edit_form_alter"            
         implementation must have 2 or 3 parameters. Expected signature:        
         method(&$form, \Drupal\Core\Form\FormStateInterface $form_state[,      
         $form_id])                                                             
         🪪  hookFormAlter.invalidParameterCount

I'm not sure why the form_alter rule cares about having to few parameters. Specifically, dropping the $form_state when not used. Seems like not including unused parameters would be a best practice. I tried to follow the history on the code but there doesn't seem to be a reference or discussion so figured I'd ask.

Code snippet that reproduces the problem

Reference to the code.
https://github.com/mglaman/phpstan-drupal/blame/70c804da7e9f61e9c60785827e7d360b9444ca24/src/Rules/Drupal/HookFormAlterRule.php#L115-L124

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions