Skip to content

Inconsistent use of self vs static in AutowireTrait #6470

@Sweetchuck

Description

@Sweetchuck

Describe the bug
The AutowireTrait collects the constructor arguments based on static, but the instance is created from self.

Drupal 11.2.8 uses static in both places.

To Reproduce

// NOT IN a directory where command discovery could find it.
abstract class MyCommandBase extends \Symfony\Component\Console\Command\Command {
  use \Drush\Commands\AutowireTrait;

   public function __construct(
    #[Autowire('logger')]
    protected LoggerInterface $logger,
  ) {
    parent::__construct();
  }

  // ...
}

// IN a directory where command discover can find it.
[\Symfony\Component\Console\Attribute\AsCommand(
  name: 'my:foo',
  description: 'my desc',
)]
final class FooCommand extends MyCommandBase {
  // ...
}

Expected behavior
Create a new command

Actual behavior
Fatal error exception:

Cannot instantiate abstract class MyCommandBase

Workaround
Every command MUST HAVE its own __construct() or use \Drush\Commands\AutowireTrait;.

System Configuration

Q A
Drush version? 13.7.0
Drupal version? 11.2.8
PHP version 8.3.x
OS? Linux

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