brokencube/automatorm

View on GitHub
src/Orm/Model.php

Summary

Maintainability
C
1 day
Test Coverage

Model has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

class Model implements \JsonSerializable
{
    // Flags
    const COUNT_ONLY = 1;
    
Severity: Minor
Found in src/Orm/Model.php - About 3 hrs to fix

    Function factoryObjectCache has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
        {
            $schema = $schema ?: Schema::get(static::getNamespace());
            list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
            $namespace = $schema->namespace;
    Severity: Minor
    Found in src/Orm/Model.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 Model.php has 263 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    namespace Automatorm\Orm;
    
    use Automatorm\Exception;
    
    
    Severity: Minor
    Found in src/Orm/Model.php - About 2 hrs to fix

      Method factoryObjectCache has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
          {
              $schema = $schema ?: Schema::get(static::getNamespace());
              list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
              $namespace = $schema->namespace;
      Severity: Minor
      Found in src/Orm/Model.php - About 1 hr to fix

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

            final public function dataClearCache()
            {
                $modelschema = $this->_data->getModel();
                
                // Clean out cached column data
        Severity: Minor
        Found in src/Orm/Model.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 factory has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
        Severity: Minor
        Found in src/Orm/Model.php - About 35 mins to fix

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

              final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
              {
                  // Figure out the base class and table we need based on current context
                  $schema = $schema ?: Schema::get(static::getNamespace());
                  list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
          Severity: Minor
          Found in src/Orm/Model.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

          The method factoryObjectCache() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
          Open

              final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
              {
                  $schema = $schema ?: Schema::get(static::getNamespace());
                  list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
                  $namespace = $schema->namespace;
          Severity: Minor
          Found in src/Orm/Model.php by phpmd

          CyclomaticComplexity

          Since: 0.1

          Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

          Example

          // Cyclomatic Complexity = 11
          class Foo {
          1   public function example() {
          2       if ($a == $b) {
          3           if ($a1 == $b1) {
                          fiddle();
          4           } elseif ($a2 == $b2) {
                          fiddle();
                      } else {
                          fiddle();
                      }
          5       } elseif ($c == $d) {
          6           while ($c == $d) {
                          fiddle();
                      }
          7        } elseif ($e == $f) {
          8           for ($n = 0; $n < $h; $n++) {
                          fiddle();
                      }
                  } else {
                      switch ($z) {
          9               case 1:
                              fiddle();
                              break;
          10              case 2:
                              fiddle();
                              break;
          11              case 3:
                              fiddle();
                              break;
                          default:
                              fiddle();
                              break;
                      }
                  }
              }
          }

          Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

                          Model::$instance[$namespace][$table][$row['id']] = $obj;
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                                  $collection[] = Model::$instance[$namespace][$table][$id];
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                              if (isset(Model::$instance[$namespace][$table][$id])) {
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                      if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                          if (isset(Model::$instance[$namespace][$table][$ids])) {
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                  Model::$instance[$this->namespace][$this->table][strtolower(get_called_class())][$this->id] = $this;
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                      if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
          Severity: Minor
          Found in src/Orm/Model.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 '$instance' which will lead to PHP notices.
          Open

                              return Model::$instance[$namespace][$table][$ids];
          Severity: Minor
          Found in src/Orm/Model.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 '314', column '23').
          Open

                      throw new \BadMethodCallException("Method does not exist ({$var})", 0, $e);
          Severity: Minor
          Found in src/Orm/Model.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 '123', column '18').
          Open

              final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
              {
                  // Figure out the base class and table we need based on current context
                  $schema = $schema ?: Schema::get(static::getNamespace());
                  list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
          Severity: Minor
          Found in src/Orm/Model.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

          Avoid unused local variables such as '$class'.
          Open

                  list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
          Severity: Minor
          Found in src/Orm/Model.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

          Saw an @param annotation for options, but it was not found in the param list of function countAll(array|mixed[] $where = null) : \Automatorm\Orm\Collection|int
          Open

               * @param mixed[] $options Options to pass: limit => int, offeset => int, sort => "column direction"
          Severity: Info
          Found in src/Orm/Model.php by phan

          Doc-block of $ids in getAll is phpdoc param type int[] which is not a permitted replacement of the nullable param type ?array declared in the signature ('?T' should be documented as 'T|null' or '?T')
          Open

               * @param int[] $ids Ids of rows
          Severity: Minor
          Found in src/Orm/Model.php by phan

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

              public function __wakeup()
          Severity: Info
          Found in src/Orm/Model.php by phan

          Doc-block of countAll contains declared return type \Automatorm\Orm\Collection which is incompatible with the return type int declared in the signature
          Open

               * @return \Automatorm\Orm\Collection
          Severity: Minor
          Found in src/Orm/Model.php by phan

          Assigning array[][][] to property but \Automatorm\Orm\Model::$instance is object[][][]
          Open

                      static::$instance[$namespace][$table][$id] = [];
          Severity: Minor
          Found in src/Orm/Model.php by phan

          The property $_data is not named in camelCase.
          Open

          class Model implements \JsonSerializable
          {
              // Flags
              const COUNT_ONLY = 1;
              
          Severity: Minor
          Found in src/Orm/Model.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

          Property name "$_data" should not be prefixed with an underscore to indicate visibility
          Open

              protected $_data;             // Container for the Model_Data object for this row. Used for both internal and external __get access.
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Method name "_init" should not be prefixed with an underscore to indicate visibility
          Open

              protected function _init()
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 144 characters
          Open

                          // Call Model objects _init() function - this is to avoid recursion issues with object's natural constructor and the cache above
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 134 characters
          Open

              final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 122 characters
          Open

              protected static $instance; // An internal store of created objects so that objects for each row only get created once
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 141 characters
          Open

                      if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 173 characters
          Open

                  $foreignkeys = (array) $modelschema['one-to-one'] + (array) $modelschema['one-to-many'] + (array) $modelschema['many-to-many'] + (array) $modelschema['many-to-one'];
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 124 characters
          Open

                  // If a special property method exists, then in effect the property exists, even if it hasn't been materialised yet.
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 139 characters
          Open

              // Return an empty Model_Data object for this class/table so that a new object can be constructed (and a new row entered in the table).
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 136 characters
          Open

              protected $_data;             // Container for the Model_Data object for this row. Used for both internal and external __get access.
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 125 characters
          Open

              // Dynamic object properties - Prefer properties set on the model object over column data from the db (Model_Data object)
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 121 characters
          Open

                      // We have a data object, call replacement constructor after storing in the cache list (to prevent recursion)
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 125 characters
          Open

              final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          Line exceeds 120 characters; contains 127 characters
          Open

              // The real constructor is marked final as the normal constructor can cause infinite loops when combined with Class::get();
          Severity: Minor
          Found in src/Orm/Model.php by phpcodesniffer

          The method _init is not named in camelCase.
          Open

              protected function _init()
              {
              }
          Severity: Minor
          Found in src/Orm/Model.php by phpmd

          CamelCaseMethodName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name methods.

          Example

          class ClassName {
              public function get_name() {
              }
          }

          Source

          There are no issues that match your filters.

          Category
          Status