| Conditions | 25 |
| Paths | 24 |
| Total Lines | 59 |
| Code Lines | 33 |
| 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 |
||
| 92 | public static function validateCookieDomain( $domain, $originDomain = null ) { |
||
| 93 | $dc = explode( ".", $domain ); |
||
| 94 | |||
| 95 | // Don't allow a trailing dot or addresses without a or just a leading dot |
||
| 96 | if ( substr( $domain, -1 ) == '.' || |
||
| 97 | count( $dc ) <= 1 || |
||
| 98 | count( $dc ) == 2 && $dc[0] === '' |
||
| 99 | ) { |
||
| 100 | return false; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Only allow full, valid IP addresses |
||
| 104 | if ( preg_match( '/^[0-9.]+$/', $domain ) ) { |
||
| 105 | if ( count( $dc ) != 4 ) { |
||
| 106 | return false; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ( ip2long( $domain ) === false ) { |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ( $originDomain == null || $originDomain == $domain ) { |
||
|
|
|||
| 114 | return true; |
||
| 115 | } |
||
| 116 | |||
| 117 | } |
||
| 118 | |||
| 119 | // Don't allow cookies for "co.uk" or "gov.uk", etc, but allow "supermarket.uk" |
||
| 120 | if ( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) { |
||
| 121 | if ( ( count( $dc ) == 2 && strlen( $dc[0] ) <= 2 ) |
||
| 122 | || ( count( $dc ) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) { |
||
| 123 | return false; |
||
| 124 | } |
||
| 125 | if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == '' ) ) |
||
| 126 | && preg_match( '/(com|net|org|gov|edu)\...$/', $domain ) ) { |
||
| 127 | return false; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | if ( $originDomain != null ) { |
||
| 132 | if ( substr( $domain, 0, 1 ) != '.' && $domain != $originDomain ) { |
||
| 133 | return false; |
||
| 134 | } |
||
| 135 | |||
| 136 | if ( substr( $domain, 0, 1 ) == '.' |
||
| 137 | && substr_compare( |
||
| 138 | $originDomain, |
||
| 139 | $domain, |
||
| 140 | -strlen( $domain ), |
||
| 141 | strlen( $domain ), |
||
| 142 | true |
||
| 143 | ) != 0 |
||
| 144 | ) { |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | return true; |
||
| 150 | } |
||
| 151 | |||
| 209 |