src/Exception/Model.php
Method makeMessage
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
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;
Function makeMessage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
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;
- Read upRead up
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
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.';
Avoid too many return
statements within this method. Open
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.'"';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
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.'"!';
Avoid too many return
statements within this method. Open
Open
return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it a variable of type "'.$type.'"';
Avoid too many return
statements within this method. Open
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?';
Avoid too many return
statements within this method. Open
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).'". ';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
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?';
Avoid too many return
statements within this method. Open
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)';
Avoid too many return
statements within this method. Open
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()';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
Open
return 'NO_SUCH_SERVICE: Tried to access service "{$data}", but it has not yet been definied';
Avoid too many return
statements within this method. Open
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';
Avoid too many return
statements within this method. Open
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.';
Avoid too many return
statements within this method. Open
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!';
Avoid too many return
statements within this method. Open
Open
return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
Avoid too many return
statements within this method. Open
Open
return "Unknown error code ({$code})";
The method makeMessage() has a Cyclomatic Complexity of 26. The configured cyclomatic complexity threshold is 10. Open
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;
- Read upRead up
- Exclude checks
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
Open
list($classOrTable, $normalised, $class) = $data;
- Read upRead up
- Exclude checks
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
Open
return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
- Exclude checks
Call to undeclared method \Throwable::makeMessage
Open
Open
return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
- Exclude checks
Line exceeds 120 characters; contains 168 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
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?';
- Exclude checks
Line exceeds 120 characters; contains 338 characters Open
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)';
- Exclude checks
Line exceeds 120 characters; contains 263 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 192 characters Open
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?';
- Exclude checks
Line exceeds 120 characters; contains 225 characters Open
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()';
- Exclude checks
Line exceeds 120 characters; contains 175 characters Open
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';
- Exclude checks
Line exceeds 120 characters; contains 209 characters Open
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?';
- Exclude checks
Line exceeds 120 characters; contains 225 characters Open
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.'"!';
- Exclude checks
Line exceeds 120 characters; contains 329 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
Open
return 'MODEL_DATA:MODEL_EXPECTED_FOR_KEY: Property "'.$column.'" expected a Model object, but you gave it a variable of type "'.$type.'"';
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
Open
return 'ERROR_DURING_MASS_ASSIGNMENT: During ->assignData(), the following exception occurred: ' . $e->makeMessage($e->code, $e->data);
- Exclude checks
Line exceeds 120 characters; contains 218 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 258 characters Open
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.'"';
- Exclude checks
Line exceeds 120 characters; contains 205 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 218 characters Open
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!';
- Exclude checks
Line exceeds 120 characters; contains 274 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 340 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 291 characters Open
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).'". ';
- Exclude checks
Line exceeds 120 characters; contains 211 characters Open
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.';
- Exclude checks
Line exceeds 120 characters; contains 249 characters Open
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!';
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
Open
case 'MODEL_DATA:SCALAR_VALUE_EXPECTED_FOR_COLUMN':
- Exclude checks