LibreNMS/Alert/Transport/Mail.php
Method configTemplate
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static function configTemplate(): array
{
$roles = array_merge(['None' => ''], \Bouncer::role()->pluck('name', 'title')->all());
return [
The method deliverAlert uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
// fix line returns for windows mail clients
$msg = preg_replace("/(?<!\r)\n/", "\r\n", $alert_data['msg']);
}
- Read upRead up
- Exclude checks
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
Open
<?php
- Exclude checks
Possible parse error: class missing opening or closing brace Open
Open
class Mail extends Transport
- Exclude checks
Possible parse error: class missing opening or closing brace Open
Open
class Mail extends Transport
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
$emails = match ($this->config['mail-contact'] ?? '') {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 12 Open
Open
default => $this->config['email'],
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
Open
public function deliverAlert(array $alert_data): bool
- Exclude checks
Closing brace indented incorrectly; expected 4 spaces, found 0 Open
Open
}
- Exclude checks