A common Drupal dependency injection pattern has create methods looking like this:
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('module_handler'),
);
}
This results in an "unsafe usage of new static()" PhpStan error. This can be fixed by marking the constructor as "final". Then, if anyone wants to subclass this class and add an additional dependency, they can use something like the following (no constructor in the subclass required):
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
$instance = parent::create($container, $plugin_id, $plugin_definition);
$instance->time = $container->get('datetime.time');
return $instance;
}
Additional info: https://www.drupaleasy.com/blogs/ultimike/2023/12/how-best-handle-unsafe...
So, this task is to remove "final" from the MarkdownEasy class and add it to the constructor in order to get a more clean PhpStan report.
-mike