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
User
has 68 functions (exceeds 20 allowed). Consider refactoring. Open
class User extends TableAccess
{
public const MAX_INVALID_LOGINS = 3;
/**
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) {
- 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 delete
has 128 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function delete(): bool
{
global $gChangeNotification;
$usrId = $this->getValue('usr_id');
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) {
Function getVCard
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function getVCard(): string
{
global $gSettingsManager, $gCurrentUser, $gL10n;
$vCard = array(
- 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 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');
- 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 getVCard
has 93 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getVCard(): string
{
global $gSettingsManager, $gCurrentUser, $gL10n;
$vCard = array(
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
- 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 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
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())) {
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())) {
Method searchSimilarUsers
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function searchSimilarUsers(): array
{
global $gSettingsManager;
$foundUserIds = array();
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
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())
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()) {
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');
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');
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())
- 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 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
- 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 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())
- 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 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) {
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())
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()) {
- 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 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');
- 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
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
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) {
- 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
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) {
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
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
- 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
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $returnCode;
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')) {
- 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
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) {
- 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 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
- 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
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) {
- 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 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
- 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