wikimedia/mediawiki-core

View on GitHub
includes/user/UserGroupManager.php

Summary

Maintainability
F
6 days
Test Coverage

File UserGroupManager.php has 771 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/user/UserGroupManager.php - About 1 day to fix

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

        private function recCheckCondition( $cond, User $user ): bool {
            if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], self::VALID_OPS ) ) {
                // Recursive condition
                if ( $cond[0] == '&' ) { // AND (all conds pass)
                    foreach ( array_slice( $cond, 1 ) as $subcond ) {
    Severity: Minor
    Found in includes/user/UserGroupManager.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

    UserGroupManager has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UserGroupManager {
    
        /**
         * @internal For use by ServiceWiring
         */
    Severity: Minor
    Found in includes/user/UserGroupManager.php - About 3 hrs to fix

      Method addUserToGroup has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function addUserToGroup(
              UserIdentity $user,
              string $group,
              string $expiry = null,
              bool $allowUpdate = false
      Severity: Major
      Found in includes/user/UserGroupManager.php - About 3 hrs to fix

        Function addUserToGroup has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            public function addUserToGroup(
                UserIdentity $user,
                string $group,
                string $expiry = null,
                bool $allowUpdate = false
        Severity: Minor
        Found in includes/user/UserGroupManager.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

        Function getUserAutopromoteOnceGroups has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getUserAutopromoteOnceGroups(
                UserIdentity $user,
                string $event
            ): array {
                $user->assertWiki( $this->wikiId );
        Severity: Minor
        Found in includes/user/UserGroupManager.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 checkCondition has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function checkCondition( array $cond, User $user ): bool {
                if ( count( $cond ) < 1 ) {
                    return false;
                }
        
        
        Severity: Major
        Found in includes/user/UserGroupManager.php - About 2 hrs to fix

          Method addUserToAutopromoteOnceGroups has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function addUserToAutopromoteOnceGroups(
                  UserIdentity $user,
                  string $event
              ): array {
                  $user->assertWiki( $this->wikiId );
          Severity: Minor
          Found in includes/user/UserGroupManager.php - About 1 hr to fix

            Method purgeExpired has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function purgeExpired() {
                    if ( $this->readOnlyMode->isReadOnly( $this->wikiId ) ) {
                        return false;
                    }
            
            
            Severity: Minor
            Found in includes/user/UserGroupManager.php - About 1 hr to fix

              Method removeUserFromGroup has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function removeUserFromGroup( UserIdentity $user, string $group ): bool {
                      $user->assertWiki( $this->wikiId );
                      // TODO: Deprecate passing out user object in the hook by introducing
                      // an alternative hook
                      if ( $this->hookContainer->isRegistered( 'UserRemoveGroup' ) ) {
              Severity: Minor
              Found in includes/user/UserGroupManager.php - About 1 hr to fix

                Method recCheckCondition has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function recCheckCondition( $cond, User $user ): bool {
                        if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], self::VALID_OPS ) ) {
                            // Recursive condition
                            if ( $cond[0] == '&' ) { // AND (all conds pass)
                                foreach ( array_slice( $cond, 1 ) as $subcond ) {
                Severity: Minor
                Found in includes/user/UserGroupManager.php - About 1 hr to fix

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

                          ServiceOptions $options,
                          ReadOnlyMode $readOnlyMode,
                          ILBFactory $lbFactory,
                          HookContainer $hookContainer,
                          UserEditTracker $userEditTracker,
                  Severity: Major
                  Found in includes/user/UserGroupManager.php - About 1 hr to fix

                    Function getUserImplicitGroups has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getUserImplicitGroups(
                            UserIdentity $user,
                            int $queryFlags = IDBAccessObject::READ_NORMAL,
                            bool $recache = false
                        ): array {
                    Severity: Minor
                    Found in includes/user/UserGroupManager.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 getGroupsChangeableBy has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getGroupsChangeableBy( Authority $authority ): array {
                            if ( $authority->isAllowed( 'userrights' ) ) {
                                // This group gives the right to modify everything (reverse-
                                // compatibility with old "userrights lets you change
                                // everything")
                    Severity: Minor
                    Found in includes/user/UserGroupManager.php - About 1 hr to fix

                      Function checkCondition has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function checkCondition( array $cond, User $user ): bool {
                              if ( count( $cond ) < 1 ) {
                                  return false;
                              }
                      
                      
                      Severity: Minor
                      Found in includes/user/UserGroupManager.php - About 55 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

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

                          public function removeUserFromGroup( UserIdentity $user, string $group ): bool {
                              $user->assertWiki( $this->wikiId );
                              // TODO: Deprecate passing out user object in the hook by introducing
                              // an alternative hook
                              if ( $this->hookContainer->isRegistered( 'UserRemoveGroup' ) ) {
                      Severity: Minor
                      Found in includes/user/UserGroupManager.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 $this->recCheckCondition( $cond[1], $user )
                                          xor $this->recCheckCondition( $cond[2], $user );
                      Severity: Major
                      Found in includes/user/UserGroupManager.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return $age >= $reqAge;
                        Severity: Major
                        Found in includes/user/UserGroupManager.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return count( array_intersect( $groups, $this->getUserGroups( $user ) ) ) == count( $groups );
                          Severity: Major
                          Found in includes/user/UserGroupManager.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return true;
                            Severity: Major
                            Found in includes/user/UserGroupManager.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return $cond[1] == $user->getRequest()->getIP();
                              Severity: Major
                              Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return true;
                                Severity: Major
                                Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return $this->checkCondition( $cond, $user );
                                  Severity: Major
                                  Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return (bool)$result;
                                    Severity: Major
                                    Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                              return false;
                                      Severity: Major
                                      Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return (int)$this->userEditTracker->getUserEditCount( $user ) >= $reqEditCount;
                                        Severity: Major
                                        Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return IPUtils::isInRange( $user->getRequest()->getIP(), $cond[1] );
                                          Severity: Major
                                          Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return in_array( 'bot', $this->groupPermissionsLookup
                                                                ->getGroupPermissions( $this->getUserGroups( $user ) ) );
                                            Severity: Major
                                            Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                              return $age >= $cond[1];
                                              Severity: Major
                                              Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                return $block && $block->isSitewide();
                                                Severity: Major
                                                Found in includes/user/UserGroupManager.php - About 30 mins to fix

                                                  Function getUserGroupMemberships has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                      public function getUserGroupMemberships(
                                                          UserIdentity $user,
                                                          int $queryFlags = IDBAccessObject::READ_NORMAL
                                                      ): array {
                                                          $user->assertWiki( $this->wikiId );
                                                  Severity: Minor
                                                  Found in includes/user/UserGroupManager.php - About 25 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

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status