| Conditions | 11 |
| Paths | 3 |
| Total Lines | 50 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 85 | private function _cacheImage($data) |
||
| 86 | { |
||
| 87 | if(!isset($data["ori"]) || !isset($data["path"]) || !isset($data["baseurl"]) || !isset($data["space_deli"]) || !isset($data["cookie"])){ |
||
| 88 | throw new Exception("data is not completely exist in cacheImage"); |
||
| 89 | } |
||
| 90 | $ori = $data["ori"]; |
||
| 91 | $path = $data["path"]; |
||
| 92 | $baseurl = $data["baseurl"]; |
||
| 93 | $space_deli = $data["space_deli"]; |
||
| 94 | $cookie = $data["cookie"]; |
||
| 95 | |||
| 96 | $para["path"]=$path; |
||
| 97 | $para["base"]=$baseurl; |
||
| 98 | $para["trans"]=!$space_deli; |
||
| 99 | $para["cookie"]=$cookie; |
||
| 100 | |||
| 101 | if ($space_deli) { |
||
| 102 | $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\' >]*)[^>]*>/si"; |
||
| 103 | } else { |
||
| 104 | $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\'>]*)[^>]*>/si"; |
||
| 105 | } |
||
| 106 | |||
| 107 | return preg_replace_callback($reg, function($matches) use ($para) { |
||
| 108 | global $config; |
||
| 109 | $url=trim($matches[1]); |
||
| 110 | if (stripos($url, "http://")===false && stripos($url, "https://")===false) { |
||
| 111 | if ($para["trans"]) { |
||
| 112 | $url=str_replace(" ", "%20", $url); |
||
| 113 | } |
||
| 114 | $url=$para["base"].$url; |
||
| 115 | } |
||
| 116 | $name=basename($url); |
||
| 117 | $name="images/".strtr($name, ":", "_"); |
||
| 118 | $result=str_replace(trim($matches[1]), "online_Judges/spoj/images/".strtr(basename($url), ":", "_"), $matches[0]); |
||
| 119 | $ch=curl_init(); |
||
| 120 | curl_setopt($ch, CURLOPT_URL, $url); |
||
| 121 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
| 122 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||
| 123 | if ($para["cookie"]!="") { |
||
| 124 | curl_setopt($ch, CURLOPT_COOKIEFILE, $para["cookie"]); |
||
| 125 | } |
||
| 126 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
| 127 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
| 128 | $content=curl_exec($ch); |
||
| 129 | curl_close($ch); |
||
| 130 | $fp=fopen($name, "wb"); |
||
| 131 | fwrite($fp, $content); |
||
| 132 | fclose($fp); |
||
| 133 | return $result; |
||
| 134 | }, $ori); |
||
| 135 | } |
||
| 184 |