studioespresso/craft-seo-fields

View on GitHub

Showing 1,008 of 1,021 total issues

Remove the code after this "return".
Open

                return false;
Severity: Major
Found in src/services/SitemapService.php by sonar-php

Jump statements (return, break, continue, and goto) and throw expressions move control flow out of the current code block. Typically, any statements in a block that come after a jump or throw are simply wasted keystrokes lying in wait to confuse the unwary.

Rarely, as illustrated below, code after a jump or throw is reachable. However, such code is difficult to understand, and should be refactored.

Noncompliant Code Example

function fun($a) {
  $i = 10;
  return $i + $a;
  $i++;             // this is never executed
}

function foo($a) {
  if ($a == 5) {
    goto error;
  } else {
    // do the job
  }
  return;

  error:
    printf("don't use 5"); // this is reachable but unreadable

}

Compliant Solution

function fun($a) {
  $i = 10;
  return $i + $a;
}

function foo($a) {
  if ($a == 5) {
    handleError();
  } else {
    // do the job
  }
  return;
}

See

  • MISRA C:2004, 14.1 - There shall be no unreachable code
  • MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
  • MISRA C++:2008, 0-1-9 - There shall be no dead code
  • MISRA C:2012, 2.1 - A project shall not contain unreachable code
  • MISRA C:2012, 2.2 - There shall be no dead code
  • MITRE, CWE-561 - Dead Code
  • CERT, MSC56-J. - Detect and remove superfluous code and values
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC07-CPP. - Detect and remove dead code

Define a constant instead of duplicating this literal "CASCADE" 3 times.
Open

            'CASCADE'
Severity: Critical
Found in src/migrations/Install.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 "counter" 3 times.
Open

                ['counter', 'url', 'dateLastHit', 'handled', 'siteId'], 'required',
Severity: Critical
Found in src/models/NotFoundModel.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.

Rename "$redirect" which has the same name as the field declared at line 44.
Open

            $redirect = RedirectRecord::findOne(['id' => $this->redirect]);
Severity: Major
Found in src/models/NotFoundModel.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Define a constant instead of duplicating this literal "pattern" 4 times.
Open

            'pattern' => Craft::$app->getRequest()->getParam('pattern') ?? null,

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 "filename" 3 times.
Open

            $variables['filename'] = $filePath;

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.

Remove this commented out code.
Open

        //$headers = $reader->fetchOne(0);

Programmers should not comment out code as it bloats programs and reduces readability.

Unused code should be deleted and can be retrieved from source control history if required.

See

  • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
  • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
  • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
  • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

Define a constant instead of duplicating this literal "_index_site" 3 times.
Open

                self::SITEMAP_CACHE_KEY . '_index_site' . $currentSite->id,
Severity: Critical
Found in src/services/SitemapService.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