hauntd/yii2-vote

View on GitHub

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');
Severity: Minor
Found in models/VoteForm.php by phpmd

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;

    /**
Severity: Minor
Found in widgets/BaseWidget.php by phpmd

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 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(),
Severity: Minor
Found in migrations/m160620_131811_vote.php by phpmd

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());

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_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);
    }

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) {
Severity: Minor
Found in models/VoteForm.php - About 1 hr to fix

    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) {
    Severity: Minor
    Found in models/VoteForm.php - About 55 mins to fix

    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];
    Severity: Minor
    Found in actions/VoteAction.php - About 55 mins to fix

    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);

    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);

    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}}', [
    Severity: Minor
    Found in migrations/m160620_131811_vote.php by phpmd

    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;
    
        /**
    Severity: Minor
    Found in widgets/BaseWidget.php by phpmd

    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;
            }
    Severity: Minor
    Found in widgets/BaseWidget.php - About 45 mins to fix

    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);
            }
    Severity: Minor
    Found in actions/VoteAction.php - About 35 mins to fix

    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 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)
    Severity: Minor
    Found in behaviors/VoteBehavior.php by phpmd

    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 too many return statements within this method.
    Open

            return true;
    Severity: Major
    Found in models/VoteForm.php - About 30 mins to fix

      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)
      Severity: Minor
      Found in behaviors/VoteBehavior.php by phpmd

      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 'hauntd\vote\models\VoteAggregate' in method 'updateRating'.
      Open

              $aggregateModel = VoteAggregate::findOne([
                  'entity' => $entity,
                  'target_id' => $targetId,
              ]);
      Severity: Minor
      Found in models/Vote.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 processVote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  if ($vote->value !== $form->getValue()) {
                      $vote->value = $form->getValue();
                      if ($vote->save()) {
                          $response = ['success' => true, 'changed' => true];
      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 '\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
              ]);
      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

      Severity
      Category
      Status
      Source
      Language