brokencube/automatorm

View on GitHub
src/Exception/Model.php

Summary

Maintainability
D
1 day
Test Coverage

Method makeMessage has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function makeMessage($code, $data)
    {
        switch ($code) {
            case 'NO_GENERATED_SCHEMA':
                return 'NO_GENERATED_SCHEMA: Could not find a schema definition for namespace: ' . $data;
Severity: Major
Found in src/Exception/Model.php - About 2 hrs to fix

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

        private function makeMessage($code, $data)
        {
            switch ($code) {
                case 'NO_GENERATED_SCHEMA':
                    return 'NO_GENERATED_SCHEMA: Could not find a schema definition for namespace: ' . $data;
    Severity: Minor
    Found in src/Exception/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

    Avoid too many return statements within this method.
    Open

                    return 'MODEL_DATA:INCORRECT_MODEL_FOR_RELATIONSHIP: Property "'.$column.'" expected a Model relating to table "'.$expectedTable.'" but a Model for "'.$suppliedTable.'" was given instead.';
    Severity: Major
    Found in src/Exception/Model.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return 'MODEL_DATA:MODEL_EXPECTED_IN_PIVOT_ARRAY: Property "'.$column.'" represents a M-M (Pivot) relationship. You successfully passed an array to this property, but it was expecting an array of Model objects and you gave it an "'.$type.'"';
      Severity: Major
      Found in src/Exception/Model.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                            return 'MODEL_DATA:ARRAY_EXPECTED_FOR_PIVOT: Property "'.$column.'" represents a M-M (Pivot) relationship. It expects an array of Model objects, but you gave it a Model object. If you intended to replace all of the objects in this join with a single object, you should wrap your Model object in array first.';
        Severity: Major
        Found in src/Exception/Model.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return 'MODEL_DATA_UPDATE:PIVOT_INCORRECT_OBJECT_TYPE: Trying to update property "'.$table.'" (pivot:.'.$pivot['pivot'].') - Was expecting an array of "'.$pivot['table'].'" objects, but found a "'.$class.'"!';
          Severity: Major
          Found in src/Exception/Model.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it a variable of type "'.$type.'"';
            Severity: Major
            Found in src/Exception/Model.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                  return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it an integer - Perhaps you meant to set "'.$column.'_id" instead?';
              Severity: Major
              Found in src/Exception/Model.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                    return 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN: Property "'.$column.'" on this object is a database column which can only accept scalar values. You tried to assign a "'.$type.'" to it. You probably meant to pass this object to column "'.substr($column, 0, -3).'". ';
                Severity: Major
                Found in src/Exception/Model.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN: Property "'.$column.'" on this object is a database column which can only accept scalar values. You tried to assign a "'.$type.'" to it.';
                  Severity: Major
                  Found in src/Exception/Model.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return 'MODEL_DATA:CANNOT_DELETE_UNCOMMITED_DATA: You cannot mark a Data object for deletion if it does not represent an existing row in the database.';
                    Severity: Major
                    Found in src/Exception/Model.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return 'MODEL_DATA:CANNOT_SET_EXTERNAL_KEYS_TO_THIS_TABLE: Property "'.$column.'" represents a list of objects that have a foreign key that refers to this object. To change this, you must update those objects - you cannot alter this relationship from here.';
                      Severity: Major
                      Found in src/Exception/Model.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return 'MODEL_DATA:UNKNOWN_FOREIGN_PROPERTY: Tried to access a foreign key not defined in the schema ('.$data['property'].'). Maybe try dump()ing this object to check what keys are available?';
                        Severity: Major
                        Found in src/Exception/Model.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return 'MODEL_DATA:DATETIME_VALUE_EXPECTED_FOR_COLUMN: Column "'.$column.'" has been declared as a Datetime field - you tried to set it to "'.$value.'". You can set DateTime fields by passing it: Orm\Date objects, \DateTime objects, strings that resolve when strtotime\'d, unix_timestamps, or null (for nullable columns)';
                          Severity: Major
                          Found in src/Exception/Model.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return 'MODEL_DATA:UNEXPECTED_COLUMN_NAME: Property "'.$column.'" does not exist in the schema for this object ('.$model['table_name'].'). Please check the $model for this object, or look at $obj->var_dump()';
                            Severity: Major
                            Found in src/Exception/Model.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return 'MODEL_DATA:ARRAY_EXPECTED_FOR_PIVOT: Property "'.$column.'" represents a M-M (Pivot) relationship. It expects an array of Model objects, but you gave it a variable of type "'.$type.'" instead.';
                              Severity: Major
                              Found in src/Exception/Model.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return 'NO_SUCH_SERVICE: Tried to access service "{$data}", but it has not yet been definied';
                                Severity: Major
                                Found in src/Exception/Model.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return 'MODEL:CALLED_GROUP_JOIN_ON_UNKNOWN_FOREIGN_PROPERTY: Tried to call join on property (' . $var . ') on Collection but was not a recognised foreign key';
                                  Severity: Major
                                  Found in src/Exception/Model.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return 'MODEL_DATA:CANNOT_CALL_MULTIPIVOT_AS_PROPERTY: Property "'.$column.'" represents a M-M (Pivot) relationship with more than two keys. As we don\'t know which type of object to return (as there are multiple choices), you can\'t call this link as a simple property. Use the $model->property([\$where]) syntax instead.';
                                    Severity: Major
                                    Found in src/Exception/Model.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return 'MODEL_DATA:UNEXPECTED_COLUMN_NAME: Property "'.$column.'" does not exist in the schema for this object ('.$model['table_name'].'), but "'.$column.'_id" does. You probably haven\'t set up the foreign key for this column!';
                                      Severity: Major
                                      Found in src/Exception/Model.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
                                        Severity: Major
                                        Found in src/Exception/Model.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return "Unknown error code ({$code})";
                                          Severity: Major
                                          Found in src/Exception/Model.php - About 30 mins to fix

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

                                                private function makeMessage($code, $data)
                                                {
                                                    switch ($code) {
                                                        case 'NO_GENERATED_SCHEMA':
                                                            return 'NO_GENERATED_SCHEMA: Could not find a schema definition for namespace: ' . $data;
                                            Severity: Minor
                                            Found in src/Exception/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 unused local variables such as '$normalised'.
                                            Open

                                                            list($classOrTable, $normalised, $class) = $data;
                                            Severity: Minor
                                            Found in src/Exception/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

                                            Reference to undeclared property \Exception->data (Did you mean $data)
                                            Open

                                                            return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phan

                                            Call to undeclared method \Throwable::makeMessage
                                            Open

                                                            return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
                                            Severity: Critical
                                            Found in src/Exception/Model.php by phan

                                            Line exceeds 120 characters; contains 168 characters
                                            Open

                                                            return 'MODEL_DATA:CANNOT_DELETE_UNCOMMITED_DATA: You cannot mark a Data object for deletion if it does not represent an existing row in the database.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 149 characters
                                            Open

                                                            return 'MODEL_DATA:CANNOT_CHANGE_ID: You cannot change the id column of an object. You probably meant to make a new object instead?';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 338 characters
                                            Open

                                                            return 'MODEL_DATA:DATETIME_VALUE_EXPECTED_FOR_COLUMN: Column "'.$column.'" has been declared as a Datetime field - you tried to set it to "'.$value.'". You can set DateTime fields by passing it: Orm\Date objects, \DateTime objects, strings that resolve when strtotime\'d, unix_timestamps, or null (for nullable columns)';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 263 characters
                                            Open

                                                            return 'NO_SCHEMA: Could not find a schema definition for this object (' . $classOrTable . '). Are you sure the classname and table are the same (case-insensitive). Otherwise, try calling Model::generate_schema(true) to refresh the schema cache.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 192 characters
                                            Open

                                                                return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it an integer - Perhaps you meant to set "'.$column.'_id" instead?';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 225 characters
                                            Open

                                                            return 'MODEL_DATA:UNEXPECTED_COLUMN_NAME: Property "'.$column.'" does not exist in the schema for this object ('.$model['table_name'].'). Please check the $model for this object, or look at $obj->var_dump()';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 175 characters
                                            Open

                                                            return 'MODEL:CALLED_GROUP_JOIN_ON_UNKNOWN_FOREIGN_PROPERTY: Tried to call join on property (' . $var . ') on Collection but was not a recognised foreign key';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 209 characters
                                            Open

                                                            return 'MODEL_DATA:UNKNOWN_FOREIGN_PROPERTY: Tried to access a foreign key not defined in the schema ('.$data['property'].'). Maybe try dump()ing this object to check what keys are available?';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 225 characters
                                            Open

                                                            return 'MODEL_DATA_UPDATE:PIVOT_INCORRECT_OBJECT_TYPE: Trying to update property "'.$table.'" (pivot:.'.$pivot['pivot'].') - Was expecting an array of "'.$pivot['table'].'" objects, but found a "'.$class.'"!';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 329 characters
                                            Open

                                                                return 'MODEL_DATA:ARRAY_EXPECTED_FOR_PIVOT: Property "'.$column.'" represents a M-M (Pivot) relationship. It expects an array of Model objects, but you gave it a Model object. If you intended to replace all of the objects in this join with a single object, you should wrap your Model object in array first.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 155 characters
                                            Open

                                                            return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it a variable of type "'.$type.'"';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 151 characters
                                            Open

                                                            return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 218 characters
                                            Open

                                                            return 'MODEL_DATA:ARRAY_EXPECTED_FOR_PIVOT: Property "'.$column.'" represents a M-M (Pivot) relationship. It expects an array of Model objects, but you gave it a variable of type "'.$type.'" instead.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 258 characters
                                            Open

                                                            return 'MODEL_DATA:MODEL_EXPECTED_IN_PIVOT_ARRAY: Property "'.$column.'" represents a M-M (Pivot) relationship. You successfully passed an array to this property, but it was expecting an array of Model objects and you gave it an "'.$type.'"';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 205 characters
                                            Open

                                                            return 'MODEL_DATA:INCORRECT_MODEL_FOR_RELATIONSHIP: Property "'.$column.'" expected a Model relating to table "'.$expectedTable.'" but a Model for "'.$suppliedTable.'" was given instead.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 218 characters
                                            Open

                                                            return 'MODEL_DATA:SET_WHEN_LOCKED: It appears you tried to assign a new value to the "'.$column.'" column directly on the $obj->_data object - Updates should be done via a call to $obj->db() instead!';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 274 characters
                                            Open

                                                            return 'MODEL_DATA:CANNOT_SET_EXTERNAL_KEYS_TO_THIS_TABLE: Property "'.$column.'" represents a list of objects that have a foreign key that refers to this object. To change this, you must update those objects - you cannot alter this relationship from here.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 340 characters
                                            Open

                                                            return 'MODEL_DATA:CANNOT_CALL_MULTIPIVOT_AS_PROPERTY: Property "'.$column.'" represents a M-M (Pivot) relationship with more than two keys. As we don\'t know which type of object to return (as there are multiple choices), you can\'t call this link as a simple property. Use the $model->property([\$where]) syntax instead.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 291 characters
                                            Open

                                                                return 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN: Property "'.$column.'" on this object is a database column which can only accept scalar values. You tried to assign a "'.$type.'" to it. You probably meant to pass this object to column "'.substr($column, 0, -3).'". ';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 211 characters
                                            Open

                                                                return 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN: Property "'.$column.'" on this object is a database column which can only accept scalar values. You tried to assign a "'.$type.'" to it.';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            Line exceeds 120 characters; contains 249 characters
                                            Open

                                                                return 'MODEL_DATA:UNEXPECTED_COLUMN_NAME: Property "'.$column.'" does not exist in the schema for this object ('.$model['table_name'].'), but "'.$column.'_id" does. You probably haven\'t set up the foreign key for this column!';
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            There must be a comment when fall-through is intentional in a non-empty case body
                                            Open

                                                        case 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN':
                                            Severity: Minor
                                            Found in src/Exception/Model.php by phpcodesniffer

                                            There are no issues that match your filters.

                                            Category
                                            Status