Showing 248 of 248 total issues
Either remove this useless object instantiation of class "EightQueens" or use it Open
new EightQueens();
- Read upRead up
- Exclude checks
There is no good reason to create a new object to not do anything with it. Most of the time, this is due to a missing piece of code and so could lead to an unexpected behavior in production.
If it was done on purpose because the constructor has side-effects, then that side-effect code should be moved into a separate, static method and called directly.
Noncompliant Code Example
if ($x < 0) { new foo; // Noncompliant }
Compliant Solution
$var = NULL; if ($x < 0) { $var = new foo; }
Variable $this
is undeclared Open
| <a href="<?= $this->router->getHome(); ?>about/">About the 8 Queens Puzzle</a>
- Exclude checks
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed. Open
function queens_under_attack($board)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Invalid operator: left operand of -
is array
(expected number) Open
while ($bitShift < ($board - $checkRow)) {
- Exclude checks
Either remove or fill this block of code. Open
for ($j = $size; $row[$j] <= $row[$i]; --$j) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Merge this if statement with the enclosing one. Open
if (!in_array($row, $solutions)) {
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Define a constant instead of duplicating this literal "<div style="border:1px solid black;padding:10px;height:300px;overflow:auto;">" 3 times.</div> Open
print '<div style="border:1px solid black;padding:10px;height:300px;overflow:auto;">';
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "" 5 times. Open
print '</div>';
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.