Conditions | 5 |
Paths | 5 |
Total Lines | 53 |
Code Lines | 41 |
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 |
||
73 | public function getProblemDetail($pid) { |
||
74 | $cate = []; |
||
75 | |||
76 | $url = "https://www.spoj.com/problems/".$pid; |
||
77 | $res = Requests::get($url); |
||
78 | if (strpos("<h1>Not Found</h1>",$res->body) !== false) { |
||
79 | header('HTTP/1.1 404 Not Found'); |
||
80 | die(); |
||
81 | }else{ |
||
82 | $this->pro['title'] = trim(self::find('/<h2 id="problem-name".* - (.*)<\/h2>/sU',$res->body)); |
||
83 | $temp = $res->body; |
||
84 | $temp = explode('<tr><td>Time limit:</td><td>', $temp)[1]; |
||
85 | $this->pro['time_limit']=trim(explode('s </td></tr>', $temp)[0]); //as for html arrange |
||
86 | $temp = $res->body; |
||
87 | $temp = explode('<tr><td>Memory limit:</td><td>', $temp)[1]; |
||
88 | $this->pro['memory_limit']=trim(explode('MB</td></tr>' , $temp)[0]); |
||
89 | $temp = $res->body; |
||
90 | $temp = explode('<tr><td>Languages:</td><td>', $temp)[1]; |
||
91 | $this->pro['note'] = "Languages Limit:".explode('</td></tr>', $temp)[0]; |
||
92 | |||
93 | if(strpos($res->body, "<tr><td>Resource:</td><td>")!==false) |
||
94 | { |
||
95 | $temp = $res->body; |
||
96 | $temp = explode('<tr><td>Resource:</td><td>', $temp)[1]; |
||
97 | $this->pro['source'] = strip_tags(explode('</td></tr>', $temp)[0]); |
||
98 | }else { |
||
99 | $this->pro['source'] = "SPOJ-".$pid; |
||
100 | } |
||
101 | |||
102 | if(strpos($res->body,"No tags")===false) |
||
103 | { |
||
104 | $temp = $res->body; |
||
105 | $temp = explode('<div id="problem-tags" class="col-lg-12 text-center">', $temp)[1]; |
||
106 | $temp = explode('</div>', $temp)[0]; |
||
107 | $cat = explode('<a href="/problems/tag/', $temp); |
||
108 | for($i = 1;$i < count($cat); $i++) |
||
109 | { |
||
110 | $temp = $cat[$i]; |
||
111 | $temp = explode('">', $temp)[0]; |
||
112 | array_push($cate,$temp); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | $temp = $res->body; |
||
117 | $temp = explode('<div id="problem-body">', $temp)[1]; |
||
118 | $content = explode('<div class="text-center">', $temp)[0]; |
||
119 | |||
120 | $this->pro['description'] = $this->cacheImage(HtmlDomParser::str_get_html(explode('<h3>Input</h3>', $content)[0], true, true, DEFAULT_TARGET_CHARSET, false)); |
||
121 | $content = explode('<h3>Input</h3>', $content)[1]; |
||
122 | $this->pro['input'] = explode('<h3>Output</h3>', $content)[0]; |
||
123 | $content = explode('<h3>Output</h3>', $content)[1]; |
||
124 | $tgis->pro['output'] = explode('<h3>Example</h3>', $content)[0]; |
||
125 | $content = explode('<h3>Example</h3>', $content)[1]; |
||
126 | |||
176 | } |