File SeoFieldModel.php
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace studioespresso\seofields\models;
use Craft;
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;
- Exclude checks
SeoFieldModel
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
class SeoFieldModel extends Model
{
public $metaTitle;
public $metaDescription;
Method getSchema
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSchema(Element $element = null)
{
if (!$element) {
return null;
}
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;
- Read upRead up
- Exclude checks
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;
}
Function getSchema
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getSchema(Element $element = null)
{
if (!$element) {
return null;
}
- Read upRead up
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
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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']),
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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),
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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();
}
- Read upRead up
- Exclude checks
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();
}
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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();
}
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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'])
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$schema" which has the same name as the field declared at line 37. Open
$schema = null;
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Avoid unused parameters such as '$value'. Open
public function setTwitterTitle($value)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getCurrentSite();
- Exclude checks
Call to method createObject
from undeclared class \Craft
Open
$schema = \Craft::createObject($schemaClass);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Invalid
$asset = Craft::$app->getAssets()->getAssetById($this->twitterImage[0]);
- Exclude checks
Reference to instance property title
from undeclared class \craft\elements\Asset
Open
'alt' => $asset->title,
- Exclude checks
@throws type of setFacebookTitle
has undeclared type \craft\errors\DeprecationException
Open
public function setFacebookTitle($value)
- Exclude checks
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 ");
- Exclude checks
Reference to instance property title
from undeclared class \craft\elements\Asset
Open
'alt' => $asset->title,
- Exclude checks
Call to method getWidth
from undeclared class \craft\elements\Asset
Open
'width' => $asset->getWidth($transform),
- Exclude checks
Call to method __construct
from undeclared class \craft\db\Query
Open
(new Query())->select(['siteId', 'uri', 'language', 'sites.primary as primary'])
- Exclude checks
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 ");
- Exclude checks
Call to method getUrl
from undeclared class \craft\base\Element
Open
$schema->url($element->getUrl() ?? "");
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$siteName = Craft::$app->getSystemName();
- Exclude checks
@throws type of setMetaTitle
has undeclared type \craft\errors\DeprecationException
Open
public function setMetaTitle($value = null)
- Exclude checks
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 ");
- Exclude checks
@throws type of setTwitterTitle
has undeclared type \craft\errors\DeprecationException
Open
public function setTwitterTitle($value)
- Exclude checks
Reference to instance property focalPoint
from undeclared class \craft\elements\Asset
Open
$transform->position = implode(',', $asset->focalPoint);
- Exclude checks
Parameter $element
has undeclared type ?\craft\base\Element
Open
public function getSchema(Element $element = null)
- Exclude checks
Reference to instance property section
from undeclared class \craft\base\Element
Open
$sectionId = $element->section->id;
- Exclude checks
Reference to constant class
from undeclared class \studioespresso\seofields\SeoFields
Open
\Craft::error($e, SeoFields::class);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$request = Craft::$app->getRequest();
- Exclude checks
Parameter $asset
has undeclared type ?\craft\elements\Asset
Open
public function getOgImage(Asset $asset = null)
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$asset = Craft::$app->getAssets()->getAssetById($this->facebookImage[0]);
- Exclude checks
Call to method getHeight
from undeclared class \craft\elements\Asset
Open
'height' => $asset->getHeight($transform),
- Exclude checks
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 ");
- Exclude checks
Call to method getUrl
from undeclared class \craft\base\Element
Open
$schema->url($element->getUrl() ?? "");
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$defaults = SeoFields::getInstance()->defaultsService->getDataBySite($primarySite);
- Exclude checks
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 ");
- Exclude checks
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 ");
- Exclude checks
Reference to instance property position
from undeclared class \craft\models\ImageTransform
Open
$transform->position = implode(',', $asset->focalPoint);
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$this->siteDefault = SeoFields::getInstance()->defaultsService->getDataBySite($site);
- Exclude checks
Call to method error
from undeclared class \Craft
Open
\Craft::error($e, SeoFields::class);
- Exclude checks
Reference to instance property height
from undeclared class \craft\models\ImageTransform
Open
$transform->height = 590;
- Exclude checks
Possibly zero references to use statement for classlike/namespace Schema
(\Spatie\SchemaOrg\Schema)
Open
use Spatie\SchemaOrg\Schema;
- Exclude checks
Call to method getWidth
from undeclared class \craft\elements\Asset
Open
'width' => $asset->getWidth($transform),
- Exclude checks
Parameter $value
has undeclared type ?\craft\elements\Asset
Open
public function getTwitterImage(Asset $value = null)
- Exclude checks
Call to method __construct
from undeclared class \craft\models\ImageTransform
Open
$transform = new ImageTransform();
- Exclude checks
Reference to constant POS_END
from undeclared class \craft\web\View
Open
View::POS_END, [
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$asset = Craft::$app->getAssets()->getAssetById($this->siteDefault->defaultImage[0]);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$currentSite = Craft::$app->getSites()->getCurrentSite()->id;
- Exclude checks
@throws type of setMetaDescription
has undeclared type \craft\errors\DeprecationException
Open
public function setMetaDescription($value)
- Exclude checks
Call to method getMetaTitle
from undeclared class \craft\base\Element
Open
$title = $element->getMetaTitle();
- Exclude checks
Call to method getUrl
from undeclared class \craft\elements\Asset
Open
'url' => $asset->getUrl($transform, true),
- Exclude checks
@throws type of setTwitterDescription
has undeclared type \craft\errors\DeprecationException
Open
public function setTwitterDescription($value)
- Exclude checks
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 ");
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$this->siteDefault = SeoFields::getInstance()->defaultsService->getDataBySite($site);
- Exclude checks
Reference to instance property group
from undeclared class \craft\base\Element
Open
$groupId = $element->group->id;
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
\Craft::$app->getView()->registerScript(
- Exclude checks
Call to method getMetaTitle
from undeclared class \craft\base\Element
Open
if ($element->getMetaTitle()) {
- Exclude checks
Call to method getHeight
from undeclared class \craft\elements\Asset
Open
'height' => $asset->getHeight($transform),
- Exclude checks
@throws type of setFacebookImage
has undeclared type \craft\errors\DeprecationException
Open
public function setFacebookImage($value)
- Exclude checks
Parameter $asset
has undeclared type \craft\elements\Asset
Open
private function _getPreviewTransform(Asset $asset)
- Exclude checks
Reference to instance property width
from undeclared class \craft\models\ImageTransform
Open
$transform->width = 1200;
- Exclude checks
Class extends undeclared class \craft\base\Model
Open
class SeoFieldModel extends Model
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$primarySite = Craft::$app->getSites()->getPrimarySite();
- Exclude checks
Reference to constant class
from undeclared class \craft\elements\Entry
Open
case Entry::class:
- Exclude checks
Reference to constant class
from undeclared class \craft\elements\Category
Open
case Category::class:
- Exclude checks
Call to method createObject
from undeclared class \Craft
Open
$schema = Craft::createObject($schemaClass);
- Exclude checks
Call to method getShouldRenderSchema
from undeclared class \craft\base\Element
Open
if (!$element->getShouldRenderSchema()) {
- Exclude checks
Call to method encode
from undeclared class \craft\helpers\Json
Open
Json::encode($schema),
- Exclude checks
Reference to instance property mode
from undeclared class \craft\models\ImageTransform
Open
$transform->mode = 'crop';
- Exclude checks
Reference to instance property hasFocalPoint
from undeclared class \craft\elements\Asset
Open
if ($asset->hasFocalPoint) {
- Exclude checks
Call to method select
from undeclared class \craft\db\Query
Open
(new Query())->select(['siteId', 'uri', 'language', 'sites.primary as primary'])
- Exclude checks
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 ");
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getSiteById($this->siteId);
- Exclude checks
Call to method getUrl
from undeclared class \craft\elements\Asset
Open
'url' => $asset->getUrl($transform, true),
- Exclude checks
@throws type of setFacebookDescription
has undeclared type \craft\errors\DeprecationException
Open
public function setFacebookDescription($value)
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getCurrentSite();
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$asset = Craft::$app->getAssets()->getAssetById($this->siteDefault->defaultImage[0]);
- Exclude checks
Call to method siteUrl
from undeclared class \craft\helpers\UrlHelper
Open
'url' => UrlHelper::siteUrl($site['uri'] === '__home__' ? '' : $site['uri'], null, null, $site['siteId']),
- Exclude checks
@throws type of setTwitterImage
has undeclared type \craft\errors\DeprecationException
Open
public function setTwitterImage($value)
- Exclude checks
Remove or correct this useless self-assignment Open
$asset = $asset;
- Read upRead up
- Exclude checks
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
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
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()) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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()) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method name "_getPreviewTransform" should not be prefixed with an underscore to indicate visibility Open
private function _getPreviewTransform(Asset $asset)
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
View::POS_END, [
- Exclude checks
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 ");
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
'url' => UrlHelper::siteUrl($site['uri'] === '__home__' ? '' : $site['uri'], null, null, $site['siteId']),
- Exclude checks
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
- Exclude checks
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 ");
- Exclude checks
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 ");
- Exclude checks
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
- Exclude checks
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
- Exclude checks
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
- Exclude checks
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 ");
- Exclude checks
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
- Exclude checks
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 ");
- Exclude checks
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
- Exclude checks
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
- Exclude checks
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 ");
- Exclude checks
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
- Exclude checks
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 ");
- Exclude checks
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 ");
- Exclude checks
The method _getPreviewTransform is not named in camelCase. Open
private function _getPreviewTransform(Asset $asset)
{
$transform = new ImageTransform();
$transform->width = 1200;
$transform->height = 590;
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}