I am not certain if it is allowed by coding standards but it looks a bit weird and inconsistent with other files.


use Drupal\Component\Utility\Crypt;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;

/**
 * @file
 * Enables the user registration and login system.
 */

https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/8

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Chi created an issue. See original summary.

joshi.rohit100’s picture

Status: Active » Needs review
FileSize
657 bytes
Lars Toomre’s picture

When this file user.module is run through PHP_CodeSniffer using the Drupal standard, approximately thirty additional issues with this one file are flagged as errors or warnings. Does it make sense to repurpose this issue to clean up the additional issues in this one file? I think it does.

Lars Toomre’s picture

Attached are the sniffs that result from checking user.module with code_sniffer:

FILE: D:\Webs\tcm-dru8\core\modules\user\user.module
----------------------------------------------------------------------
FOUND 31 ERRORS AND 9 WARNINGS AFFECTING 35 LINES
----------------------------------------------------------------------
    1 | ERROR   | [x] Missing file doc comment
      |         |     (Drupal.Commenting.FileComment.Missing)
   45 | ERROR   | [ ] Doc comment short description must be on a single
      |         |     line, further text should be a separate paragraph
      |         |     (Drupal.Commenting.DocComment.ShortSingleLine)
   67 | ERROR   | [x] Expected 1 space between "':accounts'" and double
      |         |     arrow; 2 found
      |         |     (Squiz.Arrays.ArrayDeclaration.SpaceBeforeDoubleArrow)
   69 | ERROR   | [ ] If the line declaring an array spans longer than 80
      |         |     characters, each element should be broken into its own
      |         |     line (Drupal.Array.Array.LongLineDeclaration)
   69 | ERROR   | [x] Expected 1 space between "':field_help'" and double
      |         |     arrow; 0 found
      |         |     (Squiz.Arrays.ArrayDeclaration.NoSpaceBeforeDoubleArrow)
   69 | ERROR   | [x] Expected 1 space between double arrow and "("; 0
      |         |     found
      |         |     (Squiz.Arrays.ArrayDeclaration.NoSpaceAfterDoubleArrow)
   69 | ERROR   | [x] Expected 1 space before "=>"; 0 found
      |         |     (Drupal.WhiteSpace.OperatorSpacing.NoSpaceBefore)
   69 | ERROR   | [x] Expected 1 space after "=>"; 0 found
      |         |     (Drupal.WhiteSpace.OperatorSpacing.NoSpaceAfter)
  102 | ERROR   | [ ] If the line declaring an array spans longer than 80
      |         |     characters, each element should be broken into its own
      |         |     line (Drupal.Array.Array.LongLineDeclaration)
  158 | WARNING | [ ] Avoid backslash escaping in translatable strings
      |         |     when possible, use "" quotes instead
      |         |     (Drupal.Semantics.FunctionT.BackslashSingleQuote)
  227 | ERROR   | [x] Separate the @param and @return sections by a blank
      |         |     line.
      |         |     (Drupal.Commenting.DocComment.TagGroupSpacing)
  243 | ERROR   | [x] Separate the @param and @return sections by a blank
      |         |     line.
      |         |     (Drupal.Commenting.DocComment.TagGroupSpacing)
  264 | ERROR   | [x] Additional blank lines found at end of doc
      |         |     comment (Drupal.Commenting.DocComment.SpacingAfter)
  368 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  380 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  397 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  453 | ERROR   | [x] Parameter comment indentation must be 3 spaces,
      |         |     found 1 spaces
      |         |     (Drupal.Commenting.FunctionComment.ParamCommentIndentation)
  454 | ERROR   | [x] Parameter comment indentation must be 3 spaces,
      |         |     found 1 spaces
      |         |     (Drupal.Commenting.FunctionComment.ParamCommentIndentation)
  463 | WARNING | [ ] Do not concatenate strings to translatable strings,
      |         |     they should be part of the t() argument and you should
      |         |     use placeholders
      |         |     (Drupal.Semantics.FunctionT.ConcatString)
  579 | ERROR   | [ ] Type hint "\Drupal\user\UserInterface" missing for
      |         |     $account
      |         |     (Drupal.Commenting.FunctionComment.TypeHintMissing)
  590 | WARNING | [x] A comma should follow the last multiline array
      |         |     item. Found: ) (Drupal.Array.Array.CommaLastItem)
  619 | WARNING | [x] A comma should follow the last multiline array
      |         |     item. Found: ) (Drupal.Array.Array.CommaLastItem)
  689 | ERROR   | [ ] If the line declaring an array spans longer than 80
      |         |     characters, each element should be broken into its own
      |         |     line (Drupal.Array.Array.LongLineDeclaration)
  720 | ERROR   | [x] There must be exactly one blank line before the
      |         |     tags in a doc comment
      |         |     (Drupal.Commenting.DocComment.SpacingBeforeTags)
  729 | ERROR   | [ ] Type hint "\Drupal\user\UserInterface" missing for
      |         |     $account
      |         |     (Drupal.Commenting.FunctionComment.TypeHintMissing)
  883 | ERROR   | [ ] Type hint "\Drupal\user\UserInterface" missing for
      |         |     $account
      |         |     (Drupal.Commenting.FunctionComment.TypeHintMissing)
  893 | ERROR   | [ ] Parameter comment must end with a full stop
      |         |     (Drupal.Commenting.FunctionComment.ParamCommentFullStop)
  919 | ERROR   | [ ] If the line declaring an array spans longer than 80
      |         |     characters, each element should be broken into its own
      |         |     line (Drupal.Array.Array.LongLineDeclaration)
  978 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
 1015 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
 1099 | ERROR   | [x] Expected 1 space after asterisk; 3 found
      |         |     (Squiz.Commenting.DocCommentAlignment.SpaceAfterStar)
 1107 | ERROR   | [x] Expected 1 space after asterisk; 3 found
      |         |     (Squiz.Commenting.DocCommentAlignment.SpaceAfterStar)
 1169 | ERROR   | [ ] Doc comment short description must be on a single
      |         |     line, further text should be a separate paragraph
      |         |     (Drupal.Commenting.DocComment.ShortSingleLine)
 1184 | ERROR   | [ ] Parameter tags must be grouped together in a doc
      |         |     comment (Drupal.Commenting.DocComment.ParamGroup)
 1187 | ERROR   | [ ] Parameter tags must be grouped together in a doc
      |         |     comment (Drupal.Commenting.DocComment.ParamGroup)
 1197 | ERROR   | [ ] Type hint "\Drupal\Core\Session\AccountInterface"
      |         |     missing for $account
      |         |     (Drupal.Commenting.FunctionComment.TypeHintMissing)
 1337 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found
      |         |     5 (Drupal.WhiteSpace.ScopeIndent.IncorrectExact)
 1338 | ERROR   | [x] Array indentation error, expected 7 spaces but
      |         |     found 6 (Drupal.Array.Array.ArrayIndentation)
 1342 | ERROR   | [x] Line indented incorrectly; expected at least 5
      |         |     spaces, found 4
      |         |     (Drupal.WhiteSpace.ScopeIndent.Incorrect)
 1342 | ERROR   | [x] Array closing indentation error, expected 5 spaces
      |         |     but found 4
      |         |     (Drupal.Array.Array.ArrayClosingIndentation)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 20 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Edit: Added tags to clean up spacing.

cilefen’s picture

Title: user.module - move file doc comment block to the top of the file » user.module coding standards cleanup
Status: Needs review » Needs work

Yes, why not do it all?

Lars Toomre’s picture

Attached is a WIP patch that addresses many of the sniffs from #4. I did not touch any of the 'Implements hook_foo() warnings. There are also a couple of the sniffs that are giving what I think are false positives.

This file then also needs a careful read through to catch the active verb tense at the start of docblocks and that all of the (optional) variables have been documented as such (along with their default values).

Here are the coder_sniffer summary after applying this patch:

FILE: D:\Webs\tcm-dru8\core\modules\user\user.module
----------------------------------------------------------------------
FOUND 3 ERRORS AND 6 WARNINGS AFFECTING 9 LINES
----------------------------------------------------------------------
  378 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  390 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  407 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
  473 | WARNING | [ ] Do not concatenate strings to translatable strings,
      |         |     they should be part of the t() argument and you should
      |         |     use placeholders
      |         |     (Drupal.Semantics.FunctionT.ConcatString)
  700 | ERROR   | [ ] If the line declaring an array spans longer than 80
      |         |     characters, each element should be broken into its own
      |         |     line (Drupal.Array.Array.LongLineDeclaration)
  994 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
 1031 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
      |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
      |         |     Implements hook_foo_BAR_ID_bar() for
      |         |     xyz-bar.html.twig.", or "* Implements
      |         |     hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".
      |         |     (Drupal.Commenting.HookComment)
 1115 | ERROR   | [x] Expected 1 space after asterisk; 3 found
      |         |     (Squiz.Commenting.DocCommentAlignment.SpaceAfterStar)
 1123 | ERROR   | [x] Expected 1 space after asterisk; 3 found
      |         |     (Squiz.Commenting.DocCommentAlignment.SpaceAfterStar)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Lars Toomre’s picture

Status: Needs work » Needs review

Forgot to update the status.

anish.a’s picture

Assigned: Unassigned » anish.a
anish.a’s picture

Issue tags: +drupalconasia2016

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

anish.a’s picture

Much of the issues mentioned in the diff are already fixed according to the coder module check I have made.

Adding the patch for issues I could fix. Checked out from 8.2.x branch.

markdorison’s picture

Status: Needs review » Needs work
FileSize
3.95 KB

Re-rolled against 8.2.x.

markdorison’s picture

Status: Needs work » Needs review
markdorison’s picture

Assigned: anish.a » Unassigned
Mile23’s picture

Status: Needs review » Reviewed & tested by the community

Heads-up that we're fixing coding standards by sniff over here: #2571965: [meta] Fix PHP coding standards in core

  1. +++ b/core/modules/user/src/Form/UserPermissionsForm.php
    @@ -100,7 +100,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -    $options = array();
    
    @@ -145,7 +144,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -        $options[$perm] = $perm_item['title'];
    
    @@ -158,7 +156,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -        $options[$perm] = '';
    

    $options seems to be unused in this method, so +1.

  2. +++ b/core/modules/user/src/Tests/UserAdminTest.php
    @@ -174,8 +174,8 @@ function testNotificationEmailAddress() {
    -    $edit['name'] = $name = $this->randomMachineName();
    -    $edit['mail'] = $mail = $edit['name'] . '@example.com';
    +    $edit['name'] = $this->randomMachineName();
    +    $edit['mail'] = $edit['name'] . '@example.com';
    

    $name and $mail are never used, so +1.

  3. +++ b/core/modules/user/tests/src/Kernel/UserAccountFormFieldsTest.php
    @@ -135,7 +135,7 @@ protected function buildAccountForm($operation) {
    -    $form_object = $this->container->get('entity.manager')
    +    $this->container->get('entity.manager')
    

    $form_object is not used so +1.

alexpott’s picture

Title: user.module coding standards cleanup » Remove unused variables in user.module
Status: Reviewed & tested by the community » Needs work

Thank you for your work on cleaning up Drupal core's code style!

+++ b/core/modules/user/src/AccountForm.php
@@ -312,7 +312,6 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
     //   called twice, we have to prevent it from getting the array keys twice.
-
     if (is_string(key($form_state->getValue('roles')))) {

+++ b/core/modules/user/src/Form/UserPermissionsForm.php
@@ -100,7 +100,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
-    $options = array();

This is two different things. The removal of the blank line is a coding standard that should be fixed in a maintainable way, all our coding standards issues should be done on a per-rule basis across all of core, rather than fixing standards in individual modules or files. We should also separate fixes where we need to write new documentation from fixes where we need to correct existing standards. This all should be done as part of #2571965: [meta] Fix PHP coding standards in core. A good place to start is the child issues of #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard.

For background information on why we usually will not commit coding standards fixes that aren't scoped in that way, see the core issue scope guidelines, especially the note about coding standards cleanups. That document also includes numerous suggestions for scoping issues including documentation coding standards cleanups.

Contributing to the overall plan above will help ensure that your fixes for core's coding standards remain in core the long term.

This issue can focus on the second task of removing unused variables because whilst this is automatable we have no current plans to try to do this with coder and also the review needs to check the code code to ensure that it truly is unused so simpler patch contexts are better.

chgasparoto’s picture

Status: Needs work » Needs review
FileSize
703 bytes
3.27 KB

Applied changes suggested by #16.
Please review it.

Mile23’s picture

Status: Needs review » Reviewed & tested by the community

See review in #15, which still applies. The out-of-scope CS change is gone.

Looks good.

There are still unused variables in user module, but they are for constructs like foreach ($array as $key=>$unused).

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x, thanks!

  • catch committed ee76fe4 on 8.2.x
    Issue #2624822 by chgasparoto, Lars Toomre, markdorison, anish.a, joshi....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.