Admidio/admidio

View on GitHub
adm_program/system/classes/User.php

Summary

Maintainability
F
1 wk
Test Coverage

File User.php has 1210 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
use Admidio\Exception;

/**
 * @brief Class handle role rights, cards and other things of users
Severity: Major
Found in adm_program/system/classes/User.php - About 3 days to fix

    User has 68 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class User extends TableAccess
    {
        public const MAX_INVALID_LOGINS = 3;
    
        /**
    Severity: Major
    Found in adm_program/system/classes/User.php - About 1 day to fix

      Function checkRolesRight has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
      Open

          public function checkRolesRight(string $right = null): bool
          {
              $sqlFetchedRows = array();
      
              if ((int)$this->getValue('usr_id') === 0) {
      Severity: Minor
      Found in adm_program/system/classes/User.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 delete has 128 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function delete(): bool
          {
              global $gChangeNotification;
      
              $usrId = $this->getValue('usr_id');
      Severity: Major
      Found in adm_program/system/classes/User.php - About 5 hrs to fix

        Method checkRolesRight has 110 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function checkRolesRight(string $right = null): bool
            {
                $sqlFetchedRows = array();
        
                if ((int)$this->getValue('usr_id') === 0) {
        Severity: Major
        Found in adm_program/system/classes/User.php - About 4 hrs to fix

          Function getVCard has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getVCard(): string
              {
                  global $gSettingsManager, $gCurrentUser, $gL10n;
          
                  $vCard = array(
          Severity: Minor
          Found in adm_program/system/classes/User.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

          Function hasRightEditProfile has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
          Open

              public function hasRightEditProfile(self $user, bool $checkOwnProfile = true): bool
              {
                  $usrId = (int)$this->getValue('usr_id');
                  $userId = (int)$user->getValue('usr_id');
          
          
          Severity: Minor
          Found in adm_program/system/classes/User.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

          Method getVCard has 93 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getVCard(): string
              {
                  global $gSettingsManager, $gCurrentUser, $gL10n;
          
                  $vCard = array(
          Severity: Major
          Found in adm_program/system/classes/User.php - About 3 hrs to fix

            Function setValue has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

                public function setValue(string $columnName, $newValue, bool $checkValue = true): bool
                {
                    global $gSettingsManager, $gChangeNotification;
            
                    // users data from adm_users table
            Severity: Minor
            Found in adm_program/system/classes/User.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 setValue has 58 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function setValue(string $columnName, $newValue, bool $checkValue = true): bool
                {
                    global $gSettingsManager, $gChangeNotification;
            
                    // users data from adm_users table
            Severity: Major
            Found in adm_program/system/classes/User.php - About 2 hrs to fix

              Consider simplifying this complex logical expression.
              Open

                      if (($categoryType === 'ANN' && $this->editAnnouncements())
                          || ($categoryType === 'EVT' && $this->editEvents())
                          || ($categoryType === 'LNK' && $this->editWeblinksRight())
                          || ($categoryType === 'USF' && $this->editUsers())
                          || ($categoryType === 'ROL' && $this->assignRoles())) {
              Severity: Critical
              Found in adm_program/system/classes/User.php - About 2 hrs to fix

                Consider simplifying this complex logical expression.
                Open

                        if (($categoryType === 'ANN' && $this->editAnnouncements())
                            || ($categoryType === 'EVT' && $this->editEvents())
                            || ($categoryType === 'LNK' && $this->editWeblinksRight())
                            || ($categoryType === 'USF' && $this->editUsers())
                            || ($categoryType === 'ROL' && $this->manageRoles())) {
                Severity: Critical
                Found in adm_program/system/classes/User.php - About 2 hrs to fix

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

                      public function searchSimilarUsers(): array
                      {
                          global $gSettingsManager;
                  
                          $foundUserIds = array();
                  Severity: Minor
                  Found in adm_program/system/classes/User.php - About 1 hr to fix

                    Method hasRightViewProfile has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function hasRightViewProfile(self $user): bool
                        {
                            global $gValidLogin;
                    
                            // if user is allowed to edit the profile then he can also view it
                    Severity: Minor
                    Found in adm_program/system/classes/User.php - About 1 hr to fix

                      Method getAllVisibleCategories has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getAllVisibleCategories(string $categoryType): array
                          {
                              $queryParams = array($categoryType, $this->organizationId);
                      
                              if (($categoryType === 'ANN' && $this->editAnnouncements())
                      Severity: Minor
                      Found in adm_program/system/classes/User.php - About 1 hr to fix

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

                            public function checkLogin(string $password, bool $setAutoLogin = false, bool $updateSessionCookies = true, bool $updateHash = true, bool $isAdministrator = false): bool
                            {
                                global $gSettingsManager, $gCurrentSession, $installedDbVersion;
                        
                                if ($this->hasMaxInvalidLogins()) {
                        Severity: Minor
                        Found in adm_program/system/classes/User.php - About 1 hr to fix

                          Method save has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function save(bool $updateFingerPrint = true): bool
                              {
                                  global $gCurrentSession, $gCurrentUser, $gChangeNotification;
                          
                                  $usrId = $this->getValue('usr_id');
                          Severity: Minor
                          Found in adm_program/system/classes/User.php - About 1 hr to fix

                            Method hasRightEditProfile has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function hasRightEditProfile(self $user, bool $checkOwnProfile = true): bool
                                {
                                    $usrId = (int)$this->getValue('usr_id');
                                    $userId = (int)$user->getValue('usr_id');
                            
                            
                            Severity: Minor
                            Found in adm_program/system/classes/User.php - About 1 hr to fix

                              Function getAllEditableCategories has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function getAllEditableCategories(string $categoryType): array
                                  {
                                      $queryParams = array($categoryType, $this->organizationId);
                              
                                      if (($categoryType === 'ANN' && $this->editAnnouncements())
                              Severity: Minor
                              Found in adm_program/system/classes/User.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

                              Function hasRightViewProfile has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function hasRightViewProfile(self $user): bool
                                  {
                                      global $gValidLogin;
                              
                                      // if user is allowed to edit the profile then he can also view it
                              Severity: Minor
                              Found in adm_program/system/classes/User.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

                              Function getAllVisibleCategories has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function getAllVisibleCategories(string $categoryType): array
                                  {
                                      $queryParams = array($categoryType, $this->organizationId);
                              
                                      if (($categoryType === 'ANN' && $this->editAnnouncements())
                              Severity: Minor
                              Found in adm_program/system/classes/User.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 setPassword has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function setPassword(string $newPassword, bool $doHashing = true): bool
                                  {
                                      global $gSettingsManager, $gPasswordHashAlgorithm, $gChangeNotification;
                              
                                      if (!$doHashing) {
                              Severity: Minor
                              Found in adm_program/system/classes/User.php - About 1 hr to fix

                                Method getAllEditableCategories has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function getAllEditableCategories(string $categoryType): array
                                    {
                                        $queryParams = array($categoryType, $this->organizationId);
                                
                                        if (($categoryType === 'ANN' && $this->editAnnouncements())
                                Severity: Minor
                                Found in adm_program/system/classes/User.php - About 1 hr to fix

                                  Function checkLogin has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function checkLogin(string $password, bool $setAutoLogin = false, bool $updateSessionCookies = true, bool $updateHash = true, bool $isAdministrator = false): bool
                                      {
                                          global $gSettingsManager, $gCurrentSession, $installedDbVersion;
                                  
                                          if ($this->hasMaxInvalidLogins()) {
                                  Severity: Minor
                                  Found in adm_program/system/classes/User.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

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

                                      public function save(bool $updateFingerPrint = true): bool
                                      {
                                          global $gCurrentSession, $gCurrentUser, $gChangeNotification;
                                  
                                          $usrId = $this->getValue('usr_id');
                                  Severity: Minor
                                  Found in adm_program/system/classes/User.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

                                  Consider simplifying this complex logical expression.
                                  Open

                                          if ((int)$gSettingsManager->get('groups_roles_show_former_members') !== 1
                                              && ($this->checkRolesRight('rol_assign_roles')
                                                  || ($this->isLeaderOfRole($roleId) && in_array($this->rolesMembershipLeader[$roleId], array(1, 3), true)))) {
                                              return true;
                                          } elseif ((int)$gSettingsManager->get('groups_roles_show_former_members') !== 2
                                  Severity: Major
                                  Found in adm_program/system/classes/User.php - About 1 hr to fix

                                    Function setPassword has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function setPassword(string $newPassword, bool $doHashing = true): bool
                                        {
                                            global $gSettingsManager, $gPasswordHashAlgorithm, $gChangeNotification;
                                    
                                            if (!$doHashing) {
                                    Severity: Minor
                                    Found in adm_program/system/classes/User.php - About 45 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

                                    Consider simplifying this complex logical expression.
                                    Open

                                            if (($this->getValue('usr_id') === 0 && $GLOBALS['gCurrentUserId'] === 0)
                                                || (int)$this->mProfileFieldsData->getProperty($columnName, 'usf_disabled') === 0
                                                || ((int)$this->mProfileFieldsData->getProperty($columnName, 'usf_disabled') === 1
                                                    && $GLOBALS['gCurrentUser']->hasRightEditProfile($this, false))
                                                || $this->saveChangesWithoutRights === true) {
                                    Severity: Major
                                    Found in adm_program/system/classes/User.php - About 40 mins to fix

                                      Method checkLogin has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                          public function checkLogin(string $password, bool $setAutoLogin = false, bool $updateSessionCookies = true, bool $updateHash = true, bool $isAdministrator = false): bool
                                      Severity: Minor
                                      Found in adm_program/system/classes/User.php - About 35 mins to fix

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

                                            public function hasRightViewFormerRolesMembers(int $roleId): bool
                                            {
                                                global $gSettingsManager;
                                        
                                                if ((int)$gSettingsManager->get('groups_roles_show_former_members') !== 1
                                        Severity: Minor
                                        Found in adm_program/system/classes/User.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 true;
                                        Severity: Major
                                        Found in adm_program/system/classes/User.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return false;
                                          Severity: Major
                                          Found in adm_program/system/classes/User.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                                return true;
                                            Severity: Major
                                            Found in adm_program/system/classes/User.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return true;
                                              Severity: Major
                                              Found in adm_program/system/classes/User.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                        return $returnCode;
                                                Severity: Major
                                                Found in adm_program/system/classes/User.php - About 30 mins to fix

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

                                                      private function checkRelationshipsRights(): bool
                                                      {
                                                          global $gSettingsManager;
                                                  
                                                          if ((int)$this->getValue('usr_id') === 0 || !$gSettingsManager->getBool('contacts_user_relations_enabled')) {
                                                  Severity: Minor
                                                  Found in adm_program/system/classes/User.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

                                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                                  Open

                                                                      if ((int)$sqlRow['rol_view_members_profiles'] === TableRoles::VIEW_ROLE_MEMBERS && $sqlRow['mem_usr_id'] > 0) {
                                                                          // only role members are allowed to view memberships
                                                                          $this->rolesViewProfiles[] = $roleId;
                                                                          $this->rolesViewProfilesUUID[] = $roleUUID;
                                                                      } elseif ((int)$sqlRow['rol_view_members_profiles'] === TableRoles::VIEW_LOGIN_USERS) {
                                                  Severity: Major
                                                  Found in adm_program/system/classes/User.php and 1 other location - About 4 hrs to fix
                                                  adm_program/system/classes/User.php on lines 323..339

                                                  Duplicated Code

                                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                  Tuning

                                                  This issue has a mass of 166.

                                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                  Refactorings

                                                  Further Reading

                                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                                  Open

                                                                      if ((int)$sqlRow['rol_view_memberships'] === TableRoles::VIEW_ROLE_MEMBERS && $sqlRow['mem_usr_id'] > 0) {
                                                                          // only role members are allowed to view memberships
                                                                          $this->rolesViewMemberships[] = $roleId;
                                                                          $this->rolesViewMembershipsUUID[] = $roleUUID;
                                                                      } elseif ((int)$sqlRow['rol_view_memberships'] === TableRoles::VIEW_LOGIN_USERS) {
                                                  Severity: Major
                                                  Found in adm_program/system/classes/User.php and 1 other location - About 4 hrs to fix
                                                  adm_program/system/classes/User.php on lines 342..358

                                                  Duplicated Code

                                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                  Tuning

                                                  This issue has a mass of 166.

                                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                  Refactorings

                                                  Further Reading

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status