Fix for minor PhpStan issue

Created on 18 December 2023, about 1 year ago
Updated 1 January 2024, 12 months ago

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

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ultimike Florida, USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024