All injected services should be marked readonly

Created on 21 April 2023, over 1 year ago
Updated 3 May 2023, over 1 year ago

Problem/Motivation

Surfaced at ๐Ÿ“Œ Create a PreApply validator that prevents Drupal projects from being removed if they are enabled Fixed , specifically at https://git.drupalcode.org/project/automatic_updates/-/merge_requests/82....

Steps to reproduce

N/A

Proposed resolution

Services should never be modified after injection/object initialization. Therefore all injected services should not just be protected or private like they already are, but also readonly. The only exception is if a service can be injected using a setter, but AFAIK AU/PM don't do that anywhere.

Note that this would then also match the example established by Drupal core: \Drupal\Core\Asset\CssCollectionOptimizerLazy::__construct() was the first code in core to use constructor promotion, was written by release manager @catch, and also uses protected readonly SomethingInterface $something.

Remaining tasks

Do it!

User interface changes

None.

API changes

None.

Data model changes

None.

๐Ÿ“Œ Task
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

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

Comments & Activities

Production build 0.71.5 2024