Function makeAliveBlacklistFile
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function makeAliveBlacklistFile(&$aliveBlacklists)
{
if (!array_key_exists('blHostName', $aliveBlacklists[0]))
throw new MxToolboxRuntimeException("Cannot found index ['blHostName'] in array. Build test array first.");
- 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
Remove error control operator '@' on line 118. Open
public function deleteAliveBlacklist()
{
if (empty($this->blacklistPath))
$this->setBlacklistFilePath();
$blAliveFile = $this->blacklistPath . 'blacklistsAlive.txt';
- Read upRead up
- Exclude checks
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
Remove error control operator '@' on line 98. Open
public function makeAliveBlacklistFile(&$aliveBlacklists)
{
if (!array_key_exists('blHostName', $aliveBlacklists[0]))
throw new MxToolboxRuntimeException("Cannot found index ['blHostName'] in array. Build test array first.");
- Read upRead up
- Exclude checks
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
Remove error control operator '@' on line 86. Open
public function makeAliveBlacklistFile(&$aliveBlacklists)
{
if (!array_key_exists('blHostName', $aliveBlacklists[0]))
throw new MxToolboxRuntimeException("Cannot found index ['blHostName'] in array. Build test array first.");
- Read upRead up
- Exclude checks
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 setBlacklistFilePath has a boolean flag argument $path, which is a certain sign of a Single Responsibility Principle violation. Open
public function setBlacklistFilePath($path=false)
- Read upRead up
- Exclude checks
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
Avoid assigning values to variables in if clauses and the like (line '59', column '15'). Open
public function loadBlacklistsFromFile($fileName)
{
// user not defined any path
if (empty($this->blacklistPath))
$this->setBlacklistFilePath();
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '86', column '15'). Open
public function makeAliveBlacklistFile(&$aliveBlacklists)
{
if (!array_key_exists('blHostName', $aliveBlacklists[0]))
throw new MxToolboxRuntimeException("Cannot found index ['blHostName'] in array. Build test array first.");
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}