Conditions | 4 |
Paths | 3 |
Total Lines | 61 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
88 | private function validate() |
||
89 | { |
||
90 | sleep(1); |
||
91 | |||
92 | $this->makePostVars(); |
||
93 | |||
94 | $user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'; |
||
95 | $options = [ |
||
96 | CURLOPT_CUSTOMREQUEST => 'POST', //set request type post or get |
||
97 | CURLOPT_POST => 1, //set to GET |
||
98 | CURLOPT_USERAGENT => $user_agent, //"test from www.sunnysideup.co.nz",//$user_agent, //set user agent |
||
99 | CURLOPT_COOKIEFILE => 'cookie.txt', //set cookie file |
||
100 | CURLOPT_COOKIEJAR => 'cookie.txt', //set cookie jar |
||
101 | CURLOPT_RETURNTRANSFER => true, // return web page |
||
102 | CURLOPT_HEADER => false, // don't return headers |
||
103 | CURLOPT_FOLLOWLOCATION => true, // follow redirects |
||
104 | CURLOPT_ENCODING => '', // handle all encodings |
||
105 | CURLOPT_AUTOREFERER => true, // set referer on redirect |
||
106 | CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect |
||
107 | CURLOPT_TIMEOUT => 120, // timeout on response |
||
108 | CURLOPT_MAXREDIRS => 10, // stop after 10 redirects |
||
109 | CURLOPT_POSTFIELDS => $this->postVars, |
||
110 | CURLOPT_URL => $this->baseURL, |
||
111 | ]; |
||
112 | // Initialize the curl session |
||
113 | $ch = curl_init(); |
||
114 | curl_setopt_array($ch, $options); |
||
115 | // Execute the session and capture the response |
||
116 | $out = curl_exec($ch); |
||
117 | |||
118 | //$err = curl_errno( $ch ); |
||
119 | //$errmsg = curl_error( $ch ); |
||
120 | //$header = curl_getinfo( $ch ); |
||
121 | $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
122 | if ($httpCode === 200) { |
||
123 | $doc = simplexml_load_string($out); |
||
124 | $doc->registerXPathNamespace('m', 'http://www.w3.org/2005/10/markup-validator'); |
||
125 | |||
126 | //valid ?? |
||
127 | $nodes = $doc->xpath('//m:markupvalidationresponse/m:validity'); |
||
128 | $this->validResult = strval($nodes[0]) === 'true' ? true : false; |
||
129 | |||
130 | //error count ?? |
||
131 | $nodes = $doc->xpath('//m:markupvalidationresponse/m:errors/m:errorcount'); |
||
132 | $this->errorCount = strval($nodes[0]); |
||
133 | //errors |
||
134 | $nodes = $doc->xpath('//m:markupvalidationresponse/m:errors/m:errorlist/m:error'); |
||
135 | foreach ($nodes as $node) { |
||
136 | //line |
||
137 | $nodes = $node->xpath('m:line'); |
||
138 | $line = strval($nodes[0]); |
||
139 | //col |
||
140 | $nodes = $node->xpath('m:col'); |
||
141 | $col = strval($nodes[0]); |
||
142 | //message |
||
143 | $nodes = $node->xpath('m:message'); |
||
144 | $message = strval($nodes[0]); |
||
145 | $this->errorList[] = $message . "(${line},${col})"; |
||
146 | } |
||
147 | } |
||
148 | return $httpCode; |
||
149 | } |
||
151 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.