Showing 122 of 122 total issues
Avoid excessively long variable names like $entityAuthorAttribute. Keep variable name length under 20. Open
$entityAuthorAttribute = ArrayHelper::getValue($settings, 'entityAuthorAttribute', 'user_id');
- 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
The class BaseWidget has 16 fields. Consider redesigning BaseWidget to keep the number of fields under 15. Open
abstract class BaseWidget extends Widget
{
use ModuleTrait;
/**
- 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
Avoid using short method names like m160706_223457_vote_index::up(). The configured minimum method name length is 3. Open
public function up()
{
$this->createIndex('vote_target_value_idx', '{{%vote}}', ['entity', 'target_id', 'value'], false);
}
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid using short method names like m160620_131811_vote::up(). The configured minimum method name length is 3. Open
public function up()
{
$this->createTable('{{%vote}}', [
'id' => $this->primaryKey(),
'entity' => $this->integer()->unsigned()->notNull(),
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid using short method names like m160706_223500_vote_updates::up(). The configured minimum method name length is 3. Open
public function up()
{
$this->createIndex('vote_target_user_idx', '{{%vote}}', ['entity', 'target_id', 'user_id'], false);
$this->alterColumn('{{%vote}}', 'value', $this->boolean()->notNull());
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Method checkModel
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function checkModel()
{
$module = $this->getModule();
$settings = $module->getSettingsForEntity($this->entity);
if ($settings === null) {
Function checkModel
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function checkModel()
{
$module = $this->getModule();
$settings = $module->getSettingsForEntity($this->entity);
if ($settings === 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
Function processVote
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function processVote(VoteForm $form)
{
/* @var $vote Vote */
$module = $this->getModule();
$response = ['success' => false];
- 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
The class m160706_223500_vote_updates is not named in CamelCase. Open
class m160706_223500_vote_updates extends Migration
{
public function up()
{
$this->createIndex('vote_target_user_idx', '{{%vote}}', ['entity', 'target_id', 'user_id'], false);
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The class m160706_223457_vote_index is not named in CamelCase. Open
class m160706_223457_vote_index extends Migration
{
public function up()
{
$this->createIndex('vote_target_value_idx', '{{%vote}}', ['entity', 'target_id', 'value'], false);
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The class m160620_131811_vote is not named in CamelCase. Open
class m160620_131811_vote extends Migration
{
public function up()
{
$this->createTable('{{%vote}}', [
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The property $_behaviorIncluded is not named in camelCase. Open
abstract class BaseWidget extends Widget
{
use ModuleTrait;
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Function isBehaviorIncluded
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function isBehaviorIncluded()
{
if (isset($this->_behaviorIncluded)) {
return $this->_behaviorIncluded;
}
- 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
Function run
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function run()
{
if (!Yii::$app->request->getIsAjax() || !Yii::$app->request->getIsPost()) {
throw new MethodNotAllowedHttpException(Yii::t('vote', 'Forbidden method'), 405);
}
- 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
Avoid too many return
statements within this method. Open
return true;
The method canSetProperty has a boolean flag argument $checkVars, which is a certain sign of a Single Responsibility Principle violation. Open
public function canSetProperty($name, $checkVars = 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
The method canGetProperty has a boolean flag argument $checkVars, which is a certain sign of a Single Responsibility Principle violation. Open
public function canGetProperty($name, $checkVars = 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 '\Yii' in method 'attributeLabels'. Open
'target_id' => Yii::t('vote', 'Target Model 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
The method run uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$response = ['success' => false, 'errors' => $form->errors];
}
- 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 '\hauntd\vote\models\Vote' in method 'processToggle'. Open
$vote = Vote::findOne([
'entity' => $module->encodeEntity($form->entity),
'target_id' => $form->targetId,
'user_id' => Yii::$app->user->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();
}
}