studioespresso/craft-seo-fields

View on GitHub

Showing 41 of 1,021 total issues

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

    File SeoFieldModel.php has 329 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace studioespresso\seofields\models;
    
    use Craft;
    Severity: Minor
    Found in src/models/SeoFieldModel.php - About 3 hrs to fix

      File SitemapService.php has 323 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace studioespresso\seofields\services;
      
      use Craft;
      Severity: Minor
      Found in src/services/SitemapService.php - About 3 hrs to fix

        SeoFieldModel has 25 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class SeoFieldModel extends Model
        {
            public $metaTitle;
            public $metaDescription;
        
        
        Severity: Minor
        Found in src/models/SeoFieldModel.php - About 2 hrs to fix

          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

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

              Method createTables has 56 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function createTables()
                  {
                      $tablesCreated = false;
                      $tableSchema = Craft::$app->db->schema->getTableSchema(DefaultsRecord::tableName());
                      if ($tableSchema === null) {
              Severity: Major
              Found in src/migrations/Install.php - About 2 hrs to fix

                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 _addElementsToSitemap has 49 lines of code (exceeds 25 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

                    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

                          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

                              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 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 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
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language