hauntd/yii2-vote

View on GitHub
models/VoteForm.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    Avoid too many return statements within this method.
    Open

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

      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 using static access to class '\Yii' in method 'checkModel'.
      Open

                  $this->addError('entity', Yii::t('vote', 'This entity is not supported.'));
      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' in method 'checkModel'.
      Open

                  $this->addError('targetId', Yii::t('vote', 'Target model not found.'));
      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

              $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

                  $entityAuthorAttribute = ArrayHelper::getValue($settings, 'entityAuthorAttribute', 'user_id');
      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' in method 'checkModel'.
      Open

                      $this->addError('entity', Yii::t('vote', 'Self-voting are not allowed.'));
      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 '\Yii' in method 'checkModel'.
      Open

                  $this->addError('entity', Yii::t('vote', 'Guests are not allowed for this voting.'));
      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 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

      There are no issues that match your filters.

      Category
      Status