Class property DI naming

Created on 1 December 2024, 25 days ago

Problem/Motivation

During MR review (https://git.drupalcode.org/project/crop/-/merge_requests/18#note_419455) I faced with interesting case.
Is there policy for property naming when using DI?
Because it can help to prevent injecting same service multiple times.

In core service name converted to camelCase property name.
But I was not able to find any policy regarding property naming.

Example

  form_validator:
    class: Drupal\Core\Form\FormValidator
    arguments: ['@request_stack', '@string_translation', '@csrf_token', '@logger.channel.form', '@form_error_handler']
  # Drupal\Core\Form\FormValidator

  public function __construct(RequestStack $request_stack, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, FormErrorHandlerInterface $form_error_handler) {
    $this->requestStack = $request_stack;
    $this->stringTranslation = $string_translation;
    $this->csrfToken = $csrf_token;
    $this->logger = $logger;
    $this->formErrorHandler = $form_error_handler;
  }

Steps to reproduce

Proposed resolution

  • Update documentation about property naming with DI.
  • (Optional) Create coder rule to check property name equals to service name.

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

8.3

Component

Review/Rules

Created by

🇷🇺Russia zniki.ru

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

Comments & Activities

Production build 0.71.5 2024