convenia/revisionable

View on GitHub

Showing 33 of 33 total issues

Function getValue has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getValue($which = 'new')
    {
        $whichValue = $which.'_value';

        // First find the main model that was updated
Severity: Minor
Found in src/Revision.php - About 3 hrs 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

File RevisionableTrait.php has 297 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Convenia\Revisionable;

/*
Severity: Minor
Found in src/RevisionableTrait.php - About 3 hrs to fix

    Function postSave has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        public function postSave()
        {
            $limitReached = false;
    
            if (isset($this->historyLimit) && $this->revisionHistory()->count() >= $this->historyLimit) {
    Severity: Minor
    Found in src/RevisionableTrait.php - About 2 hrs 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 excessively long variable names like $revisionFormattedFields. Keep variable name length under 20.
    Open

            $revisionFormattedFields = $relatedModel->getRevisionFormattedFields();
    Severity: Minor
    Found in src/Revision.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

    Avoid excessively long variable names like $revisionFormattedFieldNames. Keep variable name length under 20.
    Open

            $revisionFormattedFieldNames = $relatedModel->getRevisionFormattedFieldNames();
    Severity: Minor
    Found in src/Revision.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

    Avoid excessively long variable names like $revisionFormattedFields. Keep variable name length under 20.
    Open

        protected $revisionFormattedFields = [];
    Severity: Minor
    Found in src/Revision.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

    Method postSave has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function postSave()
        {
            $limitReached = false;
    
            if (isset($this->historyLimit) && $this->revisionHistory()->count() >= $this->historyLimit) {
    Severity: Minor
    Found in src/RevisionableTrait.php - About 1 hr to fix

      Function preSave has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function preSave()
          {
              if (self::$suspended === true) {
                  return;
              }
      Severity: Minor
      Found in src/RevisionableTrait.php - About 1 hr 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

      Method getValue has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function getValue($which = 'new')
          {
              $whichValue = $which.'_value';
      
              // First find the main model that was updated
      Severity: Minor
      Found in src/Revision.php - About 1 hr to fix

        Method preSave has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function preSave()
            {
                if (self::$suspended === true) {
                    return;
                }
        Severity: Minor
        Found in src/RevisionableTrait.php - About 1 hr to fix

          Avoid using undefined variables such as '$revisions' which will lead to PHP notices.
          Open

                      \DB::table($revision->getTable())->insert($revisions);
          Severity: Minor
          Found in src/RevisionableTrait.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$revisions' which will lead to PHP notices.
          Open

                      \Event::fire('revisionable.deleted', ['model' => $this, 'revisions' => $revisions]);
          Severity: Minor
          Found in src/RevisionableTrait.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$revisions' which will lead to PHP notices.
          Open

                      $revisions[] = [
          Severity: Minor
          Found in src/RevisionableTrait.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Function format has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function format($key, $value, $formats)
              {
                  foreach ($formats as $pkey => $format) {
                      $parts = explode(':', $format);
                      if (count($parts) === 1) {
          Severity: Minor
          Found in src/FieldFormatter.php - About 1 hr 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

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

              public function postCreate()
              {
                  // Check if we should store creations in our revision history
                  // Set this value to true in your model if you want to
                  if (empty($this->revisionCreationsEnabled)) {
          Severity: Minor
          Found in src/RevisionableTrait.php - About 1 hr to fix

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

                protected function changedRevisionableFields()
                {
                    $changesToRecord = [];
                    foreach ($this->dirtyData as $key => $value) {
                        // check that the field is revisionable, and double check
            Severity: Minor
            Found in src/RevisionableTrait.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 postCreate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function postCreate()
                {
                    // Check if we should store creations in our revision history
                    // Set this value to true in your model if you want to
                    if (empty($this->revisionCreationsEnabled)) {
            Severity: Minor
            Found in src/RevisionableTrait.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

            Function userResponsible has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function userResponsible()
                {
                    if (empty($this->user_id)) {
                        return false;
                    }
            Severity: Minor
            Found in src/Revision.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

            Avoid too many return statements within this method.
            Open

                    return $userModel::find($this->user_id);
            Severity: Major
            Found in src/Revision.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $this->format($this->key, $this->$whichValue);
              Severity: Major
              Found in src/Revision.php - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language