Conditions | 12 |
Paths | 7 |
Total Lines | 70 |
Code Lines | 42 |
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 |
||
70 | public function readData($option): array { |
||
71 | $error = 0; |
||
72 | $path = $option['path']; |
||
73 | $file = $this->rootFolder->getUserFolder($option['user_id'])->get($option['link']); |
||
74 | $rawResult = $file->getContent(); |
||
75 | |||
76 | $json = json_decode($rawResult, true); |
||
77 | |||
78 | // check if a specific array of values should be extracted |
||
79 | // e.g. {BTC,tmsp,price} |
||
80 | preg_match_all("/(?<={).*(?=})/", $path, $matches); |
||
81 | if (count($matches[0]) > 0) { |
||
82 | // array extraction |
||
83 | |||
84 | // check if absolute path is in front of the array |
||
85 | // e.g. data/data{from,to,intensity/forecast} |
||
86 | $firstArray = strpos($path, '{'); |
||
87 | if ($firstArray && $firstArray !== 0) { |
||
88 | $singlePath = substr($path, 0, $firstArray); |
||
89 | $json = $this->get_nested_array_value($json, $singlePath); |
||
90 | } |
||
91 | |||
92 | // separate the fields of the array {BTC,tmsp,price} |
||
93 | $paths = explode(',', $matches[0][0]); |
||
94 | // fill up with dummies in case of missing columns |
||
95 | while (count($paths) < 3) { |
||
96 | array_unshift($paths, 'empty'); |
||
97 | } |
||
98 | foreach ($json as $rowArray) { |
||
99 | // get the array fields from the json |
||
100 | // if no match is not found, the field name will be used as a constant string |
||
101 | $dim1 = $this->get_nested_array_value($rowArray, $paths[0]) ?: $paths[0]; |
||
102 | $dim2 = $this->get_nested_array_value($rowArray, $paths[1]) ?: $paths[1]; |
||
103 | $val = $this->get_nested_array_value($rowArray, $paths[2]) ?: $paths[2]; |
||
104 | $data[] = [$dim1, $dim2, $val]; |
||
105 | } |
||
106 | } else { |
||
107 | // single value extraction |
||
108 | // e.g. data/currentHashrate,data/averageHashrate |
||
109 | $paths = explode(',', $path); |
||
110 | foreach ($paths as $singlePath) { |
||
111 | // e.g. data/currentHashrate |
||
112 | $array = $this->get_nested_array_value($json, $singlePath); |
||
113 | |||
114 | if (is_array($array)) { |
||
115 | // if the target is an array itself |
||
116 | foreach ($array as $key => $value) { |
||
117 | $pathArray = explode('/', $singlePath); |
||
118 | $group = end($pathArray); |
||
119 | $data[] = [$group, $key, $value]; |
||
120 | } |
||
121 | } else { |
||
122 | $pathArray = explode('/', $singlePath); |
||
123 | $key = end($pathArray); |
||
124 | $data[] = ['', $key, $array]; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | $header = array(); |
||
130 | $header[0] = ''; |
||
131 | $header[1] = 'Key'; |
||
132 | $header[2] = 'Value'; |
||
133 | |||
134 | return [ |
||
135 | 'header' => $header, |
||
136 | 'dimensions' => array_slice($header, 0, count($header) - 1), |
||
137 | 'data' => $data, |
||
138 | 'rawdata' => $rawResult, |
||
139 | 'error' => $error, |
||
140 | ]; |
||
159 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths