Avoid using static access to class '\craft\helpers\Json' in method 'getInputHtml'. Open
$jsonVars = Json::encode($jsonVars);
- 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 'displayName'. Open
return Craft::t('seo-fields', 'SEO Fields');
- 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 'normalizeValue'. Open
$model->setAttributes(Json::decodeIfJson($value));
- 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 unused parameters such as '$element'. Open
public function normalizeValue($value, ElementInterface $element = null): mixed
- 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
Class extends undeclared class \craft\base\Field
Open
class SeoField extends Field
- Exclude checks
Call to method decodeIfJson
from undeclared class \craft\helpers\Json
Open
$model->setAttributes(Json::decodeIfJson($value));
- Exclude checks
Reference to undeclared class \craft\base\Field
Open
return parent::serializeValue($value, $element);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Invalid
$id = Craft::$app->getView()->formatInputId($this->handle);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
Craft::$app->getView()->registerJs("$('#{$namespacedId}-field').SeoField(" . $jsonVars . ");");
- Exclude checks
Doc-block of serializeValue
contains declared return type null
which is incompatible with the return type \studioespresso\seofields\fields\mixed
declared in the signature Open
* @return null|false `false` in the event that the method is sure that no elements are going to be found.
- Exclude checks
Reference to undeclared property \studioespresso\seofields\fields\SeoField->handle
Open
$id = Craft::$app->getView()->formatInputId($this->handle);
- Exclude checks
Call to method encode
from undeclared class \craft\helpers\Json
Open
$jsonVars = Json::encode($jsonVars);
- Exclude checks
Return type of serializeValue()
is undeclared type \studioespresso\seofields\fields\mixed
Open
public function serializeValue($value, ElementInterface $element = null): mixed
- Exclude checks
Reference to undeclared property \studioespresso\seofields\fields\SeoField->handle
Open
'name' => $this->handle,
- Exclude checks
Possibly zero references to use statement for classlike/namespace SeoFields
(\studioespresso\seofields\SeoFields)
Open
use studioespresso\seofields\SeoFields;
- Exclude checks
Reference to constant TYPE_TEXT
from undeclared class \yii\db\Schema
Open
return Schema::TYPE_TEXT;
- Exclude checks
Reference to undeclared property \studioespresso\seofields\fields\SeoField->handle
Open
'name' => $this->handle,
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
'prefix' => Craft::$app->getView()->namespaceInputId(''),
- Exclude checks
Doc-block of normalizeValue
contains declared return type mixed
which is incompatible with the return type \studioespresso\seofields\fields\mixed
declared in the signature Open
* @return mixed The prepared field value
- Exclude checks
Parameter $element
has undeclared type \craft\base\ElementInterface
Open
public function normalizeValue($value, ElementInterface $element = null): mixed
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
return Craft::$app->getView()->renderTemplate(
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoFieldModel::setAttributes
Open
$model->setAttributes($value);
- Exclude checks
Doc-block of serializeValue
contains declared return type false
which is incompatible with the return type \studioespresso\seofields\fields\mixed
declared in the signature Open
* @return null|false `false` in the event that the method is sure that no elements are going to be found.
- Exclude checks
Reference to undeclared class \craft\base\Field
Open
$rules = parent::rules();
- Exclude checks
Parameter $element
has undeclared type ?\craft\base\ElementInterface
Open
public function serializeValue($value, ElementInterface $element = null): mixed
- Exclude checks
Assigning array{}
to property but \studioespresso\seofields\fields\SeoField->tabs
is string
Open
public $tabs = [];
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$namespacedId = Craft::$app->getView()->namespaceInputId($id);
- Exclude checks
Call to method t
from undeclared class \Craft
Open
return Craft::t('seo-fields', 'SEO Fields');
- Exclude checks
Return type of normalizeValue()
is undeclared type \studioespresso\seofields\fields\mixed
Open
public function normalizeValue($value, ElementInterface $element = null): mixed
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\SeoFieldModel::setAttributes
Open
$model->setAttributes(Json::decodeIfJson($value));
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
return Craft::$app->getView()->renderTemplate(
- Exclude checks
Parameter $element
has undeclared type \craft\base\ElementInterface
Open
public function getInputHtml($value, ElementInterface $element = null): string
- Exclude checks
Reference to instance property siteId
from undeclared class \craft\base\ElementInterface
Open
$value->siteId = $element->siteId;
- Exclude checks
Avoid excessively long variable names like $allowSitenameOverwrite. Keep variable name length under 20. Open
public $allowSitenameOverwrite = false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = Craft::$app->getView()->formatInputId($this->handle);
- 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;
}
}
}