vistart/yii2-models

View on GitHub
traits/BlameableTrait.php

Summary

Maintainability
C
7 hrs
Test Coverage

File BlameableTrait.php has 379 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 *  _   __ __ _____ _____ ___  ____  _____
 * | | / // // ___//_  _//   ||  __||_   _|
Severity: Minor
Found in traits/BlameableTrait.php - About 5 hrs to fix

    Method getContentRules has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getContentRules()
        {
            if (!$this->contentAttribute) {
                return [];
            }
    Severity: Minor
    Found in traits/BlameableTrait.php - About 1 hr to fix

      Function getContentRules has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getContentRules()
          {
              if (!$this->contentAttribute) {
                  return [];
              }
      Severity: Minor
      Found in traits/BlameableTrait.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 enabledFields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function enabledFields()
          {
              $fields = parent::enabledFields();
              if (is_string($this->createdByAttribute)) {
                  $fields[] = $this->createdByAttribute;
      Severity: Minor
      Found in traits/BlameableTrait.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 findOneById has a boolean flag argument $throwException, which is a certain sign of a Single Responsibility Principle violation.
      Open

          public static function findOneById($id, $throwException = true, $identity = null)
      Severity: Minor
      Found in traits/BlameableTrait.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 '\yii\behaviors\BlameableBehavior' in method 'getBlameableBehaviors'.
      Open

                      'class' => BlameableBehavior::className(),
      Severity: Minor
      Found in traits/BlameableTrait.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\caching\TagDependency' in method 'getBlameableRules'.
      Open

                  TagDependency::invalidate($cache, [$this->getEntityRulesCacheTag()]);
      Severity: Minor
      Found in traits/BlameableTrait.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\caching\TagDependency' in method 'getBlameableBehaviors'.
      Open

                      TagDependency::invalidate($cache, [$this->getEntityBehaviorsCacheTag()]);
      Severity: Minor
      Found in traits/BlameableTrait.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 variables with short names like $id. Configured minimum length is 3.
      Open

          public static function findOneById($id, $throwException = true, $identity = null)
      Severity: Minor
      Found in traits/BlameableTrait.php by phpmd

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

      Source https://phpmd.org/rules/naming.html#shortvariable

      The 'getContentCanBeEdited()' method which returns a boolean should be named 'is...()' or 'has...()'
      Open

          public function getContentCanBeEdited()
          {
              if ($this->contentAttribute === false) {
                  return false;
              }
      Severity: Minor
      Found in traits/BlameableTrait.php by phpmd

      BooleanGetMethodName

      Since: 0.2

      Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

      Example

      class Foo {
          /**
           * @return boolean
           */
          public function getFoo() {} // bad
          /**
           * @return bool
           */
          public function isFoo(); // ok
          /**
           * @return boolean
           */
          public function getFoo($bar); // ok, unless checkParameterizedMethods=true
      }

      Source https://phpmd.org/rules/naming.html#booleangetmethodname

      Whitespace found at end of line
      Open

           * 
      Severity: Minor
      Found in traits/BlameableTrait.php by phpcodesniffer

      Whitespace found at end of line
      Open

           * 
      Severity: Minor
      Found in traits/BlameableTrait.php by phpcodesniffer

      Whitespace found at end of line
      Open

           * 
      Severity: Minor
      Found in traits/BlameableTrait.php by phpcodesniffer

      Whitespace found at end of line
      Open

           * 
      Severity: Minor
      Found in traits/BlameableTrait.php by phpcodesniffer

      Whitespace found at end of line
      Open

           * 
      Severity: Minor
      Found in traits/BlameableTrait.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status