| Conditions | 5 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 65 | public function readData($option): array |
||
| 66 | { |
||
| 67 | $string = $option['url']; |
||
| 68 | $path = $option['path']; |
||
| 69 | $auth = $option['auth']; |
||
| 70 | $data = array(); |
||
| 71 | |||
| 72 | $ch = curl_init(); |
||
| 73 | if ($ch !== false) { |
||
| 74 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); |
||
| 75 | curl_setopt($ch, CURLOPT_URL, $string); |
||
| 76 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||
| 77 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||
| 78 | 'OCS-APIRequest: true' |
||
| 79 | )); |
||
| 80 | curl_setopt($ch, CURLOPT_USERPWD, $auth); |
||
| 81 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
||
| 82 | $curlResult = curl_exec($ch); |
||
| 83 | curl_close($ch); |
||
| 84 | } else { |
||
| 85 | $curlResult = ''; |
||
| 86 | } |
||
| 87 | |||
| 88 | $json = json_decode($curlResult, true); |
||
|
|
|||
| 89 | $paths = explode(',', $path); |
||
| 90 | |||
| 91 | foreach ($paths as $singlePath) { |
||
| 92 | $array = $this->get_nested_array_value($json, $singlePath); |
||
| 93 | |||
| 94 | if (is_array($array)) { |
||
| 95 | foreach ($array as $key => $value) { |
||
| 96 | $pathArray = explode('/', $singlePath); |
||
| 97 | $group = end($pathArray); |
||
| 98 | array_push($data, [$group, $key, $value]); |
||
| 99 | } |
||
| 100 | } else { |
||
| 101 | $pathArray = explode('/', $singlePath); |
||
| 102 | $key = end($pathArray); |
||
| 103 | array_push($data, ['', $key, $array]); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $header = array(); |
||
| 108 | $header[0] = ''; |
||
| 109 | $header[1] = 'Key'; |
||
| 110 | $header[2] = 'Value'; |
||
| 111 | |||
| 112 | return [ |
||
| 113 | 'header' => $header, |
||
| 114 | 'dimensions' => array_slice($header, 0, count($header) - 1), |
||
| 115 | 'data' => $data, |
||
| 116 | 'error' => 0, |
||
| 117 | ]; |
||
| 140 | } |