| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 60 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 157 | public function import(string $path = null, string $raw = null) |
||
| 158 | { |
||
| 159 | if ($path !== '') { |
||
| 160 | $file = $this->rootFolder->getUserFolder($this->userId)->get($path); |
||
| 161 | $data = $file->getContent(); |
||
| 162 | } else if ($raw !== null) { |
||
| 163 | $data = $raw; |
||
| 164 | } else { |
||
| 165 | return false; |
||
| 166 | } |
||
| 167 | $data = json_decode($data, true); |
||
| 168 | |||
| 169 | $dataset = $data['dataset']; |
||
| 170 | isset($dataset['name']) ? $name = $dataset['name'] : $name = ''; |
||
| 171 | isset($dataset['subheader']) ? $subheader = $dataset['subheader'] : $subheader = ''; |
||
| 172 | $parent = 0; |
||
| 173 | isset($dataset['type']) ? $type = $dataset['type'] : $type = null; |
||
| 174 | isset($dataset['link']) ? $link = $dataset['link'] : $link = null; |
||
| 175 | isset($dataset['visualization']) ? $visualization = $dataset['visualization'] : $visualization = null; |
||
| 176 | isset($dataset['chart']) ? $chart = $dataset['chart'] : $chart = null; |
||
| 177 | isset($dataset['chartoptions']) ? $chartoptions = $dataset['chartoptions'] : $chartoptions = null; |
||
| 178 | isset($dataset['dataoptions']) ? $dataoptions = $dataset['dataoptions'] : $dataoptions = null; |
||
| 179 | isset($dataset['filteroptions']) ? $filteroptions = $dataset['filteroptions'] : $filteroptions = null; |
||
| 180 | isset($dataset['dimension1']) ? $dimension1 = $dataset['dimension1'] : $dimension1 = null; |
||
| 181 | isset($dataset['dimension2']) ? $dimension2 = $dataset['dimension2'] : $dimension2 = null; |
||
| 182 | isset($dataset['value']) ? $value = $dataset['value'] : $value = null; |
||
| 183 | |||
| 184 | $datasetId = $this->DatasetMapper->create(); |
||
| 185 | $this->DatasetMapper->update($datasetId, $name, $subheader, $parent, $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value, $filteroptions); |
||
| 186 | |||
| 187 | foreach ($data['dataload'] as $dataload) { |
||
| 188 | isset($dataload['datasource']) ? $datasource = $dataload['datasource'] : $datasource = null; |
||
| 189 | isset($dataload['name']) ? $name = $dataload['name'] : $name = null; |
||
| 190 | isset($dataload['option']) ? $option = $dataload['option'] : $option = null; |
||
| 191 | $schedule = null; |
||
| 192 | |||
| 193 | $dataloadId = $this->DataloadMapper->create($datasetId, $datasource); |
||
| 194 | $this->DataloadMapper->update($dataloadId, $name, $option, $schedule); |
||
| 195 | } |
||
| 196 | |||
| 197 | foreach ($data['threshold'] as $threshold) { |
||
| 198 | isset($threshold['dimension1']) ? $dimension1 = $threshold['dimension1'] : $dimension1 = null; |
||
| 199 | isset($threshold['value']) ? $value = $threshold['value'] : $value = null; |
||
| 200 | isset($threshold['option']) ? $option = $threshold['option'] : $option = null; |
||
| 201 | isset($threshold['severity']) ? $severity = $threshold['severity'] : $severity = null; |
||
| 202 | $this->ThresholdService->create($datasetId, $dimension1, $option, $value, $severity); |
||
| 203 | } |
||
| 204 | |||
| 205 | foreach ($data['data'] as $dData) { |
||
| 206 | isset($dData[0]) ? $dimension1 = $dData[0] : $dimension1 = null; |
||
| 207 | isset($dData[1]) ? $dimension2 = $dData[1] : $dimension2 = null; |
||
| 208 | isset($dData[2]) ? $value = $dData[2] : $value = null; |
||
| 209 | $this->StorageMapper->create($datasetId, $dimension1, $dimension2, $value); |
||
| 210 | } |
||
| 211 | |||
| 212 | if (isset($data['favorite'])) { |
||
| 213 | $this->setFavorite($datasetId, $data['favorite']); |
||
| 214 | } |
||
| 215 | |||
| 216 | return $datasetId; |
||
| 217 | } |
||
| 268 | } |