wikimedia/mediawiki-core

View on GitHub
includes/specials/SpecialUserRights.php

Summary

Maintainability
F
1 wk
Test Coverage

File SpecialUserRights.php has 783 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Implements Special:Userrights
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/specials/SpecialUserRights.php - About 1 day to fix

    Function groupCheckboxes has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
    Open

        private function groupCheckboxes( $usergroups, $user ) {
            $allgroups = $this->userGroupManager->listAllGroups();
            $ret = '';
    
            // Get the list of preset expiry times from the system message
    Severity: Minor
    Found in includes/specials/SpecialUserRights.php - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method groupCheckboxes has 143 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function groupCheckboxes( $usergroups, $user ) {
            $allgroups = $this->userGroupManager->listAllGroups();
            $ret = '';
    
            // Get the list of preset expiry times from the system message
    Severity: Major
    Found in includes/specials/SpecialUserRights.php - About 5 hrs to fix

      Method showEditUserGroupsForm has 136 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function showEditUserGroupsForm( $user, $groups, $groupMemberships ) {
              $list = $membersList = $tempList = $tempMembersList = [];
              foreach ( $groupMemberships as $ugm ) {
                  $linkG = UserGroupMembership::getLinkHTML( $ugm, $this->getContext() );
                  $linkM = UserGroupMembership::getLinkHTML( $ugm, $this->getContext(), $user->getName() );
      Severity: Major
      Found in includes/specials/SpecialUserRights.php - About 5 hrs to fix

        Function saveUserGroups has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function saveUserGroups( $reason, $user ) {
                if ( $this->userNameUtils->isTemp( $user->getName() ) ) {
                    return Status::newFatal( 'userrights-no-tempuser' );
                }
                $allgroups = $this->userGroupManager->listAllGroups();
        Severity: Minor
        Found in includes/specials/SpecialUserRights.php - About 4 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method execute has 97 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function execute( $par ) {
                $user = $this->getUser();
                $request = $this->getRequest();
                $session = $request->getSession();
                $out = $this->getOutput();
        Severity: Major
        Found in includes/specials/SpecialUserRights.php - About 3 hrs to fix

          Function fetchUser has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
          Open

              public function fetchUser( $username, $writing = true ) {
                  $parts = explode( $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ),
                      $username );
                  if ( count( $parts ) < 2 ) {
                      $name = trim( $username );
          Severity: Minor
          Found in includes/specials/SpecialUserRights.php - About 3 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function execute has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              public function execute( $par ) {
                  $user = $this->getUser();
                  $request = $this->getRequest();
                  $session = $request->getSession();
                  $out = $this->getOutput();
          Severity: Minor
          Found in includes/specials/SpecialUserRights.php - About 3 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          SpecialUserRights has 24 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class SpecialUserRights extends SpecialPage {
              /**
               * The target of the local right-adjuster's interest.  Can be gotten from
               * either a GET parameter or a subpage-style parameter, so have a member
               * variable for it.
          Severity: Minor
          Found in includes/specials/SpecialUserRights.php - About 2 hrs to fix

            Method doSaveUserGroups has 65 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function doSaveUserGroups( $user, array $add, array $remove, $reason = '',
                    array $tags = [], array $groupExpiries = []
                ) {
                    // Validate input set...
                    $isself = $user->getName() == $this->getUser()->getName();
            Severity: Major
            Found in includes/specials/SpecialUserRights.php - About 2 hrs to fix

              Function doSaveUserGroups has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function doSaveUserGroups( $user, array $add, array $remove, $reason = '',
                      array $tags = [], array $groupExpiries = []
                  ) {
                      // Validate input set...
                      $isself = $user->getName() == $this->getUser()->getName();
              Severity: Minor
              Found in includes/specials/SpecialUserRights.php - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method fetchUser has 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function fetchUser( $username, $writing = true ) {
                      $parts = explode( $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ),
                          $username );
                      if ( count( $parts ) < 2 ) {
                          $name = trim( $username );
              Severity: Major
              Found in includes/specials/SpecialUserRights.php - About 2 hrs to fix

                Method saveUserGroups has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function saveUserGroups( $reason, $user ) {
                        if ( $this->userNameUtils->isTemp( $user->getName() ) ) {
                            return Status::newFatal( 'userrights-no-tempuser' );
                        }
                        $allgroups = $this->userGroupManager->listAllGroups();
                Severity: Minor
                Found in includes/specials/SpecialUserRights.php - About 1 hr to fix

                  Function showEditUserGroupsForm has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function showEditUserGroupsForm( $user, $groups, $groupMemberships ) {
                          $list = $membersList = $tempList = $tempMembersList = [];
                          foreach ( $groupMemberships as $ugm ) {
                              $linkG = UserGroupMembership::getLinkHTML( $ugm, $this->getContext() );
                              $linkM = UserGroupMembership::getLinkHTML( $ugm, $this->getContext(), $user->getName() );
                  Severity: Minor
                  Found in includes/specials/SpecialUserRights.php - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method switchForm has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function switchForm() {
                          $this->getOutput()->addModules( 'mediawiki.userSuggest' );
                  
                          $this->getOutput()->addHTML(
                              Html::openElement(
                  Severity: Minor
                  Found in includes/specials/SpecialUserRights.php - About 1 hr to fix

                    Method addLogEntry has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        protected function addLogEntry( $user, array $oldGroups, array $newGroups, $reason,
                            array $tags, array $oldUGMs, array $newUGMs
                    Severity: Major
                    Found in includes/specials/SpecialUserRights.php - About 50 mins to fix

                      Method doSaveUserGroups has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public function doSaveUserGroups( $user, array $add, array $remove, $reason = '',
                              array $tags = [], array $groupExpiries = []
                      Severity: Minor
                      Found in includes/specials/SpecialUserRights.php - About 45 mins to fix

                        Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                                UserGroupManagerFactory $userGroupManagerFactory = null,
                                UserNameUtils $userNameUtils = null,
                                UserNamePrefixSearch $userNamePrefixSearch = null,
                                UserFactory $userFactory = null,
                                ActorStoreFactory $actorStoreFactory = null,
                        Severity: Minor
                        Found in includes/specials/SpecialUserRights.php - About 45 mins to fix

                          Function userCanChangeRights has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function userCanChangeRights( UserIdentity $targetUser, $checkIfSelf = true ) {
                                  $isself = $this->getUser()->equals( $targetUser );
                          
                                  $userGroupManager = $this->userGroupManagerFactory
                                      ->getUserGroupManager( $targetUser->getWikiId() );
                          Severity: Minor
                          Found in includes/specials/SpecialUserRights.php - About 35 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Avoid too many return statements within this method.
                          Open

                                  return Status::newGood();
                          Severity: Major
                          Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return Status::newFatal( 'nosuchusershort', $username );
                            Severity: Major
                            Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return Status::newGood( $user );
                              Severity: Major
                              Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return Status::newFatal( 'userrights-no-group' );
                                Severity: Major
                                Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return Status::newFatal( 'nosuchusershort', $username );
                                  Severity: Major
                                  Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return Status::newFatal( 'nosuchusershort', $username );
                                    Severity: Major
                                    Found in includes/specials/SpecialUserRights.php - About 30 mins to fix

                                      There are no issues that match your filters.

                                      Category
                                      Status