studioespresso/craft-seo-fields

View on GitHub

Showing 1,008 of 1,021 total issues

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

    public function getTwitterImage(Asset $value = null)
    {
        if ($value) {
            $asset = $value;
        } elseif ($this->element->getTwitterImage()) {
Severity: Major
Found in src/models/SeoFieldModel.php and 1 other location - About 5 hrs to fix
src/models/SeoFieldModel.php on lines 236..258

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

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

    public function getOgImage(Asset $asset = null)
    {
        if ($asset) {
            $asset = $asset;
        } elseif ($this->element->getFacebookImage()) {
Severity: Major
Found in src/models/SeoFieldModel.php and 1 other location - About 5 hrs to fix
src/models/SeoFieldModel.php on lines 260..282

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

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

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

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

        public function actionSave()
        {
            $data = [];
            if (Craft::$app->getRequest()->getBodyParam('id')) {
                $model = SeoFields::$plugin->defaultsService->getDataById(Craft::$app->getRequest()->getBodyParam('id'));
    Severity: Major
    Found in src/controllers/SitemapController.php and 1 other location - About 4 hrs to fix
    src/controllers/SchemaController.php on lines 29..43

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

    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

        public function actionSave()
        {
            $data = [];
            if (Craft::$app->getRequest()->getBodyParam('id')) {
                $model = SeoFields::$plugin->defaultsService->getDataById(Craft::$app->getRequest()->getBodyParam('id'));
    Severity: Major
    Found in src/controllers/SchemaController.php and 1 other location - About 4 hrs to fix
    src/controllers/SitemapController.php on lines 47..61

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

    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

    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

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

                    $this->createTable(
                        RedirectRecord::tableName(),
                        [
                            'id' => $this->primaryKey(),
                            'siteId' => $this->integer(11)->defaultValue(null),
        Severity: Major
        Found in src/migrations/Install.php and 1 other location - About 3 hrs to fix
        src/migrations/m191114_201532_addRedirectsTable.php on lines 24..40

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

        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

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

                    $this->createTable(
                        RedirectRecord::tableName(),
                        [
                            'id' => $this->primaryKey(),
                            'siteId' => $this->integer(11)->defaultValue(null),
        Severity: Major
        Found in src/migrations/m191114_201532_addRedirectsTable.php and 1 other location - About 3 hrs to fix
        src/migrations/Install.php on lines 82..98

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

        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

        The class SeoFieldModel has an overall complexity of 70 which is very high. The configured complexity threshold is 50.
        Open

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

        The class SitemapService has an overall complexity of 57 which is very high. The configured complexity threshold is 50.
        Open

        class SitemapService extends Component
        {
            public const SITEMAP_CACHE_KEY = 'seofields_cache_sitemaps';
        
            public function shouldRenderBySiteId(Site $site)
        Severity: Minor
        Found in src/services/SitemapService.php by phpmd

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

                    $this->createTable(
                        NotFoundRecord::tableName(),
                        [
                            'id' => $this->primaryKey(),
                            'siteId' => $this->integer(11)->notNull(),
        Severity: Major
        Found in src/migrations/Install.php and 1 other location - About 3 hrs to fix
        src/migrations/m191114_182559_addNotFoundTable.php on lines 23..40

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

        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

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

                    $this->createTable(
                        NotFoundRecord::tableName(),
                        [
                            'id' => $this->primaryKey(),
                            'siteId' => $this->integer(11)->notNull(),
        Severity: Major
        Found in src/migrations/m191114_182559_addNotFoundTable.php and 1 other location - About 3 hrs to fix
        src/migrations/Install.php on lines 100..117

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

        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

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