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