Conditions | 14 |
Paths | 864 |
Total Lines | 52 |
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 |
||
72 | public static function generate_stats_array( $prefix = '' ) { |
||
73 | $return = array(); |
||
74 | |||
75 | $return[ "{$prefix}version" ] = JETPACK__VERSION; |
||
76 | $return[ "{$prefix}wp-version" ] = get_bloginfo( 'version' ); |
||
77 | $return[ "{$prefix}php-version" ] = PHP_VERSION; |
||
78 | $return[ "{$prefix}branch" ] = (float) JETPACK__VERSION; |
||
79 | $return[ "{$prefix}wp-branch" ] = (float) get_bloginfo( 'version' ); |
||
80 | $return[ "{$prefix}php-branch" ] = (float) PHP_VERSION; |
||
81 | $return[ "{$prefix}public" ] = Jetpack_Options::get_option( 'public' ); |
||
82 | $return[ "{$prefix}ssl" ] = Jetpack::permit_ssl(); |
||
83 | $return[ "{$prefix}is-https" ] = is_ssl() ? 'https' : 'http'; |
||
84 | $return[ "{$prefix}language" ] = get_bloginfo( 'language' ); |
||
85 | $return[ "{$prefix}charset" ] = get_bloginfo( 'charset' ); |
||
86 | $return[ "{$prefix}is-multisite" ] = is_multisite() ? 'multisite' : 'singlesite'; |
||
87 | $return[ "{$prefix}identitycrisis" ] = Jetpack::check_identity_crisis() ? 'yes' : 'no'; |
||
88 | $return[ "{$prefix}plugins" ] = implode( ',', Jetpack::get_active_plugins() ); |
||
89 | if ( function_exists( 'get_mu_plugins' ) ) { |
||
90 | $return[ "{$prefix}mu-plugins" ] = implode( ',', array_keys( get_mu_plugins() ) ); |
||
91 | } |
||
92 | $return[ "{$prefix}manage-enabled" ] = true; |
||
93 | |||
94 | $xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() ); |
||
95 | if ( $xmlrpc_errors ) { |
||
96 | $return[ "{$prefix}xmlrpc-errors" ] = implode( ',', array_keys( $xmlrpc_errors ) ); |
||
97 | Jetpack_Options::delete_option( 'xmlrpc_errors' ); |
||
98 | } |
||
99 | |||
100 | // Missing the connection owner? |
||
101 | $connection_manager = new Manager(); |
||
102 | $return[ "{$prefix}missing-owner" ] = $connection_manager->is_missing_connection_owner(); |
||
103 | |||
104 | // is-multi-network can have three values, `single-site`, `single-network`, and `multi-network`. |
||
105 | $return[ "{$prefix}is-multi-network" ] = 'single-site'; |
||
106 | if ( is_multisite() ) { |
||
107 | $return[ "{$prefix}is-multi-network" ] = Jetpack::is_multi_network() ? 'multi-network' : 'single-network'; |
||
108 | } |
||
109 | |||
110 | if ( ! empty( $_SERVER['SERVER_ADDR'] ) || ! empty( $_SERVER['LOCAL_ADDR'] ) ) { |
||
111 | $ip = ! empty( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; |
||
112 | $ip_arr = array_map( 'intval', explode( '.', $ip ) ); |
||
113 | if ( 4 === count( $ip_arr ) ) { |
||
114 | $return[ "{$prefix}ip-2-octets" ] = implode( '.', array_slice( $ip_arr, 0, 2 ) ); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | foreach ( Jetpack::get_available_modules() as $slug ) { |
||
119 | $return[ "{$prefix}module-{$slug}" ] = Jetpack::is_module_active( $slug ) ? 'on' : 'off'; |
||
120 | } |
||
121 | |||
122 | return $return; |
||
123 | } |
||
124 | |||
187 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.