phplib/Model.php

Summary

Maintainability
F
3 days
Test Coverage

File Model.php has 416 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace FOO;

/**
Severity: Minor
Found in phplib/Model.php - About 6 hrs to fix

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

        public function offsetSet($key, $value) {
            $schema = static::getSchema();
            if(array_key_exists($key, $this->obj)) {
                switch($schema[$key][0]) {
                    case static::T_BOOL:
    Severity: Minor
    Found in phplib/Model.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

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

    class Model implements \JsonSerializable, \ArrayAccess {
        // Field types
        /** Boolean field type. */
        const T_BOOL = 0;
        /** Numeric (int/float) field type. */
    Severity: Minor
    Found in phplib/Model.php - About 2 hrs to fix

      Function generateWhere has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          protected static function generateWhere(array $query) {
              $MODEL = 'FOO\\' . static::$MODEL;
      
              $clauses = [];
              $vals = [];
      Severity: Minor
      Found in phplib/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

      Function validateField has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function validateField($field, $settings, $value) {
              $ok = false;
              switch($settings[0]) {
                  case static::T_BOOL:
                      $ok = is_bool($value);
      Severity: Minor
      Found in phplib/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

      Function hydrateModels has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function hydrateModels($objs) {
              $models = [];
              foreach($objs as $obj) {
                  foreach(array_keys($obj) as $key) {
                      // If a value is numeric, cast it into an int.
      Severity: Minor
      Found in phplib/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 validateField has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function validateField($field, $settings, $value) {
              $ok = false;
              switch($settings[0]) {
                  case static::T_BOOL:
                      $ok = is_bool($value);
      Severity: Minor
      Found in phplib/Model.php - About 1 hr to fix

        Method offsetSet has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function offsetSet($key, $value) {
                $schema = static::getSchema();
                if(array_key_exists($key, $this->obj)) {
                    switch($schema[$key][0]) {
                        case static::T_BOOL:
        Severity: Minor
        Found in phplib/Model.php - About 1 hr to fix

          Method generateClauses has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected static function generateClauses($count=null, $offset=null, $sort=[], $group=[], $reverse=null) {
                  $MODEL = 'FOO\\' . static::$MODEL;
          
                  $clauses = [];
                  $order = [];
          Severity: Minor
          Found in phplib/Model.php - About 1 hr to fix

            Method generateWhere has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected static function generateWhere(array $query) {
                    $MODEL = 'FOO\\' . static::$MODEL;
            
                    $clauses = [];
                    $vals = [];
            Severity: Minor
            Found in phplib/Model.php - About 1 hr to fix

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

                  protected static function generateClauses($count=null, $offset=null, $sort=[], $group=[], $reverse=null) {
                      $MODEL = 'FOO\\' . static::$MODEL;
              
                      $clauses = [];
                      $order = [];
              Severity: Minor
              Found in phplib/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 generateQuery has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public static function generateQuery(array $fields, array $query=[], $count=null, $offset=null, $sort=[], $group=[], $reverse=null) {
              Severity: Major
              Found in phplib/Model.php - About 50 mins to fix

                Method generateClauses has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    protected static function generateClauses($count=null, $offset=null, $sort=[], $group=[], $reverse=null) {
                Severity: Minor
                Found in phplib/Model.php - About 35 mins to fix

                  Method getByQuery has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public static function getByQuery(array $query=[], $count=null, $offset=null, $sort=[], $reverse=null) {
                  Severity: Minor
                  Found in phplib/Model.php - About 35 mins to fix

                    Method countByQuery has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public static function countByQuery(array $query=[], $count=null, $offset=null, $sort=[], $reverse=null) {
                    Severity: Minor
                    Found in phplib/Model.php - About 35 mins to fix

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

                          public function delete($hard=false) {
                              if($this->new) {
                                  return false;
                              }
                      
                      
                      Severity: Minor
                      Found in phplib/Model.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 generateClause has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected static function generateClause($key, $value) {
                              $val_cmp = true;
                              $conds = [];
                              $vals = [];
                      
                      
                      Severity: Minor
                      Found in phplib/Model.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 toArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function toArray(array $keys=null) {
                              $ret = [];
                              if(is_null($keys)) {
                                  $keys = array_keys($this->obj);
                              } else {
                      Severity: Minor
                      Found in phplib/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

                      There are no issues that match your filters.

                      Category
                      Status