modxcms/revolution

View on GitHub
core/model/modx/moduser.class.php

Summary

Maintainability
F
6 days
Test Coverage

File moduser.class.php has 559 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * This file is part of MODX Revolution.
 *
 * Copyright (c) MODX, LLC. All Rights Reserved.
Severity: Major
Found in core/model/modx/moduser.class.php - About 1 day to fix

    modUser has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class modUser extends modPrincipal {
        /** @var modX|xPDO $xpdo */
        public $xpdo;
        /**
         * A collection of contexts which the current principal is authenticated in.
    Severity: Minor
    Found in core/model/modx/moduser.class.php - About 4 hrs to fix

      Function loadAttributes has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function loadAttributes($target, $context = '', $reload = false) {
              $context = !empty($context) ? $context : $this->xpdo->context->get('key');
              $id = $this->get('id') ? (string) $this->get('id') : '0';
              if ($this->get('id') && !$reload) {
                  $staleContexts = $this->get('session_stale');
      Severity: Minor
      Found in core/model/modx/moduser.class.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 activatePassword has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          public function activatePassword($key) {
              $activated = -1;
              if ($this->get('cachepwd')) {
                  if ($this->xpdo->getService('registry', 'registry.modRegistry') && $this->xpdo->registry->getRegister('user', 'registry.modDbRegister')) {
                      if ($this->xpdo->registry->user->connect()) {
      Severity: Minor
      Found in core/model/modx/moduser.class.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 removeLocks has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public function removeLocks(array $options = array()) {
              $removed = false;
              if ($this->xpdo instanceof modX) {
                  if ($this->xpdo->getService('registry', 'registry.modRegistry')) {
                      $this->xpdo->registry->addRegister('locks', 'registry.modDbRegister', array('directory' => 'locks'));
      Severity: Minor
      Found in core/model/modx/moduser.class.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 getSessionContexts has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getSessionContexts() {
              if (!is_array($this->sessionContexts) || empty ($this->sessionContexts)) {
                  $this->sessionContexts= array ();
                  if (isset ($_SESSION['modx.user.contextTokens'])) {
                      $this->sessionContexts= $_SESSION['modx.user.contextTokens'];
      Severity: Minor
      Found in core/model/modx/moduser.class.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 joinGroup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function joinGroup($groupId,$roleId = null,$rank = null) {
              $joined = false;
      
              $groupPk = is_string($groupId) ? array('name' => $groupId) : $groupId;
              /** @var modUserGroup $userGroup */
      Severity: Minor
      Found in core/model/modx/moduser.class.php - About 1 hr to fix

        Method loadAttributes has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function loadAttributes($target, $context = '', $reload = false) {
                $context = !empty($context) ? $context : $this->xpdo->context->get('key');
                $id = $this->get('id') ? (string) $this->get('id') : '0';
                if ($this->get('id') && !$reload) {
                    $staleContexts = $this->get('session_stale');
        Severity: Minor
        Found in core/model/modx/moduser.class.php - About 1 hr to fix

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

              public function joinGroup($groupId,$roleId = null,$rank = null) {
                  $joined = false;
          
                  $groupPk = is_string($groupId) ? array('name' => $groupId) : $groupId;
                  /** @var modUserGroup $userGroup */
          Severity: Minor
          Found in core/model/modx/moduser.class.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 addSessionContext has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public function addSessionContext($context) {
                  if (!$this->xpdo->startSession()) {
                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempt to start a session failed", '', __METHOD__, __FILE__, __LINE__);
                      return;
                  }
          Severity: Minor
          Found in core/model/modx/moduser.class.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 removeSessionContext has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function removeSessionContext($context) {
                  if ($this->getSessionContexts()) {
                      $contextToken= array ();
                      if (is_array($context)) {
                          foreach ($context as $ctx) {
          Severity: Minor
          Found in core/model/modx/moduser.class.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 addSessionContext has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function addSessionContext($context) {
                  if (!$this->xpdo->startSession()) {
                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempt to start a session failed", '', __METHOD__, __FILE__, __LINE__);
                      return;
                  }
          Severity: Minor
          Found in core/model/modx/moduser.class.php - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                                    if ($key === reset($msgs)) {
                                        $this->_setRaw('password', $this->get('cachepwd'));
                                        $this->_setRaw('cachepwd', '');
                                        $activated = $this->save();
                                    }
            Severity: Major
            Found in core/model/modx/moduser.class.php - About 45 mins to fix

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

                  public function getUserGroups() {
                      $groups= array();
                      $id = $this->get('id') ? (string) $this->get('id') : '0';
                      if (isset($_SESSION["modx.user.{$id}.userGroups"]) && $this->xpdo->user->get('id') == $this->get('id')) {
                          $groups= $_SESSION["modx.user.{$id}.userGroups"];
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function isMember($groups,$matchAll = false) {
                      $isMember= false;
                      $groupNames= $this->getUserGroupNames();
                      if ($groupNames) {
                          if (is_array($groups)) {
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function getUserGroupNames() {
                      $groupNames= array();
                      $id = $this->get('id') ? (string) $this->get('id') : '0';
                      if (isset($_SESSION["modx.user.{$id}.userGroupNames"]) && $this->xpdo->user->get('id') == $this->get('id')) {
                          $groupNames= $_SESSION["modx.user.{$id}.userGroupNames"];
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function hasSessionContext($context) {
                      $hasContext= false;
                      if ($this->getSessionContexts()) {
                          $contextTokens= array ();
                          if (is_array($context)) {
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function set($k, $v= null, $vType= '') {
                      if (!$this->getOption(xPDO::OPT_SETUP)) {
                          if ($k == 'sudo') return false;
                      }
                      if (in_array($k, array('password', 'cachepwd')) && $this->xpdo->getService('hashing', 'hashing.modHashing')) {
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function changePassword($newPassword, $oldPassword, $validateOldPassword = true) {
                      $changed= false;
                      $changePassword = $validateOldPassword ? $this->passwordMatches($oldPassword) : true;
                      if ($changePassword) {
                          if (!empty ($newPassword)) {
              Severity: Minor
              Found in core/model/modx/moduser.class.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

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

                  public function getResourceGroups($ctx = '') {
                      if (empty($ctx) && is_object($this->xpdo->context)) $ctx = $this->xpdo->context->get('key');
                      $resourceGroups= array ();
                      $id = $this->get('id') ? (string) $this->get('id') : '0';
                      if (isset($_SESSION["modx.user.{$id}.resourceGroups"][$ctx])) {
              Severity: Minor
              Found in core/model/modx/moduser.class.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

                  public function getUserGroups() {
                      $groups= array();
                      $id = $this->get('id') ? (string) $this->get('id') : '0';
                      if (isset($_SESSION["modx.user.{$id}.userGroups"]) && $this->xpdo->user->get('id') == $this->get('id')) {
                          $groups= $_SESSION["modx.user.{$id}.userGroups"];
              Severity: Major
              Found in core/model/modx/moduser.class.php and 1 other location - About 4 hrs to fix
              core/model/modx/moduser.class.php on lines 617..631

              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 173.

              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

                  public function getUserGroupNames() {
                      $groupNames= array();
                      $id = $this->get('id') ? (string) $this->get('id') : '0';
                      if (isset($_SESSION["modx.user.{$id}.userGroupNames"]) && $this->xpdo->user->get('id') == $this->get('id')) {
                          $groupNames= $_SESSION["modx.user.{$id}.userGroupNames"];
              Severity: Major
              Found in core/model/modx/moduser.class.php and 1 other location - About 4 hrs to fix
              core/model/modx/moduser.class.php on lines 573..587

              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 173.

              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

                  public function isMember($groups,$matchAll = false) {
                      $isMember= false;
                      $groupNames= $this->getUserGroupNames();
                      if ($groupNames) {
                          if (is_array($groups)) {
              Severity: Major
              Found in core/model/modx/moduser.class.php and 1 other location - About 3 hrs to fix
              core/model/modx/modresource.class.php on lines 1331..1350

              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 146.

              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 3 locations. Consider refactoring.
              Open

                  public function remove(array $ancestors = array()) {
                      if ($this->xpdo instanceof modX) {
                          $this->xpdo->invokeEvent('OnUserBeforeRemove',array(
                              'user' => &$this,
                              'ancestors' => $ancestors,
              Severity: Major
              Found in core/model/modx/moduser.class.php and 2 other locations - About 1 hr to fix
              core/model/modx/modresourcegroup.class.php on lines 58..76
              core/model/modx/moduserprofile.class.php on lines 81..100

              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 102.

              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