studioespresso/craft-seo-fields

View on GitHub
src/models/NotFoundModel.php

Summary

Maintainability
A
0 mins
Test Coverage

The method getRedirect uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $redirect = RedirectRecord::findOne(['id' => $this->redirect]);
            return $redirect;
        }
Severity: Minor
Found in src/models/NotFoundModel.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Avoid using static access to class '\studioespresso\seofields\records\RedirectRecord' in method 'getRedirect'.
Open

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

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Define a constant instead of duplicating this literal "dateLastHit" 4 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.

Define a constant instead of duplicating this literal "siteId" 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.

Define a constant instead of duplicating this literal "handled" 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.

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

Class extends undeclared class \craft\base\Model
Open

class NotFoundModel extends Model
Severity: Critical
Found in src/models/NotFoundModel.php by phan

Static call to undeclared method \studioespresso\seofields\records\RedirectRecord::findOne
Open

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

Reference to constant class from undeclared class \craft\validators\DateTimeValidator
Open

            ['dateLastHit', DateTimeValidator::class],
Severity: Critical
Found in src/models/NotFoundModel.php by phan

Avoid variables with short names like $id. Configured minimum length is 3.
Open

    public $id;
Severity: Minor
Found in src/models/NotFoundModel.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Line exceeds 120 characters; contains 182 characters
Open

                ['id', 'counter', 'fullUrl', 'urlPath', 'referrer', 'urlParams', 'dateLastHit', 'handled', 'siteId', 'redirect', 'dateLastHit', 'dateCreated', 'dateUpdated'], 'safe',
Severity: Minor
Found in src/models/NotFoundModel.php by phpcodesniffer

There are no issues that match your filters.

Category
Status