attogram/8queens

View on GitHub

Showing 248 of 248 total issues

TODO found
Open

// TODO: this whole function could probably be replaced with a single regex
Severity: Minor
Found in inc/cjs030/js/chessboard-0.3.0.js by fixme

TODO found
Open

// TODO: write this, GitHub Issue #5
Severity: Minor
Found in inc/cjs030/js/chessboard-0.3.0.js by fixme

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.

Either remove or fill this block of code.
Open

    for ($i = $size - 1; @$row[$i] >= @$row[$i+1]; --$i) {
    }
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.

Variable $this is undeclared
Open

        <a href="<?= $this->router->getHome(); ?>">Play 8 Queens</a>
Severity: Minor
Found in src/footer.php by phan

Invalid operator: left operand of - is array (expected number)
Open

        while ($bitShift < ($board - $checkRow)) {
Severity: Minor
Found in src/solve8queens_2.php by phan

Cannot assign void return value
Open

$start = startTimer();
Severity: Info
Found in src/solutions.php by phan

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;
}

Reduce the number of returns of this function 9, down to the maximum allowed 3.
Open

function numtoalpha($number)
Severity: Major
Found in src/solve8queens_2.php by sonar-php

Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

Noncompliant Code Example

With the default threshold of 3:

function myFunction(){ // Noncompliant as there are 4 return statements
  if (condition1) {
    return true;
  } else {
    if (condition2) {
      return false;
    } else {
      return true;
    }
  }
  return false;
}

Variable $this is undeclared
Open

         &nbsp;|&nbsp; <a href="<?= $this->router->getHome(); ?>solutions/">Finding solutions in PHP</a>
Severity: Minor
Found in src/footer.php by phan

Variable $this is undeclared
Open

         &nbsp;|&nbsp; <a href="<?= $this->router->getHome(); ?>92/">The 92 solutions</a>
Severity: Minor
Found in src/footer.php by phan

Argument 2 (board) is 8 but \checkBoard() takes array defined at /code/src/solve8queens_2.php:171
Open

        if (checkBoard($row, $board)) {
Severity: Minor
Found in src/solve8queens_2.php by phan

Move this "case default" clause to the end of this "switch" statement.
Open

        default:
Severity: Critical
Found in src/status.php by sonar-php

The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

Noncompliant Code Example

switch ($param) {  //missing default clause
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

switch ($param) {
  default: // default clause should be the last one
    error();
    break;
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

Compliant Solution

switch ($param) {
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
  default:
    error();
    break;
}

See

  • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
  • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
  • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
  • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
  • MISRA C:2012, 16.1 - All switch statements shall be well-formed
  • MISRA C:2012, 16.4 - Every switch statement shall have a default label
  • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
  • MITRE, CWE-478 - Missing Default Case in Switch Statement
  • CERT, MSC01-C. - Strive for logical completeness
  • CERT, MSC01-CPP. - Strive for logical completeness

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

Cannot assign void return value
Open

$start = startTimer();
Severity: Info
Found in src/solutions.php by phan

Variable $tmp was undeclared, but array fields are being added to it.
Open

        $tmp[strlen(decbin($row[$checkRow])) - 1] = 1 << ($board - $checkRow - 1);
Severity: Info
Found in src/solve8queens_2.php by phan

Variable $result was undeclared, but array fields are being added to it.
Open

        $result[$name] = $value + $arrayB[$name];
Severity: Info
Found in src/solve8queens.php by phan

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.

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

Returning type void but numtoalpha() is declared to return string
Open

            return;
Severity: Minor
Found in src/solve8queens_2.php by phan
Severity
Category
Status
Source
Language