Conditions | 3 |
Paths | 2 |
Total Lines | 64 |
Code Lines | 41 |
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 |
||
85 | private function validate() |
||
86 | { |
||
87 | sleep(1); |
||
88 | |||
89 | $this->makePostVars(); |
||
90 | |||
91 | $user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'; |
||
92 | $options = [ |
||
93 | CURLOPT_CUSTOMREQUEST => 'POST', //set request type post or get |
||
94 | CURLOPT_POST => 1, //set to GET |
||
95 | CURLOPT_USERAGENT => $user_agent, //"test from www.sunnysideup.co.nz",//$user_agent, //set user agent |
||
96 | CURLOPT_COOKIEFILE => 'cookie.txt', //set cookie file |
||
97 | CURLOPT_COOKIEJAR => 'cookie.txt', //set cookie jar |
||
98 | CURLOPT_RETURNTRANSFER => true, // return web page |
||
99 | CURLOPT_HEADER => false, // don't return headers |
||
100 | CURLOPT_FOLLOWLOCATION => true, // follow redirects |
||
101 | CURLOPT_ENCODING => '', // handle all encodings |
||
102 | CURLOPT_AUTOREFERER => true, // set referer on redirect |
||
103 | CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect |
||
104 | CURLOPT_TIMEOUT => 120, // timeout on response |
||
105 | CURLOPT_MAXREDIRS => 10, // stop after 10 redirects |
||
106 | CURLOPT_POSTFIELDS => $this->postVars, |
||
107 | CURLOPT_URL => $this->baseURL, |
||
108 | ]; |
||
109 | $httpCode = '000'; |
||
|
|||
110 | |||
111 | // Initialize the curl session |
||
112 | $ch = curl_init(); |
||
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 (200 === $httpCode) { |
||
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 = 'true' === strval($nodes[0]); |
||
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 | return $httpCode; |
||
149 | } |
||
151 |