| Conditions | 11 |
| Paths | 12 |
| Total Lines | 52 |
| 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 |
||
| 19 | protected function addValueByColName(&$cols, &$row, $colName, $value) |
||
| 20 | { |
||
| 21 | if(is_object($value)) |
||
| 22 | { |
||
| 23 | switch($colName) |
||
| 24 | { |
||
| 25 | case '_id': |
||
| 26 | if(isset($value->{'$id'})) |
||
| 27 | { |
||
| 28 | $this->addValueByColName($cols, $row, $colName, $value->{'$id'}); |
||
| 29 | break; |
||
| 30 | } |
||
| 31 | else if(is_a($value, 'MongoDB\BSON\ObjectId')) |
||
| 32 | { |
||
| 33 | $this->addValueByColName($cols, $row, $colName, (string)$value); |
||
| 34 | break; |
||
| 35 | } |
||
| 36 | default: |
||
| 37 | $props = get_object_vars($value); |
||
| 38 | foreach($props as $key=>$newValue) |
||
| 39 | { |
||
| 40 | $this->addValueByColName($cols, $row, $colName.'.'.$key, $newValue); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | $index = array_search($colName, $cols); |
||
| 46 | if($index === false) |
||
| 47 | { |
||
| 48 | $index = count($cols); |
||
| 49 | $cols[$index] = $colName; |
||
| 50 | } |
||
| 51 | if(is_array($value)) |
||
| 52 | { |
||
| 53 | if(isset($value[0]) && is_object($value[0])) |
||
| 54 | { |
||
| 55 | $count = count($value); |
||
| 56 | for($i = 0; $i < $count; $i++) |
||
| 57 | { |
||
| 58 | $this->addValueByColName($cols, $row, $colName.'['.$i.']', $value[$i]); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | else |
||
| 62 | { |
||
| 63 | $row[$index] = implode(',', $value); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | else |
||
| 67 | { |
||
| 68 | $row[$index] = $value; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 96 |