FlagAction::execute() has the wrong number of arguments

Created on 11 November 2024, 3 months ago

In πŸ“Œ Add declare(strict_types=1) to all test modules Active , running phpstan at level 2 on the test cases revealed the following:

 ------ ---------------------------------------------------------------------- 
  Line   tests/src/Kernel/FlagActionTest.php                                   
 ------ ---------------------------------------------------------------------- 
  108    Method Drupal\Core\Executable\ExecutableInterface::execute() invoked  
         with 1 parameter, 0 required.                                         
  121    Method Drupal\Core\Executable\ExecutableInterface::execute() invoked  
         with 1 parameter, 0 required.                                         
 ------ ---------------------------------------------------------------------- 

In short, class FlagAction extends ActionBase. ActionBase implements ExecutableInterface which defines a method ExecutableInterface::execute() with no arguments.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Executabl...

BUT

FlagAction overrides ExecutableInterface::execute() and adds 1 argument to the method.
This violates the contract of the interface, which phpstan doesn't like.

I'm opening this issue because it's not merely a matter of correcting a phpstan error, it involves an API to the FlagAction class and maybe some rethinking about how this action is defined and used.

πŸ› Bug report
Status

Active

Version

4.0

Component

Actions integration

Created by

πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tr
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    All action plugins work like that, I don't know why on top of my head.

    phpstan doesn't complain about the method, it complains about a call to it. Add the correct type and it should not complain anymore.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    OK, I added a @var to FlagActionTest and that removes the error. I added that to the MR in πŸ“Œ Add declare(strict_types=1) to all test modules Active , and am closing this issue since since this "fix" doesn't involve changing the plugin.

Production build 0.71.5 2024