studioespresso/craft-seo-fields

View on GitHub
src/models/SeoFieldModel.php

Summary

Maintainability
D
2 days
Test Coverage

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

    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

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

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

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

          Function getSchema has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getSchema(Element $element = null)
              {
                  if (!$element) {
                      return null;
                  }
          Severity: Minor
          Found in src/models/SeoFieldModel.php - About 35 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

          Class "SeoFieldModel" has 25 methods, which is greater than 20 authorized. Split it into smaller classes.
          Open

          class SeoFieldModel extends Model
          Severity: Major
          Found in src/models/SeoFieldModel.php by sonar-php

          A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

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

          class SeoFieldModel extends Model
          {
              public $metaTitle;
              public $metaDescription;
          
          
          Severity: Minor
          Found in src/models/SeoFieldModel.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

          The method getPageTitle has a boolean flag argument $includeSiteName, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public function getPageTitle($element = null, $includeSiteName = true)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          BooleanArgumentFlag

          Since: 1.4.0

          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

          Example

          class Foo {
              public function bar($flag = true) {
              }
          }

          Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

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

                              'url' => UrlHelper::siteUrl($site['uri'] === '__home__' ? '' : $site['uri'], null, null, $site['siteId']),
          Severity: Minor
          Found in src/models/SeoFieldModel.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 'getSchema'.
          Open

                              $schema = Craft::createObject($schemaClass);
          Severity: Minor
          Found in src/models/SeoFieldModel.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\Json' in method 'getSchema'.
          Open

                              Json::encode($schema),
          Severity: Minor
          Found in src/models/SeoFieldModel.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 'getSchema'.
          Open

                              $schema = \Craft::createObject($schemaClass);
          Severity: Minor
          Found in src/models/SeoFieldModel.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 getDefaults uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $site = Craft::$app->getSites()->getCurrentSite();
                  }
          Severity: Minor
          Found in src/models/SeoFieldModel.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

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

                  } else {
                      $site = Craft::$app->getSites()->getCurrentSite();
                  }
          Severity: Minor
          Found in src/models/SeoFieldModel.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 '\Craft' in method 'getSchema'.
          Open

                      \Craft::error($e, SeoFields::class);
          Severity: Minor
          Found in src/models/SeoFieldModel.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 getSiteNameWithSeperator uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $siteName = Craft::$app->getSystemName();
                  }
          Severity: Minor
          Found in src/models/SeoFieldModel.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

          Add a "case default" clause to this "switch" statement.
          Open

                      switch (get_class($element)) {
          Severity: Critical
          Found in src/models/SeoFieldModel.php by sonar-php

          The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

          Noncompliant Code Example

          switch ($param) {  //missing default clause
            case 0:
              do_something();
              break;
            case 1:
              do_something_else();
              break;
          }
          
          switch ($param) {
            default: // default clause should be the last one
              error();
              break;
            case 0:
              do_something();
              break;
            case 1:
              do_something_else();
              break;
          }
          

          Compliant Solution

          switch ($param) {
            case 0:
              do_something();
              break;
            case 1:
              do_something_else();
              break;
            default:
              error();
              break;
          }
          

          See

          • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
          • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
          • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
          • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
          • MISRA C:2012, 16.1 - All switch statements shall be well-formed
          • MISRA C:2012, 16.4 - Every switch statement shall have a default label
          • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
          • MITRE, CWE-478 - Missing Default Case in Switch Statement
          • CERT, MSC01-C. - Strive for logical completeness
          • CERT, MSC01-CPP. - Strive for logical completeness

          Define a constant instead of duplicating this literal "language" 3 times.
          Open

                      (new Query())->select(['siteId', 'uri', 'language', 'sites.primary as primary'])
          Severity: Critical
          Found in src/models/SeoFieldModel.php by sonar-php

          Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

          On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

          Noncompliant Code Example

          With the default threshold of 3:

          function run() {
            prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
            execute('action1');
            release('action1');
          }
          

          Compliant Solution

          ACTION_1 = 'action1';
          
          function run() {
            prepare(ACTION_1);
            execute(ACTION_1);
            release(ACTION_1);
          }
          

          Exceptions

          To prevent generating some false-positives, literals having less than 5 characters are excluded.

          Rename "$siteName" which has the same name as the field declared at line 32.
          Open

                      $siteName = $this->siteName;
          Severity: Major
          Found in src/models/SeoFieldModel.php by sonar-php

          Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

          Noncompliant Code Example

          class Foo {
            public $myField;
          
            public function doSomething() {
              $myField = 0;
              ...
            }
          }
          

          See

          Rename "$schema" which has the same name as the field declared at line 37.
          Open

                      $schema = null;
          Severity: Major
          Found in src/models/SeoFieldModel.php by sonar-php

          Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

          Noncompliant Code Example

          class Foo {
            public $myField;
          
            public function doSomething() {
              $myField = 0;
              ...
            }
          }
          

          See

          Avoid unused parameters such as '$value'.
          Open

              public function setTwitterTitle($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setMetaTitle($value = null)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setFacebookTitle($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setTwitterDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setMetaDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setFacebookImage($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

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

                  $currentSite = Craft::$app->getSites()->getCurrentSite()->id;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedLocalVariable

          Since: 0.2

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

          Example

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

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

          Avoid unused parameters such as '$value'.
          Open

              public function setTwitterImage($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Avoid unused parameters such as '$value'.
          Open

              public function setFacebookDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpmd

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

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

          Reference to static property app from undeclared class \Craft
          Open

                      $site = Craft::$app->getSites()->getSiteById($this->siteId);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $site = Craft::$app->getSites()->getCurrentSite();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method createObject from undeclared class \Craft
          Open

                              $schema = \Craft::createObject($schemaClass);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Invalid

                      $asset = Craft::$app->getAssets()->getAssetById($this->twitterImage[0]);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property title from undeclared class \craft\elements\Asset
          Open

                      'alt' => $asset->title,
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setFacebookTitle has undeclared type \craft\errors\DeprecationException
          Open

              public function setFacebookTitle($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookDescription', "Overwriting SEO properties through `entry.seo.setFacebookDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property title from undeclared class \craft\elements\Asset
          Open

                      'alt' => $asset->title,
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method getWidth from undeclared class \craft\elements\Asset
          Open

                      'width' => $asset->getWidth($transform),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method __construct from undeclared class \craft\db\Query
          Open

                      (new Query())->select(['siteId', 'uri', 'language', 'sites.primary as primary'])
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterTitle', "Overwriting SEO properties through `entry.seo.setTwitterTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getUrl from undeclared class \craft\base\Element
          Open

                              $schema->url($element->getUrl() ?? "");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $siteName = Craft::$app->getSystemName();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setMetaTitle has undeclared type \craft\errors\DeprecationException
          Open

              public function setMetaTitle($value = null)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setMetaTitle', "Overwriting SEO properties through `entry.seo.setMetaTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setTwitterTitle has undeclared type \craft\errors\DeprecationException
          Open

              public function setTwitterTitle($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property focalPoint from undeclared class \craft\elements\Asset
          Open

                      $transform->position = implode(',', $asset->focalPoint);
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Parameter $element has undeclared type ?\craft\base\Element
          Open

              public function getSchema(Element $element = null)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property section from undeclared class \craft\base\Element
          Open

                              $sectionId = $element->section->id;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to constant class from undeclared class \studioespresso\seofields\SeoFields
          Open

                      \Craft::error($e, SeoFields::class);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  $request = Craft::$app->getRequest();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Parameter $asset has undeclared type ?\craft\elements\Asset
          Open

              public function getOgImage(Asset $asset = null)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $asset = Craft::$app->getAssets()->getAssetById($this->facebookImage[0]);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getHeight from undeclared class \craft\elements\Asset
          Open

                      'height' => $asset->getHeight($transform),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterImage', "Overwriting SEO properties through `entry.seo.setTwitterImage` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getUrl from undeclared class \craft\base\Element
          Open

                              $schema->url($element->getUrl() ?? "");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
          Open

                      $defaults = SeoFields::getInstance()->defaultsService->getDataBySite($primarySite);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookTitle', "Overwriting SEO properties through `entry.seo.setFacebookTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookImage', "Overwriting SEO properties through `entry.seo.setFacebookImage` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property position from undeclared class \craft\models\ImageTransform
          Open

                      $transform->position = implode(',', $asset->focalPoint);
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
          Open

                  $this->siteDefault = SeoFields::getInstance()->defaultsService->getDataBySite($site);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method error from undeclared class \Craft
          Open

                      \Craft::error($e, SeoFields::class);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property height from undeclared class \craft\models\ImageTransform
          Open

                  $transform->height = 590;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Possibly zero references to use statement for classlike/namespace Schema (\Spatie\SchemaOrg\Schema)
          Open

          use Spatie\SchemaOrg\Schema;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method getWidth from undeclared class \craft\elements\Asset
          Open

                      'width' => $asset->getWidth($transform),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Parameter $value has undeclared type ?\craft\elements\Asset
          Open

              public function getTwitterImage(Asset $value = null)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method __construct from undeclared class \craft\models\ImageTransform
          Open

                  $transform = new ImageTransform();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to constant POS_END from undeclared class \craft\web\View
          Open

                              View::POS_END, [
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $asset = Craft::$app->getAssets()->getAssetById($this->siteDefault->defaultImage[0]);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  $currentSite = Craft::$app->getSites()->getCurrentSite()->id;
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setMetaDescription has undeclared type \craft\errors\DeprecationException
          Open

              public function setMetaDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method getMetaTitle from undeclared class \craft\base\Element
          Open

                      $title = $element->getMetaTitle();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getUrl from undeclared class \craft\elements\Asset
          Open

                      'url' => $asset->getUrl($transform, true),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setTwitterDescription has undeclared type \craft\errors\DeprecationException
          Open

              public function setTwitterDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterDescription', "Overwriting SEO properties through `entry.seo.setTwitterDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getInstance from undeclared class \studioespresso\seofields\SeoFields
          Open

                  $this->siteDefault = SeoFields::getInstance()->defaultsService->getDataBySite($site);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property group from undeclared class \craft\base\Element
          Open

                              $groupId = $element->group->id;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                          \Craft::$app->getView()->registerScript(
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getMetaTitle from undeclared class \craft\base\Element
          Open

                  if ($element->getMetaTitle()) {
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getHeight from undeclared class \craft\elements\Asset
          Open

                      'height' => $asset->getHeight($transform),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setFacebookImage has undeclared type \craft\errors\DeprecationException
          Open

              public function setFacebookImage($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Parameter $asset has undeclared type \craft\elements\Asset
          Open

              private function _getPreviewTransform(Asset $asset)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property width from undeclared class \craft\models\ImageTransform
          Open

                  $transform->width = 1200;
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Class extends undeclared class \craft\base\Model
          Open

          class SeoFieldModel extends Model
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $primarySite = Craft::$app->getSites()->getPrimarySite();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to constant class from undeclared class \craft\elements\Entry
          Open

                          case Entry::class:
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to constant class from undeclared class \craft\elements\Category
          Open

                          case Category::class:
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method createObject from undeclared class \Craft
          Open

                              $schema = Craft::createObject($schemaClass);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getShouldRenderSchema from undeclared class \craft\base\Element
          Open

                  if (!$element->getShouldRenderSchema()) {
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method encode from undeclared class \craft\helpers\Json
          Open

                              Json::encode($schema),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property mode from undeclared class \craft\models\ImageTransform
          Open

                  $transform->mode = 'crop';
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to instance property hasFocalPoint from undeclared class \craft\elements\Asset
          Open

                  if ($asset->hasFocalPoint) {
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Call to method select from undeclared class \craft\db\Query
          Open

                      (new Query())->select(['siteId', 'uri', 'language', 'sites.primary as primary'])
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setMetaDescription', "Overwriting SEO properties through `entry.seo.setMetaDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $site = Craft::$app->getSites()->getSiteById($this->siteId);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Call to method getUrl from undeclared class \craft\elements\Asset
          Open

                      'url' => $asset->getUrl($transform, true),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setFacebookDescription has undeclared type \craft\errors\DeprecationException
          Open

              public function setFacebookDescription($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $site = Craft::$app->getSites()->getCurrentSite();
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          Reference to static property app from undeclared class \Craft
          Open

                      $asset = Craft::$app->getAssets()->getAssetById($this->siteDefault->defaultImage[0]);
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

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

                              'url' => UrlHelper::siteUrl($site['uri'] === '__home__' ? '' : $site['uri'], null, null, $site['siteId']),
          Severity: Critical
          Found in src/models/SeoFieldModel.php by phan

          @throws type of setTwitterImage has undeclared type \craft\errors\DeprecationException
          Open

              public function setTwitterImage($value)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phan

          Remove or correct this useless self-assignment
          Open

                      $asset = $asset;
          Severity: Major
          Found in src/models/SeoFieldModel.php by sonar-php

          There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake and some other value or variable was intended for the assignment instead.

          Noncompliant Code Example

          public function setName($name) {
              $name = $name;
          }
          

          Compliant Solution

          public function setName($name) {
              $this->name = $name;
          }
          

          See

          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

          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

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

              private function _getPreviewTransform(Asset $asset)
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

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

                              View::POS_END, [
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 206 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setMetaDescription', "Overwriting SEO properties through `entry.seo.setMetaDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 126 characters
          Open

                              'url' => UrlHelper::siteUrl($site['uri'] === '__home__' ? '' : $site['uri'], null, null, $site['siteId']),
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 202 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookTitle', "Overwriting SEO properties through `entry.seo.setFacebookTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 214 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookDescription', "Overwriting SEO properties through `entry.seo.setFacebookDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 200 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterTitle', "Overwriting SEO properties through `entry.seo.setTwitterTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 194 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setMetaTitle', "Overwriting SEO properties through `entry.seo.setMetaTitle` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 202 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setFacebookImage', "Overwriting SEO properties through `entry.seo.setFacebookImage` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 131 characters
          Open

               * @deprecated 5.0.0 Overwriting SEO properties through this method no longer works. Please see the docs for an upgrading guide
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 212 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterDescription', "Overwriting SEO properties through `entry.seo.setTwitterDescription` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          Line exceeds 120 characters; contains 200 characters
          Open

                  Craft::$app->getDeprecator()->log(__CLASS__ . 'setTwitterImage', "Overwriting SEO properties through `entry.seo.setTwitterImage` no longer works. Please see the docs for an upgrading guide ");
          Severity: Minor
          Found in src/models/SeoFieldModel.php by phpcodesniffer

          The method _getPreviewTransform is not named in camelCase.
          Open

              private function _getPreviewTransform(Asset $asset)
              {
                  $transform = new ImageTransform();
                  $transform->width = 1200;
                  $transform->height = 590;
          Severity: Minor
          Found in src/models/SeoFieldModel.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