studioespresso/craft-seo-fields

View on GitHub

Showing 1,008 of 1,021 total issues

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 getSitemapData has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getSitemapData($siteId, $type, $sectionId)
        {
            $settings = $this->getSettingsBySiteId($siteId);
            $data = [];
            switch ($type) {
    Severity: Minor
    Found in src/services/SitemapService.php - About 1 hr to fix

      Function _addElementsToSitemap has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          private function _addElementsToSitemap($entries, $settings)
          {
              $data = [];
              $data[] = '<?xml version="1.0" encoding="UTF-8"?>';
              $data[] = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9">';
      Severity: Minor
      Found in src/services/SitemapService.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

      Method getSchema has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getSchema(Element $element = null)
          {
              if (!$element) {
                  return null;
              }
      Severity: Minor
      Found in src/models/SeoFieldModel.php - About 1 hr to fix

        Avoid excessively long variable names like $createRedirectForUriChange. Keep variable name length under 20.
        Open

            public $createRedirectForUriChange = true;
        Severity: Minor
        Found in src/models/Settings.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $defaultMetaDescription. Keep variable name length under 20.
        Open

            public $defaultMetaDescription;
        Severity: Minor
        Found in src/models/SeoDefaultsModel.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $allowSitenameOverwrite. Keep variable name length under 20.
        Open

            public $allowSitenameOverwrite = false;
        Severity: Minor
        Found in src/fields/SeoField.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $shouldRenderCategories. Keep variable name length under 20.
        Open

                $shouldRenderCategories = array_filter($sitemapSettings['category'], function($group) use ($sitemapSettings) {
        Severity: Minor
        Found in src/services/SitemapService.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $shouldRenderCategories. Keep variable name length under 20.
        Open

                $shouldRenderCategories = false;
        Severity: Minor
        Found in src/services/SitemapService.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Method safeUp has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function safeUp()
            {
                $tablesCreated = false;
                $tableSchema = Craft::$app->db->schema->getTableSchema(RedirectRecord::tableName());
                if ($tableSchema === null) {
        Severity: Minor
        Found in src/migrations/m191114_201532_addRedirectsTable.php - About 1 hr to fix

          Method handleNotFound has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function handleNotFound(Request $request, Site $site)
              {
                  try {
                      $notFoundRecord = NotFoundRecord::findOne(['fullUrl' => $request->getAbsoluteUrl(), 'urlPath' => $request->getUrl(), 'siteId' => $site->id]);
                      if ($notFoundRecord) {
          Severity: Minor
          Found in src/services/NotFoundService.php - About 1 hr to fix

            The class SeoFieldModel has 16 fields. Consider redesigning SeoFieldModel to keep the number of fields under 15.
            Open

            class SeoFieldModel extends Model
            {
                public $metaTitle;
                public $metaDescription;
            
            
            Severity: Minor
            Found in src/models/SeoFieldModel.php by phpmd

            TooManyFields

            Since: 0.1

            Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

            Example

            class Person {
               protected $one;
               private $two;
               private $three;
               [... many more fields ...]
            }

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

            Method import has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function import($data, $settings)
                {
                    App::maxPowerCaptain();
                    $patternCol = $settings['patternCol'];
                    $redirectCol = $settings['redirectCol'];
            Severity: Minor
            Found in src/services/RedirectService.php - About 1 hr to fix

              Method getSitemapIndex has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getSitemapIndex($data)
                  {
                      $currentSite = Craft::$app->getSites()->getCurrentSite();
                      $cacheDependency = new TagDependency([
                          'tags' => [
              Severity: Minor
              Found in src/services/SitemapService.php - About 1 hr to fix

                Method safeUp has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function safeUp()
                    {
                        $tablesCreated = false;
                        $tableSchema = Craft::$app->db->schema->getTableSchema(NotFoundRecord::tableName());
                        if ($tableSchema === null) {
                Severity: Minor
                Found in src/migrations/m191114_182559_addNotFoundTable.php - About 1 hr to fix

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

                      protected function addForeignKeys()
                      {
                          // $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
                          $this->addForeignKey(
                              $this->db->getForeignKeyName(DefaultsRecord::tableName(), 'siteId'),
                  Severity: Minor
                  Found in src/migrations/Install.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 getMatchingRedirect has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function getMatchingRedirect(NotFoundModel $model): RedirectRecord|array|bool
                          {
                              Craft::debug("Check if our 404 is matched to a redirect", SeoFields::class);
                              $parsedUrl = parse_url($model->urlPath);
                      
                      
                      Severity: Minor
                      Found in src/services/NotFoundService.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

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language