Refactor legacy code and fix phpcs issues

Created on 4 October 2023, almost 2 years ago

Problem/Motivation

There is currently a lot of unnecessary legacy code and a lot of phpcs issues.

An example of legacy code would be the implementation of "auto_username_user_insert". Instead of simply calling
$user->setUsername($new_name) we access the database and change the name there.

Here is a list of the phpcs issue to additionally fix:

E.E....E.E.... 14 / 14 (100%)



FILE: /var/www/html/web/modules/custom/auto_username/src/Form/AutoUsernameSettingsForm.php
------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
------------------------------------------------------------------------------------------------------------------------
  11 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is
     |         |     Drupal\auto_username\AutoUsernameUtilities.
  18 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
  35 | ERROR   | [ ] Missing short description in doc comment
 287 | ERROR   | [x] Expected 1 blank line after function; 2 found
 290 | ERROR   | [x] The closing brace for the class must have an empty line before it
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/custom/auto_username/src/AutoUsernameUtilities.php
------------------------------------------------------------------------------------------------------------------------
FOUND 48 ERRORS AND 33 WARNINGS AFFECTING 49 LINES
------------------------------------------------------------------------------------------------------------------------
  16 | ERROR   | [x] Missing class doc comment
  18 | ERROR   | [ ] Missing short description in doc comment
  23 | ERROR   | [ ] Missing short description in doc comment
  28 | ERROR   | [ ] Missing short description in doc comment
  33 | ERROR   | [ ] Missing short description in doc comment
  38 | ERROR   | [ ] Missing short description in doc comment
  43 | ERROR   | [ ] Missing short description in doc comment
  48 | ERROR   | [ ] Missing short description in doc comment
  56 | ERROR   | [ ] Missing parameter comment
  57 | ERROR   | [ ] Missing parameter comment
  58 | ERROR   | [ ] Missing parameter comment
  59 | ERROR   | [ ] Missing parameter comment
  60 | ERROR   | [ ] Missing parameter comment
  61 | ERROR   | [ ] Missing parameter comment
  62 | ERROR   | [ ] Missing parameter comment
 121 | ERROR   | [ ] The array declaration extends to column 99 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 121 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 122 | ERROR   | [ ] The array declaration extends to column 113 (the limit is 80). The array content should be split
     |         |     up over multiple lines
 122 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 123 | ERROR   | [ ] The array declaration extends to column 86 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 123 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 124 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 124 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 125 | ERROR   | [ ] The array declaration extends to column 83 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 125 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 126 | ERROR   | [ ] The array declaration extends to column 83 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 126 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 127 | ERROR   | [ ] The array declaration extends to column 87 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 127 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 128 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 128 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 129 | ERROR   | [ ] The array declaration extends to column 86 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 129 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 130 | ERROR   | [ ] The array declaration extends to column 96 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 130 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 131 | ERROR   | [ ] The array declaration extends to column 95 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 131 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 132 | ERROR   | [ ] The array declaration extends to column 96 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 132 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 133 | ERROR   | [ ] The array declaration extends to column 96 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 133 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 134 | ERROR   | [ ] The array declaration extends to column 97 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 134 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 135 | ERROR   | [ ] The array declaration extends to column 86 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 135 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 136 | ERROR   | [ ] The array declaration extends to column 87 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 136 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 137 | ERROR   | [ ] The array declaration extends to column 85 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 137 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 138 | ERROR   | [ ] The array declaration extends to column 86 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 138 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 139 | ERROR   | [ ] The array declaration extends to column 89 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 139 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 140 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 140 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 141 | ERROR   | [ ] The array declaration extends to column 88 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 141 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 142 | ERROR   | [ ] The array declaration extends to column 107 (the limit is 80). The array content should be split
     |         |     up over multiple lines
 142 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 143 | ERROR   | [ ] The array declaration extends to column 84 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 143 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 144 | ERROR   | [ ] The array declaration extends to column 93 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 144 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 145 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 145 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 146 | ERROR   | [ ] The array declaration extends to column 93 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 146 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 147 | ERROR   | [ ] The array declaration extends to column 94 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 147 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 148 | ERROR   | [ ] The array declaration extends to column 90 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 148 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 149 | ERROR   | [ ] The array declaration extends to column 91 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 149 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 150 | ERROR   | [ ] The array declaration extends to column 94 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 150 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 151 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 151 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 152 | ERROR   | [ ] The array declaration extends to column 87 (the limit is 80). The array content should be split up
     |         |     over multiple lines
 152 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 203 | WARNING | [ ] The use of function eval() is discouraged
 325 | ERROR   | [ ] The array declaration extends to column 89 (the limit is 80). The array content should be split up
     |         |     over multiple lines
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/custom/auto_username/config/install/auto_username.settings.yml
----------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
 11 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/custom/auto_username/auto_username.module
------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 10 WARNINGS AFFECTING 7 LINES
------------------------------------------------------------------------------------------------------------------------
 13 | WARNING | [ ] All constants defined by a module must be prefixed with the module's name, expected
    |         |     "AUTO_USERNAME_AUN_CASE_LEAVE_ASIS" but found "AUN_CASE_LEAVE_ASIS"
 13 | WARNING | [ ] Global constants should not be used, move it to a class or interface
 18 | WARNING | [ ] All constants defined by a module must be prefixed with the module's name, expected
    |         |     "AUTO_USERNAME_AUN_CASE_LOWER" but found "AUN_CASE_LOWER"
 18 | WARNING | [ ] Global constants should not be used, move it to a class or interface
 23 | WARNING | [ ] All constants defined by a module must be prefixed with the module's name, expected
    |         |     "AUTO_USERNAME_AUN_PUNCTUATION_REMOVE" but found "AUN_PUNCTUATION_REMOVE"
 23 | WARNING | [ ] Global constants should not be used, move it to a class or interface
 28 | WARNING | [ ] All constants defined by a module must be prefixed with the module's name, expected
    |         |     "AUTO_USERNAME_AUN_PUNCTUATION_REPLACE" but found "AUN_PUNCTUATION_REPLACE"
 28 | WARNING | [ ] Global constants should not be used, move it to a class or interface
 33 | WARNING | [ ] All constants defined by a module must be prefixed with the module's name, expected
    |         |     "AUTO_USERNAME_AUN_PUNCTUATION_DO_NOTHING" but found "AUN_PUNCTUATION_DO_NOTHING"
 33 | WARNING | [ ] Global constants should not be used, move it to a class or interface
 63 | ERROR   | [x] Short array syntax must be used to define arrays
 93 | ERROR   | [x] Expected 1 newline at end of file; 3 found
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Proposed resolution

Refactor legacy code and fix phpcs issues.

Remaining tasks

User interface changes

API changes

Data model changes

šŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

šŸ‡©šŸ‡ŖGermany Grevil

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