librenms/librenms

View on GitHub
LibreNMS/Authentication/ADAuthorizationAuthorizer.php

Summary

Maintainability
A
3 hrs
Test Coverage

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

    public function getRoles(string $username): array|false
    {
        $roles = $this->authLdapSessionCacheGet('roles');
        if ($roles !== null) {
            return $roles;
Severity: Minor
Found in LibreNMS/Authentication/ADAuthorizationAuthorizer.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 __construct has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function __construct()
    {
        if (! function_exists('ldap_connect')) {
            throw new LdapMissingException();
        }
Severity: Minor
Found in LibreNMS/Authentication/ADAuthorizationAuthorizer.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 getRoles has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getRoles(string $username): array|false
    {
        $roles = $this->authLdapSessionCacheGet('roles');
        if ($roles !== null) {
            return $roles;
Severity: Minor
Found in LibreNMS/Authentication/ADAuthorizationAuthorizer.php - About 1 hr to fix

    The method userExists has a boolean flag argument $throw_exception, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function userExists($username, $throw_exception = false)

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Remove error control operator '@' on line 33.
    Open

        public function __construct()
        {
            if (! function_exists('ldap_connect')) {
                throw new LdapMissingException();
            }

    ErrorControlOperator

    Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

    Example

    function foo($filePath) {
        $file = @fopen($filPath); // hides exceptions
        $key = @$array[$notExistingKey]; // assigns null to $key
    }

    Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

    The method getUserid uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $user_id = -1;
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                // Anonymous
                if (! ldap_bind($this->ldap_connection)) {
                    echo ldap_error($this->ldap_connection);
                }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Avoid unused parameters such as '$throw_exception'.
    Open

        public function userExists($username, $throw_exception = false)

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    The property $ldap_connection is not named in camelCase.
    Open

    class ADAuthorizationAuthorizer extends MysqlAuthorizer
    {
        use LdapSessionCache;
        use ActiveDirectoryCommon;
    
    

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $AUTH_IS_EXTERNAL is not named in camelCase.
    Open

    class ADAuthorizationAuthorizer extends MysqlAuthorizer
    {
        use LdapSessionCache;
        use ActiveDirectoryCommon;
    
    

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $CAN_UPDATE_PASSWORDS is not named in camelCase.
    Open

    class ADAuthorizationAuthorizer extends MysqlAuthorizer
    {
        use LdapSessionCache;
        use ActiveDirectoryCommon;
    
    

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    There are no issues that match your filters.

    Category
    Status