studioespresso/craft-seo-fields

View on GitHub
src/SeoFields.php

Summary

Maintainability
D
2 days
Test Coverage

File SeoFields.php has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * SEO Fields plugin for Craft CMS 3.x
 *
 * Fields for your SEO & OG data
Severity: Minor
Found in src/SeoFields.php - About 5 hrs to fix

    Function _registerUrlChangeListeners has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        private function _registerUrlChangeListeners()
        {
            if (self::getInstance()->getSettings()->createRedirectForUriChange) {
                $beforeEvents = [
                    Elements::EVENT_BEFORE_SAVE_ELEMENT,
    Severity: Minor
    Found in src/SeoFields.php - About 2 hrs 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

    Method _registerCpListeners has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function _registerCpListeners()
        {
            Event::on(
                Sites::class,
                Sites::EVENT_AFTER_SAVE_SITE,
    Severity: Major
    Found in src/SeoFields.php - About 2 hrs to fix

      Method getCpNavItem has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getCpNavItem(): ?array
          {
              $subNavs = [];
              $navItem = parent::getCpNavItem();
              $navItem['label'] = $this->getSettings()->pluginLabel;
      Severity: Minor
      Found in src/SeoFields.php - About 1 hr to fix

        Method _registerUrlChangeListeners has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function _registerUrlChangeListeners()
            {
                if (self::getInstance()->getSettings()->createRedirectForUriChange) {
                    $beforeEvents = [
                        Elements::EVENT_BEFORE_SAVE_ELEMENT,
        Severity: Minor
        Found in src/SeoFields.php - About 1 hr to fix

          Method _registerPermissions has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function _registerPermissions()
              {
                  Event::on(
                      UserPermissions::class,
                      UserPermissions::EVENT_REGISTER_PERMISSIONS,
          Severity: Minor
          Found in src/SeoFields.php - About 1 hr to fix

            Method init has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function init()
                {
                    parent::init();
                    self::$plugin = $this;
            
            
            Severity: Minor
            Found in src/SeoFields.php - About 1 hr to fix

              Function getCpNavItem has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getCpNavItem(): ?array
                  {
                      $subNavs = [];
                      $navItem = parent::getCpNavItem();
                      $navItem['label'] = $this->getSettings()->pluginLabel;
              Severity: Minor
              Found in src/SeoFields.php - About 25 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

              The method _registerUrlChangeListeners() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
              Open

                  private function _registerUrlChangeListeners()
                  {
                      if (self::getInstance()->getSettings()->createRedirectForUriChange) {
                          $beforeEvents = [
                              Elements::EVENT_BEFORE_SAVE_ELEMENT,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CyclomaticComplexity

              Since: 0.1

              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

              Example

              // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

              The class SeoFields has a coupling between objects value of 42. Consider to reduce the number of dependencies under 13.
              Open

              class SeoFields extends Plugin
              {
                  // Static Properties
                  // =========================================================================
              
              
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CouplingBetweenObjects

              Since: 1.1.0

              A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

              Example

              class Foo {
                  /**
                   * @var \foo\bar\X
                   */
                  private $x = null;
              
                  /**
                   * @var \foo\bar\Y
                   */
                  private $y = null;
              
                  /**
                   * @var \foo\bar\Z
                   */
                  private $z = null;
              
                  public function setFoo(\Foo $foo) {}
                  public function setBar(\Bar $bar) {}
                  public function setBaz(\Baz $baz) {}
              
                  /**
                   * @return \SplObjectStorage
                   * @throws \OutOfRangeException
                   * @throws \InvalidArgumentException
                   * @throws \ErrorException
                   */
                  public function process(\Iterator $it) {}
              
                  // ...
              }

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

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

                              $event->permissions[Craft::t('seo-fields', 'SEO Fields')] = $permissions;
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpRoutes'.
              Open

                      Event::on(
                          UrlManager::class,
                          UrlManager::EVENT_REGISTER_CP_URL_RULES,
                          function(RegisterUrlRulesEvent $event) {
                              // Register our Control Panel routes
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerSiteListeners'.
              Open

                                  Craft::error($e->getMessage(), __CLASS__);
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerElementBehaviors'.
              Open

                          Event::on(Product::class, Product::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
                              $event->behaviors[$this->id] = ElementSeoBehavior::class;
                          });
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerSiteListeners'.
              Open

                                      Craft::debug("404 exception, processing...", __CLASS__);
              Severity: Minor
              Found in src/SeoFields.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\ElementHelper' in method '_registerUrlChangeListeners'.
              Open

                                  if (ElementHelper::isDraftOrRevision($event->element)) {
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', "redirects"),
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', "Schema.org"),
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', 'Sitemap'),
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerCpListeners'.
              Open

                              Craft::error($e->getMessage(), __CLASS__);
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerSiteListeners'.
              Open

                      Event::on(
                          ErrorHandler::class,
                          ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
                          function(ExceptionEvent $event) {
                              try {
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerElementBehaviors'.
              Open

                      Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
                          $event->behaviors[$this->id] = ElementSeoBehavior::class;
                      });
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', 'Meta'),
              Severity: Minor
              Found in src/SeoFields.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

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

                              } else {
                                  $shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getPrimarySite());
                              }
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(
                          Sites::class,
                          Sites::EVENT_AFTER_SAVE_SITE,
                          function(SiteEvent $event) {
                              if ($event->isNew) {
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(
                          Elements::class,
                          Elements::EVENT_AFTER_SAVE_ELEMENT,
                          function(ElementEvent $event) {
                              SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(Gc::class, Gc::EVENT_RUN, function() {
                          try {
                              $limit = SeoFields::$plugin->getSettings()->notFoundLimit;
                              if (!is_int($limit)) {
                                  return;
              Severity: Minor
              Found in src/SeoFields.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\NotFoundRecord' in method '_registerCpListeners'.
              Open

                              $query = NotFoundRecord::find();
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCustomElements'.
              Open

                          Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
                              function(RegisterSeoElementEvent $event) use ($elements) {
                                  $event->elements = array_merge($event->elements, $elements);
                              }
                          );
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', 'Robots'),
              Severity: Minor
              Found in src/SeoFields.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\ElementHelper' in method '_registerUrlChangeListeners'.
              Open

                                  if (ElementHelper::isDraftOrRevision($event->element)) {
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCacheOptions'.
              Open

                      Event::on(
                          ClearCaches::class,
                          ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
                          function(RegisterCacheOptionsEvent $event) {
                              // Register our Control Panel routes
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(
                          Sections::class,
                          Sections::EVENT_AFTER_DELETE_ENTRY_TYPE,
                          function(EntryTypeEvent $event) {
                              SeoFields::$plugin->sitemapSerivce->clearCaches();
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                          'label' => Craft::t('seo-fields', "404's"),
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(
                          Elements::class,
                          Elements::EVENT_AFTER_DELETE_ELEMENT,
                          function(ElementEvent $event) {
                              SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerCpListeners'.
              Open

                      Event::on(
                          Sections::class,
                          Sections::EVENT_AFTER_DELETE_SECTION,
                          function(SectionEvent $event) {
                              SeoFields::$plugin->sitemapSerivce->clearCaches();
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerFrontendRoutes'.
              Open

                      Event::on(
                          UrlManager::class,
                          UrlManager::EVENT_REGISTER_SITE_URL_RULES,
                          function(RegisterUrlRulesEvent $event) {
                              $robots = SeoFields::$plugin->defaultsService->getRobotsForSite(Craft::$app->getSites()->getCurrentSite());
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerUrlChangeListeners'.
              Open

                              Event::on(Elements::class, $event, function(ElementEvent $event) {
                                  $shouldCheckSlug = true;
                                  if (ElementHelper::isDraftOrRevision($event->element)) {
                                      $shouldCheckSlug = false;
                                  }
              Severity: Minor
              Found in src/SeoFields.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 'afterInstall'.
              Open

                          Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('seo-fields', ['showIntroduction' => true]))->send();
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerField'.
              Open

                      Event::on(
                          Fields::class,
                          Fields::EVENT_REGISTER_FIELD_TYPES,
                          function(RegisterComponentTypesEvent $event) {
                              $event->types[] = SeoField::class;
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerPermissions'.
              Open

                      Event::on(
                          UserPermissions::class,
                          UserPermissions::EVENT_REGISTER_PERMISSIONS,
                          function(RegisterUserPermissionsEvent $event) {
              
              
              Severity: Minor
              Found in src/SeoFields.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' in method '_registerPermissions'.
              Open

                                  "heading" => Craft::t('seo-fields', 'SEO Fields'),
              Severity: Minor
              Found in src/SeoFields.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 '\yii\base\Event' in method '_registerUrlChangeListeners'.
              Open

                              Event::on(Elements::class, $event, function(ElementEvent $event) {
                                  $shouldCheckSlug = true;
                                  if (ElementHelper::isDraftOrRevision($event->element)) {
                                      $shouldCheckSlug = false;
                                  }
              Severity: Minor
              Found in src/SeoFields.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

              syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
              Open

                  public string $schemaVersion = "4.0.0";
              Severity: Critical
              Found in src/SeoFields.php by phan

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                          foreach ($afterEvents as $event) {
                              Event::on(Elements::class, $event, function(ElementEvent $event) {
                                  $shouldCheckSlug = true;
                                  if (ElementHelper::isDraftOrRevision($event->element)) {
                                      $shouldCheckSlug = false;
              Severity: Major
              Found in src/SeoFields.php and 1 other location - About 1 hr to fix
              src/SeoFields.php on lines 401..412

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 102.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                          foreach ($beforeEvents as $event) {
                              Event::on(Elements::class, $event, function(ElementEvent $event) {
                                  $shouldCheckSlug = true;
                                  if (ElementHelper::isDraftOrRevision($event->element)) {
                                      $shouldCheckSlug = false;
              Severity: Major
              Found in src/SeoFields.php and 1 other location - About 1 hr to fix
              src/SeoFields.php on lines 414..425

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 102.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(RegisterUserPermissionsEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(RegisterUrlRulesEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerField" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerField()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerCpRoutes" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerCpRoutes()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(SectionEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerUrlChangeListeners" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerUrlChangeListeners()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerCpListeners" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerCpListeners()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(SiteEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerSiteListeners" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerSiteListeners()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                              Event::on(Elements::class, $event, function(ElementEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(ElementEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerCustomElements" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerCustomElements()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerFrontendRoutes" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerFrontendRoutes()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(RegisterUrlRulesEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerElementBehaviors" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerElementBehaviors(): void
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                              Event::on(Elements::class, $event, function(ElementEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerCacheOptions" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerCacheOptions()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(EntryTypeEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                      Craft::$app->view->hook('seo-fields', function(array &$context) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(RegisterComponentTypesEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerPermissions" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerPermissions()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                      Event::on(Gc::class, Gc::EVENT_RUN, function() {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(ExceptionEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Method name "_registerTwigExtension" should not be prefixed with an underscore to indicate visibility
              Open

                  private function _registerTwigExtension()
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(ElementEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          function(RegisterCacheOptionsEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                      Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                              function(RegisterSeoElementEvent $event) use ($elements) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Expected 1 space after FUNCTION keyword; 0 found
              Open

                          Event::on(Product::class, Product::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Only one argument is allowed per line in a multi-line function call
              Open

                          Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Only one argument is allowed per line in a multi-line function call
              Open

                                  $event->options, [
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 124 characters
              Open

                                  'seo-fields/<controller:(redirects|not-found)>/<action>/<id:\d+>' => 'seo-fields/<controller>/<action>',
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 123 characters
              Open

                              $robots = SeoFields::$plugin->defaultsService->getRobotsForSite(Craft::$app->getSites()->getCurrentSite());
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 142 characters
              Open

                                  $shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getCurrentSite());
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 139 characters
              Open

                                  'seo-fields/<controller:(defaults|robots|sitemap|schema)>/<siteHandle:{handle}>' => 'seo-fields/<controller>/settings',
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 142 characters
              Open

                                  $shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getPrimarySite());
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 159 characters
              Open

                                  if ($event->exception instanceof HttpException && $event->exception->statusCode === 404 && Craft::$app->getRequest()->getIsSiteRequest()) {
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 142 characters
              Open

                                      'sitemap_<siteId:\d+>_<type:(entry|product|category)>_<sectionId:\d+>_<handle:.*>.xml' => 'seo-fields/sitemap/detail',
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line exceeds 120 characters; contains 134 characters
              Open

                                  'seo-fields/<controller:(defaults|robots|sitemap|not-found|redirects|schema)>' => 'seo-fields/<controller>/index',
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Closing parenthesis of a multi-line function call must be on a line by itself
              Open

                              ]);
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Opening parenthesis of a multi-line function call must be the last content on the line
              Open

                          Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              Line indented incorrectly; expected at least 20 spaces, found 16
              Open

                              ]);
              Severity: Minor
              Found in src/SeoFields.php by phpcodesniffer

              The method _registerPermissions is not named in camelCase.
              Open

                  private function _registerPermissions()
                  {
                      Event::on(
                          UserPermissions::class,
                          UserPermissions::EVENT_REGISTER_PERMISSIONS,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerTwigExtension is not named in camelCase.
              Open

                  private function _registerTwigExtension()
                  {
                      $request = Craft::$app->getRequest();
                      if (!$request->isConsoleRequest) {
                          Craft::$app->getView()->registerTwigExtension(new SeoFieldsExtension());
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerCpListeners is not named in camelCase.
              Open

                  private function _registerCpListeners()
                  {
                      Event::on(
                          Sites::class,
                          Sites::EVENT_AFTER_SAVE_SITE,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerCacheOptions is not named in camelCase.
              Open

                  private function _registerCacheOptions()
                  {
                      Event::on(
                          ClearCaches::class,
                          ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerField is not named in camelCase.
              Open

                  private function _registerField()
                  {
                      Event::on(
                          Fields::class,
                          Fields::EVENT_REGISTER_FIELD_TYPES,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerSiteListeners is not named in camelCase.
              Open

                  private function _registerSiteListeners()
                  {
                      Event::on(
                          ErrorHandler::class,
                          ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerUrlChangeListeners is not named in camelCase.
              Open

                  private function _registerUrlChangeListeners()
                  {
                      if (self::getInstance()->getSettings()->createRedirectForUriChange) {
                          $beforeEvents = [
                              Elements::EVENT_BEFORE_SAVE_ELEMENT,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerCustomElements is not named in camelCase.
              Open

                  private function _registerCustomElements()
                  {
                      $elements = [];
                      if (Craft::$app->getPlugins()->isPluginEnabled('calendar')) {
                          /** @phpstan-ignore-next-line */
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerCpRoutes is not named in camelCase.
              Open

                  private function _registerCpRoutes()
                  {
                      Event::on(
                          UrlManager::class,
                          UrlManager::EVENT_REGISTER_CP_URL_RULES,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerFrontendRoutes is not named in camelCase.
              Open

                  private function _registerFrontendRoutes()
                  {
                      Event::on(
                          UrlManager::class,
                          UrlManager::EVENT_REGISTER_SITE_URL_RULES,
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method _registerElementBehaviors is not named in camelCase.
              Open

                  private function _registerElementBehaviors(): void
                  {
                      Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
                          $event->behaviors[$this->id] = ElementSeoBehavior::class;
                      });
              Severity: Minor
              Found in src/SeoFields.php by phpmd

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              There are no issues that match your filters.

              Category
              Status