brokencube/automatorm

View on GitHub
src/Orm/Data.php

Summary

Maintainability
F
3 days
Test Coverage

File Data.php has 576 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
namespace Automatorm\Orm;

use Automatorm\Exception;
use Automatorm\Database\SqlString;
Severity: Major
Found in src/Orm/Data.php - About 1 day to fix

    Data has 39 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Data
    {
        protected $data = [];           // Data from columns on this table
        protected $external = [];       // Links to foreign key objects
        
    Severity: Minor
    Found in src/Orm/Data.php - About 5 hrs to fix

      Method groupJoinM2M has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected static function groupJoinM2M(Collection $collection, $var, $where, $countOnly = false)
          {
              $results = new Collection();
              $proto = $collection[0]->_data;
      
      
      Severity: Minor
      Found in src/Orm/Data.php - About 1 hr to fix

        Method commit has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function commit()
            {
                // Determine the type of SQL instruction to run
                if ($this->delete) {
                    $mode = 'delete';
        Severity: Minor
        Found in src/Orm/Data.php - About 1 hr to fix

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

              public function &__get($var)
              {
                  /* This property is a native database column, return it */
                  if (isset($this->data[$var])) {
                      return $this->data[$var];
          Severity: Minor
          Found in src/Orm/Data.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

          Function join has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function join($var, array $where = [])
              {
                  if (array_key_exists($var, $this->external)) {
                      if ($this->external[$var] instanceof Collection) {
                          return $this->external[$var]->filter($where);
          Severity: Minor
          Found in src/Orm/Data.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 joinCount has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function joinCount($var, $where = [])
              {
                  if (!is_null($this->external[$var]) && !$this->external[$var] instanceof Collection) {
                      return 1;
                  }
          Severity: Minor
          Found in src/Orm/Data.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 duplicate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function duplicate($cloneExternalProps = false, Model $newParent = null)
              {
                  $clone = clone $this;
                  $clone->new = true;
                  $clone->delete = false;
          Severity: Minor
          Found in src/Orm/Data.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 __set has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function __set($var, $value)
              {
                  // Cannot change data if it is locked (i.e. it is attached to a Model object)
                  if ($this->locked) {
                      throw new Exception\Model('MODEL_DATA:SET_WHEN_LOCKED', array($var, $value));
          Severity: Minor
          Found in src/Orm/Data.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 static::groupJoinM2M($collection, $var, $where, $onlyCount);
          Severity: Major
          Found in src/Orm/Data.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return $this->joinM2M($var, $where);
            Severity: Major
            Found in src/Orm/Data.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return false;
              Severity: Major
              Found in src/Orm/Data.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return $this->joinM21($var);
                Severity: Major
                Found in src/Orm/Data.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return true;
                  Severity: Major
                  Found in src/Orm/Data.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return new Collection();
                    Severity: Major
                    Found in src/Orm/Data.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return true;
                      Severity: Major
                      Found in src/Orm/Data.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $this->joinM21($var, true);
                        Severity: Major
                        Found in src/Orm/Data.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $this->joinM2M($var, $where, true);
                          Severity: Major
                          Found in src/Orm/Data.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return $this->join12M($var, $where, true);
                            Severity: Major
                            Found in src/Orm/Data.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return $this->join12M($var, $where);
                              Severity: Major
                              Found in src/Orm/Data.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return null;
                                Severity: Major
                                Found in src/Orm/Data.php - About 30 mins to fix

                                  Function setManyToManyData has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected function setManyToManyData($var, $value)
                                      {
                                          $this->updateExternal[$var] = true;
                                          
                                          if (is_null($value)) {
                                  Severity: Minor
                                  Found in src/Orm/Data.php - About 25 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 commit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function commit()
                                      {
                                          // Determine the type of SQL instruction to run
                                          if ($this->delete) {
                                              $mode = 'delete';
                                  Severity: Minor
                                  Found in src/Orm/Data.php - About 25 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 groupJoinM2M has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected static function groupJoinM2M(Collection $collection, $var, $where, $countOnly = false)
                                      {
                                          $results = new Collection();
                                          $proto = $collection[0]->_data;
                                  
                                  
                                  Severity: Minor
                                  Found in src/Orm/Data.php - About 25 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 __isset has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function __isset($var)
                                      {
                                          // Is it already set in local array?
                                          if (array_key_exists($var, $this->data)) {
                                              return true;
                                  Severity: Minor
                                  Found in src/Orm/Data.php - About 25 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 groupJoin12M has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected static function groupJoin12M(Collection $collection, $var, $where, $countOnly = false)
                                      {
                                          $proto = $collection[0]->_data;
                                  
                                          $table = $proto->model['one-to-many'][$var]['table'];
                                  Severity: Minor
                                  Found in src/Orm/Data.php - About 25 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 using undefined variables such as '$external' which will lead to PHP notices.
                                  Open

                                                  $external[$obj->$column][] = $obj;
                                  Severity: Minor
                                  Found in src/Orm/Data.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 '$external' which will lead to PHP notices.
                                  Open

                                                  $obj->_data->external[$var] = new Collection((array) $external[$obj->id]);
                                  Severity: Minor
                                  Found in src/Orm/Data.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

                                  Missing class import via use statement (line '583', column '64').
                                  Open

                                              return new \DateTimeImmutable('@' . $datetime, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Missing class import via use statement (line '581', column '61').
                                  Open

                                              return new \DateTimeImmutable('@' . $value, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Missing class import via use statement (line '48', column '41').
                                  Open

                                                  $this->data[$key] = new \DateTimeImmutable($value, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Missing class import via use statement (line '48', column '72').
                                  Open

                                                  $this->data[$key] = new \DateTimeImmutable($value, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Missing class import via use statement (line '581', column '24').
                                  Open

                                              return new \DateTimeImmutable('@' . $value, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Missing class import via use statement (line '583', column '24').
                                  Open

                                              return new \DateTimeImmutable('@' . $datetime, new \DateTimeZone('UTC'));
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpmd

                                  MissingImport

                                  Since: 2.7.0

                                  Importing all external classes in a file through use statements makes them clearly visible.

                                  Example

                                  function make() {
                                      return new \stdClass();
                                  }

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

                                  Avoid assigning values to variables in if clauses and the like (line '582', column '30').
                                  Open

                                      protected function setDateTimeColumnData($var, $value)
                                      {
                                          if ($value instanceof \DateTimeInterface) {
                                              return $value;
                                          } elseif (is_int($value)) { // Fall back to unix timestamp
                                  Severity: Minor
                                  Found in src/Orm/Data.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

                                  Found a return statement with a value in the implementation of the magic method \Automatorm\Orm\Data::__set, expected void return type
                                  Open

                                      public function __set($var, $value)
                                  Severity: Info
                                  Found in src/Orm/Data.php by phan

                                  Variable $external was undeclared, but array fields are being added to it.
                                  Open

                                                  $external[$obj->$column][] = $obj;
                                  Severity: Info
                                  Found in src/Orm/Data.php by phan

                                  Line exceeds 120 characters; contains 126 characters
                                  Open

                                              return static::factoryDataCount($where + [$column => $this->data['id']], Schema::underscoreCase($table), $schema);
                                  Severity: Minor
                                  Found in src/Orm/Data.php by phpcodesniffer

                                  There are no issues that match your filters.

                                  Category
                                  Status