Avoid using static access to class '\craft\helpers\Json' in method 'getDataBySiteId'. Open
Json::decode($record->getAttribute("defaultMeta")) ?? [],
- 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 getDataBySiteId uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return new SeoDefaultsModel();
}
- 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 getRobotsForSite uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$model = new SeoDefaultsModel();
$fields = [
'enableRobots' => $record->enableRobots,
'robots' => $record->robots,
- 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\helpers\Json' in method 'getDataById'. Open
Json::decode($record->getAttribute("defaultMeta")) ?? [],
- 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 '\studioespresso\seofields\records\DefaultsRecord' in method 'saveDefaults'. Open
$record = DefaultsRecord::findOne(
['siteId' => $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 '\studioespresso\seofields\records\DefaultsRecord' in method 'getRecordForSiteId'. Open
$record = DefaultsRecord::findOne(
['siteId' => $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 '\studioespresso\seofields\records\DefaultsRecord' in method 'getDataById'. Open
$record = DefaultsRecord::findOne(
['id' => $id]
);
- 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
Define a constant instead of duplicating this literal "defaultMeta" 3 times. Open
$record->setAttribute('defaultMeta', $model->toArray(['defaultSiteTitle', 'defaultMetaDescription', 'titleSeperator', 'defaultImage']));
- 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.
Define a constant instead of duplicating this literal "robots" 3 times. Open
$record->setAttribute('robots', $model->robots);
- 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.
Define a constant instead of duplicating this literal "enableRobots" 3 times. Open
$record->setAttribute('enableRobots', $model->enableRobots);
- 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.
Define a constant instead of duplicating this literal "siteId" 3 times. Open
['siteId' => $siteId]
- 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.
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('schema', $model->schema);
- Exclude checks
Class extends undeclared class \craft\base\Component
Open
class DefaultsService extends Component
- Exclude checks
Parameter $site
has undeclared type \craft\models\Site
Open
public function getRobotsForSite(Site $site)
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('enableRobots', $model->enableRobots);
- Exclude checks
Reference to instance property id
from undeclared class \craft\models\Site
Open
$defaults->siteId = $site->id;
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoDefaultsModel::setAttributes
Open
$model->setAttributes($fields);
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoDefaultsModel::toArray
Open
$record->setAttribute('defaultMeta', $model->toArray(['defaultSiteTitle', 'defaultMetaDescription', 'titleSeperator', 'defaultImage']));
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('defaultMeta', $model->toArray(['defaultSiteTitle', 'defaultMetaDescription', 'titleSeperator', 'defaultImage']));
- Exclude checks
Reference to instance property id
from undeclared class \craft\models\Site
Open
$this->saveDefaults($defaults, $site->id);
- Exclude checks
Static call to undeclared method \studioespresso\seofields\records\DefaultsRecord::findOne
Open
$record = DefaultsRecord::findOne(
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('sitemap', $model->sitemap);
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::save
Open
$record->save();
- Exclude checks
Call to method decode
from undeclared class \craft\helpers\Json
Open
Json::decode($record->getAttribute("defaultMeta")) ?? [],
- Exclude checks
Static call to undeclared method \studioespresso\seofields\records\DefaultsRecord::findOne
Open
$record = DefaultsRecord::findOne(
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->sites->getSiteByHandle($handle);
- Exclude checks
Parameter $site
has undeclared type \craft\models\Site
Open
public function copyDefaultsForSite(Site $site, $oldPrimarySiteId)
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('siteId', $model->siteId ?? $siteId);
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoDefaultsModel::setAttributes
Open
$model->setAttributes($fields);
- Exclude checks
Reference to instance property id
from undeclared class \craft\models\Site
Open
return $this->getDataBySiteId($site->id);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getPrimarySite();
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoDefaultsModel::setAttributes
Open
$model->setAttributes($fields);
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::setAttribute
Open
$record->setAttribute('robots', $model->robots);
- Exclude checks
Call to undeclared method \studioespresso\seofields\records\DefaultsRecord::validate
Open
if ($record->validate()) {
- Exclude checks
Parameter $site
has undeclared type \craft\models\Site
Open
public function getDataBySite(Site $site)
- Exclude checks
Reference to static property plugin
from undeclared class \studioespresso\seofields\SeoFields
Open
if (!SeoFields::$plugin->getSettings()->robotsPerSite) {
- Exclude checks
Static call to undeclared method \studioespresso\seofields\records\DefaultsRecord::findOne
Open
$record = DefaultsRecord::findOne(
- Exclude checks
Call to method decode
from undeclared class \craft\helpers\Json
Open
Json::decode($record->getAttribute("defaultMeta")) ?? [],
- Exclude checks
Reference to instance property id
from undeclared class \craft\models\Site
Open
$record = $this->getRecordForSiteId($site->id);
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
public function getDataById($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Line exceeds 120 characters; contains 144 characters Open
$record->setAttribute('defaultMeta', $model->toArray(['defaultSiteTitle', 'defaultMetaDescription', 'titleSeperator', 'defaultImage']));
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
]);
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
]);
- Exclude checks