Conditions | 14 |
Paths | 28 |
Total Lines | 30 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
26 | protected function configureData($data){ |
||
27 | if (!empty($this->Options)){ |
||
28 | $fileField = end($this->Options); |
||
29 | } |
||
30 | if (is_string($data) && isset($fileField)){ |
||
31 | $data = array( |
||
32 | $fileField => $data |
||
33 | ); |
||
34 | } |
||
35 | if (is_array($data)) { |
||
36 | if (isset($fileField)) { |
||
37 | $data[$fileField] = $this->setFileFieldValue($data[$fileField]); |
||
38 | }else { |
||
39 | foreach ($data as $key => $value) { |
||
40 | if (strtolower($key) !== 'oauth_token' || strtolower($key) !== 'delete_if_fails' || strtolower($key) !== 'format') { |
||
41 | $data[$key] = $this->setFileFieldValue($value); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | $data['oauth_token'] = $this->accessToken; |
||
46 | $data['delete_if_fails'] = (isset($data['delete_if_fails']) ? $data['delete_if_fails'] : TRUE); |
||
47 | $data['format'] = 'sugar-html-json'; |
||
48 | }elseif (is_object($data) && isset($fileField)){ |
||
49 | $data->$fileField = $this->setFileFieldValue($data->$fileField); |
||
50 | $data->oauth_token = $this->accessToken; |
||
51 | $data->delete_if_fails = (isset($data->delete_if_fails) ? $data->delete_if_fails : TRUE); |
||
52 | $data->format = 'sugar-html-json'; |
||
53 | } |
||
54 | return $data; |
||
55 | } |
||
56 | |||
69 | } |