Problem/Motivation
While addressing the PHPCS/PHPStan errors as part of ticket:#3465396: Fix validate pipeline, a PHPStan ignore line was added for the following service call:
\Drupal::service("extension.list.$type")->getPathname($name);
To improve the codebase and adhere to best practices, we should replace this direct service call with the extension.path.resolver service object. This service object accepts extension_type and extension_name as arguments for method getPathName and returns the correct pathname, which aligns with our goal of fixing PHPStan error of avoiding \Drupal::service calls in the classes and increasing code maintainability.
Proposed resolution
- Modify the
config_update.config_listservice definition to adds theextension.path.resolverservice ias the last argument. - Refactor the
ConfigListerclass constructor to accept theextension.path.resolverservice object. - Update
listProvidedItemsmethod ofConfigListerclass and update\Drupal::service("extension.list.$type")service object. - Modify the
ConfigListerWithProvidersclass constructor to include theextension.path.resolverservice argument. - Ensure that the parent constructor is called correctly in
ConfigListerWithProvidersclass if it wasn't already. - Review and update any PHPUnit tests that are affected by these changes.
- Ensure that all tests pass without any PHPStan or PHPCS issues.
Remaining tasks
The ConfigLister class is a base class, and the ConfigListerWithProviders class extends it. Given that other contributed or custom modules might also have extended the ConfigLister class, so we should not make the extension.path.resolver service object a required argument in the ConfigLister class constructor. Instead, we should make it optional for now and include a deprecation notice stating that calling the __construct method of the ConfigLister class without passing the extension.path.resolver
Issue fork config_update-3467805
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments