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