hauntd/yii2-vote

View on GitHub

Showing 122 of 122 total issues

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

        } else {
            $rating = 0;
        }
Severity: Minor
Found in models/Vote.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 '\Yii' in method 'attributeLabels'.
Open

            'entity' => Yii::t('vote', 'Entity'),
Severity: Minor
Found in models/VoteAggregate.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 '\hauntd\vote\models\VoteAggregate' in method 'initDefaults'.
Open

                VoteAggregate::findOne([
                    'entity' => $this->getModule()->encodeEntity($this->entity),
                    'target_id' => $this->targetId,
                ]);
Severity: Minor
Found in widgets/BaseWidget.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 '\yii\bootstrap\Html' in method 'getDefaultButtonOptions'.
Open

            'icon' => Html::icon('glyphicon glyphicon-heart'),
Severity: Minor
Found in widgets/Like.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 '\yii\helpers\ArrayHelper' in method 'getVoteAggregate'.
Open

                'rating' => ArrayHelper::getValue($this->voteAttributes, ["{$name}Rating"]),
Severity: Minor
Found in behaviors/VoteBehavior.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 run uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $response = $this->processToggle($form);
            }
Severity: Minor
Found in actions/VoteAction.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 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];
        }
Severity: Minor
Found in actions/VoteAction.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 processVote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $vote = Vote::findOne(array_merge($searchParams, ['user_id' => Yii::$app->user->id]));
        }
Severity: Minor
Found in actions/VoteAction.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 createVote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return ['success' => false, 'errors' => $vote->errors];
        }
Severity: Minor
Found in actions/VoteAction.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 '\Yii' in method 'getDefaultButtonOptions'.
Open

            'labelRemove' => Yii::t('vote', 'Remove from favorites'),
Severity: Minor
Found in widgets/Favorite.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 '\yii\helpers\ArrayHelper' in method 'getVoteAggregate'.
Open

                'negative' => ArrayHelper::getValue($this->voteAttributes, ["{$name}Negative"]),
Severity: Minor
Found in behaviors/VoteBehavior.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 '\Yii' in method 'attributeLabels'.
Open

            'id' => Yii::t('vote', 'ID'),
Severity: Minor
Found in models/VoteAggregate.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 '\yii\helpers\ArrayHelper' in method 'checkModel'.
Open

        $allowGuests = ArrayHelper::getValue($settings, 'allowGuests', false);
Severity: Minor
Found in models/VoteForm.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 '\yii\helpers\ArrayHelper' in method 'checkModel'.
Open

        $allowSelfVote = ArrayHelper::getValue($settings, 'allowSelfVote', false);
Severity: Minor
Found in models/VoteForm.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 '\hauntd\vote\models\Vote' in method 'processVote'.
Open

            $vote = Vote::findOne(array_merge($searchParams, ['user_id' => Yii::$app->user->id]));
Severity: Minor
Found in actions/VoteAction.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 '\Yii' in method 'createEvent'.
Open

        return Yii::createObject([
            'class' => VoteActionEvent::class,
            'voteForm' => $voteForm,
            'responseData' => $responseData
        ]);
Severity: Minor
Found in actions/VoteAction.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 '\yii\bootstrap\Html' in method 'getDefaultButtonOptions'.
Open

            'icon' => Html::icon('glyphicon glyphicon-arrow-up'),
Severity: Minor
Found in widgets/VoteToggle.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 '\yii\helpers\ArrayHelper' in method 'getUserValue'.
Open

            return ArrayHelper::getValue($this->voteAttributes, ["{$name}UserValue"]);
Severity: Minor
Found in behaviors/VoteBehavior.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 '\Yii' in method 'checkModel'.
Open

        $targetModel = Yii::createObject($settings['modelName']);
Severity: Minor
Found in models/VoteForm.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 assigning values to variables in if clauses and the like (line '21', column '46').
Open

    public function getModule()
    {
        if (Yii::$app->hasModule('vote') && ($module = Yii::$app->getModule('vote')) instanceof Module) {
            return $module;
        }
Severity: Minor
Found in traits/ModuleTrait.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Severity
Category
Status
Source
Language