Remove as many getters and setters as possible from the Project class, in favor of public, typed properties

Created on 9 January 2024, 12 months ago
Updated 12 March 2024, 10 months ago

Problem/Motivation

The \Drupal\project_browser\ProjectBrowser\Project class comprises an army of getters and setters that really just access private properties.

Now that PHP supports typed, readonly properties, I'm not sure we really need this stuff. I would suggest we replace as many getters and setters as possible with public, typed properties. We could even use constructor property promotion, which would allow calls like this:

new Project(
  isCompatible: true,
  isMaintained: true,
  isActive: true,
  projectUsageTotal: 39,
);

...lots of flexibility is available to us. And we can remove a lot of boilerplate.

The outstanding questions:

  • ANSWER: There may or may not be reason to mutate them, but let's keep them mutable for now to keep the current behavior intact. Making them read-only has backwards compatibility implications.
  • ANSWER: Only setSummary() needed this treatment, since it has actual logic. The other properties didn't, so they are good candidates for just becoming public.
āœØ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

šŸ‡ŗšŸ‡øUnited States phenaproxima Massachusetts

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