| Conditions | 10 |
| Paths | 14 |
| Total Lines | 42 |
| Code Lines | 20 |
| 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 |
||
| 34 | public static function verify_certificate($host, $cert) { |
||
| 35 | // Calculate the valid wildcard match if the host is not an IP address |
||
| 36 | $parts = explode('.', $host); |
||
| 37 | if (ip2long($host) === false) { |
||
| 38 | $parts[0] = '*'; |
||
| 39 | } |
||
| 40 | $wildcard = implode('.', $parts); |
||
| 41 | |||
| 42 | $has_dns_alt = false; |
||
| 43 | |||
| 44 | // Check the subjectAltName |
||
| 45 | if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) { |
||
| 46 | $altnames = explode(',', $cert['extensions']['subjectAltName']); |
||
| 47 | foreach ($altnames as $altname) { |
||
| 48 | $altname = trim($altname); |
||
| 49 | if (strpos($altname, 'DNS:') !== 0) { |
||
| 50 | continue; |
||
| 51 | } |
||
| 52 | |||
| 53 | $has_dns_alt = true; |
||
| 54 | |||
| 55 | // Strip the 'DNS:' prefix and trim whitespace |
||
| 56 | $altname = trim(substr($altname, 4)); |
||
| 57 | |||
| 58 | // Check for a match |
||
| 59 | if (self::match_domain($host, $altname) === true) { |
||
| 60 | return true; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | // Fall back to checking the common name if we didn't get any dNSName |
||
| 66 | // alt names, as per RFC2818 |
||
| 67 | if (!$has_dns_alt && !empty($cert['subject']['CN'])) { |
||
| 68 | // Check for a match |
||
| 69 | if (self::match_domain($host, $cert['subject']['CN']) === true) { |
||
| 70 | return true; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return false; |
||
| 75 | } |
||
| 76 | |||
| 154 | } |