Problem/Motivation
While most phpcs issues are being fixed by
📌
Fix the issues reported by phpcs
Needs review
, I feel this one requires special attention:
FILE: ...evelopment/ddev/accessbyref-3357621/web/modules/contrib/access_by_ref/src/Controller/AbrconfigListBuilder.php
-------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------
78 | WARNING | Only string literals should be passed to t() where possible
-------------------------------------------------------------------------------------------------------------------
This is caused by the ABR Config page, which displays help text on how to use the module.
Steps to reproduce
Checkout the 3357621-phpcs-fixes branch.
Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig web/modules/contrib/access_by_ref/
Proposed resolution
There are several approaches that could be taken:
- Ignore the warning
We could decide a variable is the best way to deal with this text and ignore this warning. If we do this, we could prefix the line with // phpcs:ignore
- Change to a single string
The we could combine the concatenated string into a single multi-line string, possibly using PHP's <<< END
syntax.
- Use multiple t() calls
Instead of a single translate call on the whole message, we could break into individual paragraphs and translate each separately.
- Move text out of the code
We could take the text out of the class, and specify a template for the render array. We could then move the text into a .twig template. Text in .twig can be translated with {% trans %}
tags.
Having this much text in a PHP class seems sub-optimal to me, so moving to a template would seem a cleaner approach to me, but I'd like to hear opinions before I implement.
Remaining tasks
User interface changes
API changes
Data model changes