Conditions | 14 |
Paths | 20 |
Total Lines | 62 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
58 | public function getValues($getFrom, $getTo, $amount, $short, $isCache, $cacheTime) |
||
59 | { |
||
60 | if($isCache && CacheFile::isCacheDir()){ |
||
61 | if(CacheFile::isFile()){ |
||
62 | $file = CacheFile::getFileName(); |
||
63 | if(CacheFile::isCurrent($file)){ |
||
64 | $data = CacheFile::getCache($file); |
||
65 | }else{ |
||
66 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
||
67 | CacheFile::setNewCacheFile($file, $data, $cacheTime); |
||
68 | } |
||
69 | }else{ |
||
70 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
||
71 | CacheFile::setNewCacheFile(false, $data, $cacheTime); |
||
72 | } |
||
73 | }else{ |
||
74 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
||
75 | } |
||
76 | $data = json_decode($data); |
||
77 | |||
78 | if($this->validateErrors($data)){ |
||
79 | if(is_array($getFrom) || is_array($getTo)){ |
||
80 | $newArray = array(); |
||
81 | |||
82 | if(is_array($getFrom)){ |
||
83 | if(is_array($getTo)){ |
||
84 | foreach($getFrom as $currency){ |
||
85 | $getA = $data->rates->$currency; |
||
86 | foreach($getTo as $currency2){ |
||
87 | $getB = $data->rates->$currency2; |
||
88 | $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
||
|
|||
89 | array_push($newArray, array($currency, array($currency2 => $calc))); |
||
90 | } |
||
91 | } |
||
92 | }else{ |
||
93 | foreach($getFrom as $currency){ |
||
94 | $getA = $data->rates->$currency; |
||
95 | $getB = $data->rates->$getTo; |
||
96 | $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
||
97 | array_push($newArray, array($currency, array($getTo => $calc))); |
||
98 | } |
||
99 | } |
||
100 | }else{ |
||
101 | foreach($getTo as $currency){ |
||
102 | $getA = $data->rates->$getFrom; |
||
103 | $getB = $data->rates->$currency; |
||
104 | $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
||
105 | array_push($newArray, array($getFrom, array($currency => $calc))); |
||
106 | } |
||
107 | } |
||
108 | $output = $newArray; |
||
109 | }else{ |
||
110 | $getA = $data->rates->$getFrom; |
||
111 | $getB = $data->rates->$getTo; |
||
112 | |||
113 | $output = Calculate::roundValue(($amount * $getB)/$getA, $short); |
||
114 | } |
||
115 | }else{ |
||
116 | $output = false; |
||
117 | } |
||
118 | |||
119 | return $output; |
||
120 | } |
||
139 |