File UserGroupManager.php
has 771 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Function recCheckCondition
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
private function recCheckCondition( $cond, User $user ): bool {
if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], self::VALID_OPS ) ) {
// Recursive condition
if ( $cond[0] == '&' ) { // AND (all conds pass)
foreach ( array_slice( $cond, 1 ) as $subcond ) {
- 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
UserGroupManager
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class UserGroupManager {
/**
* @internal For use by ServiceWiring
*/
Method addUserToGroup
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addUserToGroup(
UserIdentity $user,
string $group,
string $expiry = null,
bool $allowUpdate = false
Function addUserToGroup
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function addUserToGroup(
UserIdentity $user,
string $group,
string $expiry = null,
bool $allowUpdate = false
- 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 getUserAutopromoteOnceGroups
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function getUserAutopromoteOnceGroups(
UserIdentity $user,
string $event
): array {
$user->assertWiki( $this->wikiId );
- 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 checkCondition
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function checkCondition( array $cond, User $user ): bool {
if ( count( $cond ) < 1 ) {
return false;
}
Method addUserToAutopromoteOnceGroups
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addUserToAutopromoteOnceGroups(
UserIdentity $user,
string $event
): array {
$user->assertWiki( $this->wikiId );
Method purgeExpired
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function purgeExpired() {
if ( $this->readOnlyMode->isReadOnly( $this->wikiId ) ) {
return false;
}
Method removeUserFromGroup
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function removeUserFromGroup( UserIdentity $user, string $group ): bool {
$user->assertWiki( $this->wikiId );
// TODO: Deprecate passing out user object in the hook by introducing
// an alternative hook
if ( $this->hookContainer->isRegistered( 'UserRemoveGroup' ) ) {
Method recCheckCondition
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function recCheckCondition( $cond, User $user ): bool {
if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], self::VALID_OPS ) ) {
// Recursive condition
if ( $cond[0] == '&' ) { // AND (all conds pass)
foreach ( array_slice( $cond, 1 ) as $subcond ) {
Method __construct
has 11 arguments (exceeds 4 allowed). Consider refactoring. Open
ServiceOptions $options,
ReadOnlyMode $readOnlyMode,
ILBFactory $lbFactory,
HookContainer $hookContainer,
UserEditTracker $userEditTracker,
Function getUserImplicitGroups
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getUserImplicitGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL,
bool $recache = false
): array {
- 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 getGroupsChangeableBy
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getGroupsChangeableBy( Authority $authority ): array {
if ( $authority->isAllowed( 'userrights' ) ) {
// This group gives the right to modify everything (reverse-
// compatibility with old "userrights lets you change
// everything")
Function checkCondition
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function checkCondition( array $cond, User $user ): bool {
if ( count( $cond ) < 1 ) {
return false;
}
- 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 removeUserFromGroup
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function removeUserFromGroup( UserIdentity $user, string $group ): bool {
$user->assertWiki( $this->wikiId );
// TODO: Deprecate passing out user object in the hook by introducing
// an alternative hook
if ( $this->hookContainer->isRegistered( 'UserRemoveGroup' ) ) {
- 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 $this->recCheckCondition( $cond[1], $user )
xor $this->recCheckCondition( $cond[2], $user );
Avoid too many return
statements within this method. Open
return $age >= $reqAge;
Avoid too many return
statements within this method. Open
return count( array_intersect( $groups, $this->getUserGroups( $user ) ) ) == count( $groups );
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $cond[1] == $user->getRequest()->getIP();
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $this->checkCondition( $cond, $user );
Avoid too many return
statements within this method. Open
return (bool)$result;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return (int)$this->userEditTracker->getUserEditCount( $user ) >= $reqEditCount;
Avoid too many return
statements within this method. Open
return IPUtils::isInRange( $user->getRequest()->getIP(), $cond[1] );
Avoid too many return
statements within this method. Open
return in_array( 'bot', $this->groupPermissionsLookup
->getGroupPermissions( $this->getUserGroups( $user ) ) );
Avoid too many return
statements within this method. Open
return $age >= $cond[1];
Avoid too many return
statements within this method. Open
return $block && $block->isSitewide();
Function getUserGroupMemberships
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getUserGroupMemberships(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL
): array {
$user->assertWiki( $this->wikiId );
- 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"