| Conditions | 12 | 
| Paths | 448 | 
| Total Lines | 60 | 
| 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  | 
            ||
| 12 | 	public function __construct() { | 
            ||
| 13 | // WordAds setting => default  | 
            ||
| 14 | $settings = array(  | 
            ||
| 15 | 'wordads_approved' => false,  | 
            ||
| 16 | 'wordads_active' => false,  | 
            ||
| 17 | 'wordads_house' => true,  | 
            ||
| 18 | 'wordads_unsafe' => false,  | 
            ||
| 19 | 'enable_header_ad' => true,  | 
            ||
| 20 | 'wordads_second_belowpost' => true,  | 
            ||
| 21 | 'wordads_display_front_page' => true,  | 
            ||
| 22 | 'wordads_display_post' => true,  | 
            ||
| 23 | 'wordads_display_page' => true,  | 
            ||
| 24 | 'wordads_display_archive' => true,  | 
            ||
| 25 | 'wordads_custom_adstxt' => '',  | 
            ||
| 26 | 'wordads_custom_adstxt_enabled' => false,  | 
            ||
| 27 | 'wordads_ccpa_enabled' => false,  | 
            ||
| 28 | 'wordads_ccpa_privacy_policy_url' => get_option( 'wp_page_for_privacy_policy' ) ? get_permalink( (int) get_option( 'wp_page_for_privacy_policy' ) ) : '',  | 
            ||
| 29 | );  | 
            ||
| 30 | |||
| 31 | // grab settings, or set as default if it doesn't exist  | 
            ||
| 32 | $this->options = array();  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 33 | 		foreach ( $settings as $setting => $default ) { | 
            ||
| 34 | $option = get_option( $setting, null );  | 
            ||
| 35 | |||
| 36 | 			if ( is_null( $option ) ) { | 
            ||
| 37 | |||
| 38 | // Handle retroactively setting wordads_custom_adstxt_enabled to true if custom ads.txt content is already entered.  | 
            ||
| 39 | 				if ( 'wordads_custom_adstxt_enabled' === $setting ) { | 
            ||
| 40 | $default = get_option( 'wordads_custom_adstxt' ) !== '';  | 
            ||
| 41 | }  | 
            ||
| 42 | |||
| 43 | update_option( $setting, $default, true );  | 
            ||
| 44 | $option = $default;  | 
            ||
| 45 | }  | 
            ||
| 46 | |||
| 47 | $this->options[ $setting ] = is_bool( $default ) ? (bool) $option : $option;  | 
            ||
| 48 | }  | 
            ||
| 49 | |||
| 50 | $host = 'localhost';  | 
            ||
| 51 | 		if ( isset( $_SERVER['HTTP_HOST'] ) ) { | 
            ||
| 52 | $host = $_SERVER['HTTP_HOST'];  | 
            ||
| 53 | }  | 
            ||
| 54 | |||
| 55 | $this->url = ( is_ssl() ? 'https' : 'http' ) . '://' . $host . $_SERVER['REQUEST_URI'];  | 
            ||
| 56 | 		if ( ! ( false === strpos( $this->url, '?' ) ) && ! isset( $_GET['p'] ) ) { | 
            ||
| 57 | $this->url = substr( $this->url, 0, strpos( $this->url, '?' ) );  | 
            ||
| 58 | }  | 
            ||
| 59 | |||
| 60 | $this->cloudflare = self::is_cloudflare();  | 
            ||
| 61 | $this->blog_id = Jetpack::get_option( 'id', 0 );  | 
            ||
| 62 | $this->mobile_device = jetpack_is_mobile( 'any', true );  | 
            ||
| 63 | $this->targeting_tags = array(  | 
            ||
| 64 | 'WordAds' => 1,  | 
            ||
| 65 | 'BlogId' => ( new Status() )->is_development_mode() ? 0 : Jetpack_Options::get_option( 'id' ),  | 
            ||
| 66 | 'Domain' => esc_js( wp_parse_url( home_url(), PHP_URL_HOST ) ),  | 
            ||
| 67 | 'PageURL' => esc_js( $this->url ),  | 
            ||
| 68 | 'LangId' => false !== strpos( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else?  | 
            ||
| 69 | 'AdSafe' => 1, // TODO  | 
            ||
| 70 | );  | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 238 | 
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: