librenms/librenms

View on GitHub
LibreNMS/DB/Eloquent.php

Summary

Maintainability
A
50 mins
Test Coverage

Method setConnection has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public static function setConnection($name, $db_host = null, $db_user = '', $db_pass = '', $db_name = '', $db_port = null, $db_socket = null): void
Severity: Major
Found in LibreNMS/DB/Eloquent.php - About 50 mins to fix

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

        public static function setStrictMode(bool $strict = true): void
    Severity: Minor
    Found in LibreNMS/DB/Eloquent.php by phpmd

    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

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

                } else {
                    self::DB()->getPdo()->exec("SET sql_mode=''");
                }
    Severity: Minor
    Found in LibreNMS/DB/Eloquent.php by phpmd

    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 using short method names like Eloquent::DB(). The configured minimum method name length is 3.
    Open

        public static function DB(?string $name = null): ?Connection
        {
            // check if Laravel is booted
            if (Laravel::isBooted()) {
                return DB::connection($name);
    Severity: Minor
    Found in LibreNMS/DB/Eloquent.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

    Source https://phpmd.org/rules/naming.html#shortmethodname

    The method DB is not named in camelCase.
    Open

        public static function DB(?string $name = null): ?Connection
        {
            // check if Laravel is booted
            if (Laravel::isBooted()) {
                return DB::connection($name);
    Severity: Minor
    Found in LibreNMS/DB/Eloquent.php by phpmd

    CamelCaseMethodName

    Since: 0.2

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

    Example

    class ClassName {
        public function get_name() {
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status