Settings form code improvements

Created on 1 June 2024, 6 months ago
Updated 14 June 2024, 5 months ago

Problem/Motivation

The SpamMasterSettingsForm has a large amount of repeated and inefficient code in the buildForm() method, particularly for compiling the information that is displayed. This makes the code harder to read, more prone to little bugs or issues and is generally harder to maintain in the long run.

This code was the primary reason the issue at https://www.drupal.org/project/spammaster/issues/3448819 🐛 TypeError: Unsupported operand types: bool + string in Drupal\spammaster\Form\SpamMasterSettingsForm->buildForm() (line 689 of modules/contrib/spammaster/src/Form/SpamMasterSettingsForm.php) Fixed occurred, because it was hard to spot the place where it was using a "+" instead of a "." to concatenate text. If the strings had been put into an array, then the array could have simply been imploded, which is shorter and easier to read and guarantees that all the values would be properly concatenated. Furthermore, the array could simply omit any text values that did not need to be displayed at all, rather than setting an empty or falsey value.

This is just one example, but there are various other improvements that can be made to the code for compiling the display information.

Proposed resolution

Refactor the code to break it down into more individual functions for compiling the various pieces of information about the spam master service to display. Eliminate repetitive code, particularly all the text strings that are the same in multiple cases and make better use of Drupal core services and PHP functions to compile the text to be displayed.

📌 Task
Status

Fixed

Version

2.45

Component

Code

Created by

🇨🇦Canada teknocat

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