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 |
||
52 | private function _cacheImage($data) |
||
53 | { |
||
54 | if(!isset($data["ori"]) || !isset($data["path"]) || !isset($data["baseurl"]) || !isset($data["space_deli"]) || !isset($data["cookie"])){ |
||
55 | throw new Exception("data is not completely exist in cacheImage"); |
||
56 | } |
||
57 | $ori = $data["ori"]; |
||
58 | $path = $data["path"]; |
||
59 | $baseurl = $data["baseurl"]; |
||
60 | $space_deli = $data["space_deli"]; |
||
61 | $cookie = $data["cookie"]; |
||
62 | |||
63 | $para["path"]=$path; |
||
64 | $para["base"]=$baseurl; |
||
65 | $para["trans"]=!$space_deli; |
||
66 | $para["cookie"]=$cookie; |
||
67 | |||
68 | if ($space_deli) { |
||
69 | $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\' >]*)[^>]*>/si"; |
||
70 | } else { |
||
71 | $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\'>]*)[^>]*>/si"; |
||
72 | } |
||
73 | |||
74 | return preg_replace_callback($reg, function($matches) use ($para) { |
||
75 | global $config; |
||
76 | $url=trim($matches[1]); |
||
77 | if (stripos($url, "http://")===false && stripos($url, "https://")===false) { |
||
78 | if ($para["trans"]) { |
||
79 | $url=str_replace(" ", "%20", $url); |
||
80 | } |
||
81 | $url=$para["base"].$url; |
||
82 | } |
||
83 | $name=basename($url); |
||
84 | $name="images/".strtr($name, ":", "_"); |
||
85 | $result=str_replace(trim($matches[1]), "online_Judges/spoj/images/".strtr(basename($url), ":", "_"), $matches[0]); |
||
86 | $ch=curl_init(); |
||
87 | curl_setopt($ch, CURLOPT_URL, $url); |
||
88 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
89 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||
90 | if ($para["cookie"]!="") { |
||
91 | curl_setopt($ch, CURLOPT_COOKIEFILE, $para["cookie"]); |
||
92 | } |
||
93 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
94 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
95 | $content=curl_exec($ch); |
||
96 | curl_close($ch); |
||
97 | $fp=fopen($name, "wb"); |
||
98 | fwrite($fp, $content); |
||
99 | fclose($fp); |
||
100 | return $result; |
||
101 | }, $ori); |
||
102 | } |
||
142 |