| Conditions | 7 |
| Paths | 7 |
| Total Lines | 53 |
| Lines | 53 |
| Ratio | 100 % |
| 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 |
||
| 73 | View Code Duplication | public static function is_usable_domain( $domain, $extra = array() ) { |
|
| 74 | |||
| 75 | // If it's empty, just fail out. |
||
| 76 | if ( ! $domain ) { |
||
| 77 | return new WP_Error( 'fail_domain_empty', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is empty.', 'jetpack' ), $domain ) ); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Skips the usuable domain check when connecting a site. |
||
| 82 | * |
||
| 83 | * Allows site administrators with domains that fail gethostname-based checks to pass the request to WP.com |
||
| 84 | * |
||
| 85 | * @since 4.1.0 |
||
| 86 | * |
||
| 87 | * @param bool If the check should be skipped. Default false. |
||
| 88 | */ |
||
| 89 | if ( apply_filters( 'jetpack_skip_usuable_domain_check', false ) ) { |
||
| 90 | return true; |
||
| 91 | } |
||
| 92 | |||
| 93 | // None of the explicit localhosts. |
||
| 94 | $forbidden_domains = array( |
||
| 95 | 'wordpress.com', |
||
| 96 | 'localhost', |
||
| 97 | 'localhost.localdomain', |
||
| 98 | '127.0.0.1', |
||
| 99 | 'local.wordpress.test', // VVV |
||
| 100 | 'local.wordpress-trunk.test', // VVV |
||
| 101 | 'src.wordpress-develop.test', // VVV |
||
| 102 | 'build.wordpress-develop.test', // VVV |
||
| 103 | ); |
||
| 104 | if ( in_array( $domain, $forbidden_domains ) ) { |
||
| 105 | return new WP_Error( 'fail_domain_forbidden', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is in the forbidden array.', 'jetpack' ), $domain ) ); |
||
| 106 | } |
||
| 107 | |||
| 108 | // No .test or .local domains |
||
| 109 | if ( preg_match( '#\.(test|local)$#i', $domain ) ) { |
||
| 110 | return new WP_Error( 'fail_domain_tld', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it uses an invalid top level domain.', 'jetpack' ), $domain ) ); |
||
| 111 | } |
||
| 112 | |||
| 113 | // No WPCOM subdomains |
||
| 114 | if ( preg_match( '#\.wordpress\.com$#i', $domain ) ) { |
||
| 115 | return new WP_Error( 'fail_subdomain_wpcom', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is a subdomain of WordPress.com.', 'jetpack' ), $domain ) ); |
||
| 116 | } |
||
| 117 | |||
| 118 | // If PHP was compiled without support for the Filter module (very edge case) |
||
| 119 | if ( ! function_exists( 'filter_var' ) ) { |
||
| 120 | // Just pass back true for now, and let wpcom sort it out. |
||
| 121 | return true; |
||
| 122 | } |
||
| 123 | |||
| 124 | return true; |
||
| 125 | } |
||
| 126 | } |
||
| 127 |