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