studioespresso/craft-seo-fields

View on GitHub
src/controllers/CpApiController.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method actionRedirects has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function actionRedirects()
    {
        $sort = $this->request->getQueryParam('sort');
        $search = $this->request->getQueryParam('search');
        if (!$sort) {
Severity: Major
Found in src/controllers/CpApiController.php - About 2 hrs to fix

    Method actionNotFound has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function actionNotFound()
        {
            $sort = $this->request->getQueryParam('sort');
            $search = $this->request->getQueryParam('search');
            if (!$sort) {
    Severity: Major
    Found in src/controllers/CpApiController.php - About 2 hrs to fix

      Avoid unused local variables such as '$from'.
      Open

              $from = ($page - 1) * $limit + 1;
      Severity: Minor
      Found in src/controllers/CpApiController.php by phpmd

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

      Saw an @param annotation for siteHandle, but the param list of function actionNotFound() : \yii\web\Response is empty
      Open

           * @param null $siteHandle
      Severity: Info
      Found in src/controllers/CpApiController.php by phan

      Return type of actionNotFound() is undeclared type \yii\web\Response
      Open

          public function actionNotFound()
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

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

              $page = $this->request->getQueryParam('page', 1);
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

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

              return $this->asJson([
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Call to method toDateTime from undeclared class \craft\helpers\DateTimeHelper
      Open

                  $lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Reference to constant LENGTH_SHORT from undeclared class \craft\i18n\Locale (Did you mean class \Locale)
      Open

                      'lastHit' => $lastHit ? $formatter->asDatetime($lastHit, Locale::LENGTH_SHORT) : "",
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Class extends undeclared class \craft\web\Controller
      Open

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

      Reference to static property app from undeclared class \Craft
      Open

              $formatter = Craft::$app->getFormatter();
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Reference to constant LENGTH_SHORT from undeclared class \craft\i18n\Locale (Did you mean class \Locale)
      Open

                      'lastHit' => $formatter->asDatetime($lastHit, Locale::LENGTH_SHORT),
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              return $this->asJson([
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Static call to undeclared method \studioespresso\seofields\records\NotFoundRecord::find
      Open

              $query = NotFoundRecord::find();
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Reference to static property app from undeclared class \Craft
      Open

                      'site' => Craft::$app->getSites()->getSiteById($row->siteId)->name,
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              $search = $this->request->getQueryParam('search');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

      Call to method parseParam from undeclared class \craft\helpers\Db
      Open

                  $query->orWhere(Db::parseParam('siteId', $site->id));
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              $query = RedirectRecord::find();
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              $site = $this->request->getQueryParam('site');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

      Call to method toDateTime from undeclared class \craft\helpers\DateTimeHelper
      Open

                  $lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Reference to static property app from undeclared class \Craft
      Open

              $formatter = Craft::$app->getFormatter();
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              $search = $this->request->getQueryParam('search');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

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

              $site = $this->request->getQueryParam('site');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

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

              $sort = $this->request->getQueryParam('sort');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

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

              $page = $this->request->getQueryParam('page', 1);
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

      Reference to static property app from undeclared class \Craft
      Open

                  $site = Craft::$app->getSites()->getSiteByHandle($site);
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Reference to static property app from undeclared class \Craft
      Open

                      'site' => !$row->siteId ? "All" : Craft::$app->getSites()->getSiteById($row->siteId)->name,
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

              $sort = $this->request->getQueryParam('sort');
      Severity: Minor
      Found in src/controllers/CpApiController.php by phan

      Reference to static property app from undeclared class \Craft
      Open

                  $site = Craft::$app->getSites()->getSiteByHandle($site);
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

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

                      'url' => UrlHelper::cpUrl("seo-fields/redirects/edit/{$row->id}"),
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Call to method parseParam from undeclared class \craft\helpers\Db
      Open

                  $query->orWhere(Db::parseParam('siteId', $site->id));
      Severity: Critical
      Found in src/controllers/CpApiController.php by phan

      Avoid using static access to class '\studioespresso\seofields\records\NotFoundRecord' in method 'actionNotFound'.
      Open

              $query = NotFoundRecord::find();
      Severity: Minor
      Found in src/controllers/CpApiController.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

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

                      'url' => UrlHelper::cpUrl("seo-fields/redirects/edit/{$row->id}"),
      Severity: Minor
      Found in src/controllers/CpApiController.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

      Avoid using static access to class '\craft\helpers\Db' in method 'actionNotFound'.
      Open

                  $query->orWhere(Db::parseParam('siteId', $site->id));
      Severity: Minor
      Found in src/controllers/CpApiController.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

      Avoid using static access to class '\craft\helpers\DateTimeHelper' in method 'actionNotFound'.
      Open

                  $lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
      Severity: Minor
      Found in src/controllers/CpApiController.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

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

              $query = RedirectRecord::find();
      Severity: Minor
      Found in src/controllers/CpApiController.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

      Avoid using static access to class '\craft\helpers\Db' in method 'actionRedirects'.
      Open

                  $query->orWhere(Db::parseParam('siteId', $site->id));
      Severity: Minor
      Found in src/controllers/CpApiController.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

      Avoid using static access to class '\craft\helpers\DateTimeHelper' in method 'actionRedirects'.
      Open

                  $lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
      Severity: Minor
      Found in src/controllers/CpApiController.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 "siteId" 3 times.
      Open

                  $query->orWhere(Db::parseParam('siteId', $site->id));
      Severity: Critical
      Found in src/controllers/CpApiController.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.

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

              $to = (int)$page === $lastPage ? $total : ($page * $limit);
      Severity: Minor
      Found in src/controllers/CpApiController.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

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

              $to = intval($page) === intval($lastPage) ? $total : ($page * $limit);
      Severity: Minor
      Found in src/controllers/CpApiController.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

      There are no issues that match your filters.

      Category
      Status