studioespresso/craft-seo-fields

View on GitHub
src/controllers/RedirectsController.php

Summary

Maintainability
A
1 hr
Test Coverage

Function getSitesMenu has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private function getSitesMenu()
    {
        $sites = [
            0 => Craft::t('seo-fields', 'All Sites'),
        ];
Severity: Minor
Found in src/controllers/RedirectsController.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function actionSave has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function actionSave()
    {
        $id = $this->request->getBodyParam('redirectId');
        $record = $this->request->getBodyParam('record');
        if ($id) {
Severity: Minor
Found in src/controllers/RedirectsController.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $variables['filename'] = $filePath;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $variables['filename'] = $filePath;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $variables['headers'] = $headers;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $variables['sites'] = $this->getSitesMenu();

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $variables['headers'] = $headers;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

            $variables['filename'] = $filePath;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

        $this->renderTemplate('seo-fields/_redirect/_import', $variables);

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$variables' which will lead to PHP notices.
Open

            $variables['headers'] = $headers;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using static access to class '\craft\helpers\App' in method 'actionRunImport'.
Open

        App::maxPowerCaptain();

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

Avoid using static access to class '\League\Csv\Reader' in method 'actionRunImport'.
Open

        $reader = Reader::createFromPath($filePath);

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

Avoid using static access to class '\craft\helpers\UrlHelper' in method 'actionUpload'.
Open

        $this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));

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

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

        } else {
            $model = new RedirectModel();
        }

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 '\League\Csv\Reader' in method 'actionImport'.
Open

        $csv = Reader::createFromPath($filePath);

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

Avoid using static access to class '\yii\web\UploadedFile' in method 'actionUpload'.
Open

        $file = UploadedFile::getInstanceByName('file');

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

Avoid using static access to class '\League\Csv\Reader' in method 'actionUpload'.
Open

            $csv = Reader::createFromPath($file->tempName);

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

Avoid using static access to class '\Craft' in method 'actionSave'.
Open

                Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));

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

Avoid using static access to class '\Craft' in method 'getSitesMenu'.
Open

            0 => Craft::t('seo-fields', 'All Sites'),

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

Avoid using static access to class '\Craft' in method 'actionSave'.
Open

        Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));

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

Avoid using static access to class '\Craft' in method 'actionUpload'.
Open

            Craft::info(print_r($headers, true), __METHOD__);

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

Avoid using static access to class '\craft\helpers\UrlHelper' in method 'actionImport'.
Open

            return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));

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

Avoid using static access to class '\Craft' in method 'actionDelete'.
Open

            Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));

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

            'record' => Craft::$app->getRequest()->getParam('record') ?? 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 "seo-fields/_redirect/_entry" 3 times.
Open

        return $this->renderTemplate('seo-fields/_redirect/_entry', [

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

                Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));

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 "sites" 4 times.
Open

            'sites' => $this->getSitesMenu(),

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

        if (!$data['pattern'] || $data['redirect'] || $data['method']) {

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

            $variables['headers'] = $headers;

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 "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"

Avoid using empty try-catch blocks in getRows.
Open

        } catch (\Throwable $e) {
        }

EmptyCatchBlock

Since: 2.7.0

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

Example

class Foo {

  public function bar()
  {
      try {
          // ...
      } catch (Exception $e) {} // empty catch block
  }
}

Source https://phpmd.org/rules/design.html#emptycatchblock

Avoid using empty try-catch blocks in getRows.
Open

        } catch (\Throwable $e) {
        }

EmptyCatchBlock

Since: 2.7.0

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

Example

class Foo {

  public function bar()
  {
      try {
          // ...
      } catch (Exception $e) {} // empty catch block
  }
}

Source https://phpmd.org/rules/design.html#emptycatchblock

Avoid using empty try-catch blocks in getHeaders.
Open

        } catch (\Throwable $e) {
        }

EmptyCatchBlock

Since: 2.7.0

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

Example

class Foo {

  public function bar()
  {
      try {
          // ...
      } catch (Exception $e) {} // empty catch block
  }
}

Source https://phpmd.org/rules/design.html#emptycatchblock

Avoid using empty try-catch blocks in getHeaders.
Open

        } catch (\Throwable $e) {
        }

EmptyCatchBlock

Since: 2.7.0

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

Example

class Foo {

  public function bar()
  {
      try {
          // ...
      } catch (Exception $e) {} // empty catch block
  }
}

Source https://phpmd.org/rules/design.html#emptycatchblock

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        return $this->renderTemplate('seo-fields/_redirect/_entry', [
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method t from undeclared class \Craft
Open

        Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirect
Open

        $this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        return $this->renderTemplate('seo-fields/_redirect/_import_results', $results);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method t from undeclared class \Craft
Open

            Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request (Did you mean $_REQUEST)
Open

        $id = $this->request->getBodyParam('id');

Reference to static property app from undeclared class \Craft
Open

        $model->setAttributes(Craft::$app->getRequest()->getBodyParam('fields'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method info from undeclared class \Craft
Open

            Craft::info(print_r($headers, true), __METHOD__);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        if (Craft::$app->getIsMultiSite()) {
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            $editableSites = Craft::$app->getSites()->getEditableSiteIds();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        return $this->renderTemplate('seo-fields/_redirect/_entry', [
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method t from undeclared class \Craft
Open

                Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method createFromPath from undeclared class \League\Csv\Reader
Open

            $csv = Reader::createFromPath($file->tempName);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        $request = Craft::$app->getRequest();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Parameter $reader has undeclared type \League\Csv\Reader
Open

    private function getRows(Reader $reader)

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

        $redirect = SeoFields::getInstance()->redirectService->getRedirectById($id);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method cpUrl from undeclared class \craft\helpers\UrlHelper
Open

            return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

        $results = SeoFields::getInstance()->redirectService->import($rows, $settings);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\models\RedirectModel::setAttributes
Open

        $model->setAttributes(Craft::$app->getRequest()->getBodyParam('fields'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirectToPostedUrl
Open

                $this->redirectToPostedUrl();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method t from undeclared class \Craft
Open

            0 => Craft::t('seo-fields', 'All Sites'),
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            'record' => Craft::$app->getRequest()->getParam('record') ?? null,
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

            $saved = SeoFields::getInstance()->redirectService->saveRedirect($model);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method createFromPath from undeclared class \League\Csv\Reader
Open

        $csv = Reader::createFromPath($filePath);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

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

        $variables['headers'] = $headers;

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

        $variables['headers'] = $headers;

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

        if (SeoFields::getInstance()->redirectService->deleteRedirectById($id)) {
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

                $groupSites = Craft::$app->getSites()->getSitesByGroupId($group->id);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            foreach (Craft::$app->getSites()->getAllGroups() as $group) {
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

        $redirects = SeoFields::getInstance()->redirectService->getAllRedirects($searchParam);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

                Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

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

            $variables['headers'] = $headers;

Call to method cpUrl from undeclared class \craft\helpers\UrlHelper
Open

        $this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getIterator from undeclared class \League\Csv\Reader
Open

            return $reader->getIterator();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method createFromPath from undeclared class \League\Csv\Reader
Open

        $reader = Reader::createFromPath($filePath);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Class extends undeclared class \craft\web\Controller
Open

class RedirectsController extends Controller
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

            'pattern' => Craft::$app->getRequest()->getParam('pattern') ?? null,
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request (Did you mean $_REQUEST)
Open

        $id = $this->request->getBodyParam('redirectId');

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

                    SeoFields::getInstance()->notFoundService->markAsHandled($record);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::requirePostRequest
Open

        $this->requirePostRequest();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        $this->renderTemplate('seo-fields/_redirect/_import', $variables);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method maxPowerCaptain from undeclared class \craft\helpers\App
Open

        App::maxPowerCaptain();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        return $this->renderTemplate('seo-fields/_redirect/_index', ['redirects' => $redirects]);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to static property app from undeclared class \Craft
Open

        $searchParam = Craft::$app->getRequest()->getParam('search');
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
Open

            $model = SeoFields::getInstance()->redirectService->getRedirectById($id);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\models\RedirectModel::validate
Open

        if ($model->validate()) {
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request (Did you mean $_REQUEST)
Open

        $record = $this->request->getBodyParam('record');

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open

        return $this->renderTemplate('seo-fields/_redirect/_entry', [
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method getInstanceByName from undeclared class \yii\web\UploadedFile
Open

        $file = UploadedFile::getInstanceByName('file');
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::asJson
Open

            return $this->asJson(['success' => true]);
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirect
Open

            return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Call to method fetchAll from undeclared class \League\Csv\Reader
Open

            return $reader->fetchAll();
Severity: Critical
Found in src/controllers/RedirectsController.php by phan

Either remove or fill this block of code.
Open

        } catch (\Throwable $e) {
        }

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.

Either remove or fill this block of code.
Open

        if (!$data['pattern'] || $data['redirect'] || $data['method']) {
        }

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.

Either remove or fill this block of code.
Open

        } catch (\Throwable $e) {
        }

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.

Either remove or fill this block of code.
Open

        } catch (\Throwable $e) {
        }

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.

Either remove or fill this block of code.
Open

        } catch (\Throwable $e) {
        }

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.

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

        $id = $this->request->getBodyParam('redirectId');

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

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

    public function actionEdit($id)

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

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

        $id = $this->request->getBodyParam('id');

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

There are no issues that match your filters.

Category
Status