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.
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.
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');
- Read upRead up
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()) {
- Read upRead up
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'));
- Read upRead up
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'];
- Read upRead up
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 */
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');
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 */
- Read upRead up
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;
}
- Read upRead up
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) {
- Read upRead up
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;
}
Avoid deeply nested control flow statements. Open
if ($key === reset($msgs)) {
$this->_setRaw('password', $this->get('cachepwd'));
$this->_setRaw('cachepwd', '');
$activated = $this->save();
}
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"];
- Read upRead up
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)) {
- Read upRead up
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"];
- Read upRead up
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)) {
- Read upRead up
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')) {
- Read upRead up
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)) {
- Read upRead up
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])) {
- Read upRead up
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"];
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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"];
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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,
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76