attogram/8queens

View on GitHub

Showing 248 of 248 total issues

Either remove this useless object instantiation of class "EightQueens" or use it
Open

new EightQueens();
Severity: Major
Found in index.php by sonar-php

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

         &nbsp;|&nbsp; <a href="<?= $this->router->getHome(); ?>about/">About the 8 Queens Puzzle</a>
Severity: Minor
Found in src/footer.php by phan

Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
Open

function queens_under_attack($board)
Severity: Critical
Found in src/status.php by sonar-php

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)) {
Severity: Minor
Found in src/solve8queens_2.php by phan

Either remove or fill this block of code.
Open

    for ($j = $size; $row[$j] <= $row[$i]; --$j) {
    }
Severity: Major
Found in src/solve8queens_2.php by sonar-php

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)) {
Severity: Major
Found in src/solve8queens_2.php by sonar-php

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;">';
Severity: Critical
Found in src/solutions.php by sonar-php

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>';
Severity: Critical
Found in src/solutions.php by sonar-php

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.

Severity
Category
Status
Source
Language