Conditions | 13 |
Paths | 26 |
Total Lines | 30 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
110 | private function checkType($throwException, \ReflectionProperty $property, $value, array &$errors) |
||
111 | { |
||
112 | $type = InjectorHelper::extractVarType($property->getDocComment()); |
||
113 | switch (strtolower($type)) { |
||
114 | case NOSQLBase::NOSQL_TYPE_LONG: |
||
115 | case NOSQLBase::NOSQL_TYPE_INTEGER: |
||
116 | case NOSQLBase::NOSQL_TYPE_DOUBLE: |
||
117 | if (!is_numeric($value)) { |
||
118 | $errors[] = $property->getName(); |
||
119 | } |
||
120 | break; |
||
121 | case NOSQLBase::NOSQL_TYPE_ENUM: |
||
122 | $values = explode('|', InjectorHelper::getValues($property->getDocComment())); |
||
123 | if (!in_array($value, $values)) { |
||
124 | $errors[] = $property->getName(); |
||
125 | } |
||
126 | break; |
||
127 | case NOSQLBase::NOSQL_TYPE_ARRAY: |
||
128 | if (!is_array($value)) { |
||
129 | $errors[] = $property->getName(); |
||
130 | } |
||
131 | break; |
||
132 | case NOSQLBase::NOSQL_TYPE_BOOLEAN: |
||
133 | if (!in_array($value, [true, false, 0, 1])) { |
||
134 | $errors[] = $property->getName(); |
||
135 | } |
||
136 | break; |
||
137 | } |
||
138 | if (in_array($property->getName(), $errors) && $throwException) { |
||
139 | throw new NOSQLValidationException(t('Format not valid for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_NOT_VALID); |
||
140 | } |
||
142 | } |