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