librenms/librenms

View on GitHub
LibreNMS/Alert/Transport/Mail.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method configTemplate has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function configTemplate(): array
    {
        $roles = array_merge(['None' => ''], \Bouncer::role()->pluck('name', 'title')->all());

        return [
Severity: Minor
Found in LibreNMS/Alert/Transport/Mail.php - About 2 hrs to fix

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

            } else {
                // fix line returns for windows mail clients
                $msg = preg_replace("/(?<!\r)\n/", "\r\n", $alert_data['msg']);
            }
    Severity: Minor
    Found in LibreNMS/Alert/Transport/Mail.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

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 32 and the first side effect is on line 30.
    Open

    <?php

    Possible parse error: class missing opening or closing brace
    Open

    class Mail extends Transport

    Possible parse error: class missing opening or closing brace
    Open

    class Mail extends Transport

    Space before opening parenthesis of function call prohibited
    Open

            $emails = match ($this->config['mail-contact'] ?? '') {

    Line indented incorrectly; expected 4 spaces, found 12
    Open

                default => $this->config['email'],

    Line indented incorrectly; expected 0 spaces, found 4
    Open

        public function deliverAlert(array $alert_data): bool

    Closing brace indented incorrectly; expected 4 spaces, found 0
    Open

    }

    There are no issues that match your filters.

    Category
    Status