| Conditions | 16 | 
| Paths | 18432 | 
| Total Lines | 131 | 
| 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 | ||
| 180 | 	function get_initial_state() { | ||
| 181 | // Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page | ||
| 182 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php'; | ||
| 183 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php'; | ||
| 184 | $moduleListEndpoint = new Jetpack_Core_API_Module_List_Endpoint(); | ||
| 185 | $modules = $moduleListEndpoint->get_modules(); | ||
| 186 | |||
| 187 | // Preparing translated fields for JSON encoding by transforming all HTML entities to | ||
| 188 | // respective characters. | ||
| 189 | 		foreach( $modules as $slug => $data ) { | ||
|  | |||
| 190 | $modules[ $slug ]['name'] = html_entity_decode( $data['name'] ); | ||
| 191 | $modules[ $slug ]['description'] = html_entity_decode( $data['description'] ); | ||
| 192 | $modules[ $slug ]['short_description'] = html_entity_decode( $data['short_description'] ); | ||
| 193 | $modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'] ); | ||
| 194 | } | ||
| 195 | |||
| 196 | // Collecting roles that can view site stats. | ||
| 197 | $stats_roles = array(); | ||
| 198 | $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' ); | ||
| 199 | |||
| 200 | 		if ( ! function_exists( 'get_editable_roles' ) ) { | ||
| 201 | require_once ABSPATH . 'wp-admin/includes/user.php'; | ||
| 202 | } | ||
| 203 | 		foreach ( get_editable_roles() as $slug => $role ) { | ||
| 204 | $stats_roles[ $slug ] = array( | ||
| 205 | 'name' => translate_user_role( $role['name'] ), | ||
| 206 | 'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false, | ||
| 207 | ); | ||
| 208 | } | ||
| 209 | |||
| 210 | // Get information about current theme. | ||
| 211 | $current_theme = wp_get_theme(); | ||
| 212 | |||
| 213 | // Get all themes that Infinite Scroll provides support for natively. | ||
| 214 | $inf_scr_support_themes = array(); | ||
| 215 | 		foreach ( Jetpack::glob_php( JETPACK__PLUGIN_DIR . 'modules/infinite-scroll/themes' ) as $path ) { | ||
| 216 | 			if ( is_readable( $path ) ) { | ||
| 217 | $inf_scr_support_themes[] = basename( $path, '.php' ); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | // Get last post, to build the link to Customizer in the Related Posts module. | ||
| 222 | $last_post = get_posts( array( 'posts_per_page' => 1 ) ); | ||
| 223 | $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post | ||
| 224 | ? get_permalink( $last_post[0]->ID ) | ||
| 225 | : get_home_url(); | ||
| 226 | |||
| 227 | $current_user_data = jetpack_current_user_data(); | ||
| 228 | |||
| 229 | return array( | ||
| 230 | 'WP_API_root' => esc_url_raw( rest_url() ), | ||
| 231 | 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), | ||
| 232 | 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), | ||
| 233 | 'connectionStatus' => array( | ||
| 234 | 'isActive' => Jetpack::is_active(), | ||
| 235 | 'isStaging' => Jetpack::is_staging_site(), | ||
| 236 | 'devMode' => array( | ||
| 237 | 'isActive' => ( new Status() )->is_development_mode(), | ||
| 238 | 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, | ||
| 239 | 'url' => site_url() && false === strpos( site_url(), '.' ), | ||
| 240 | 'filter' => apply_filters( 'jetpack_development_mode', false ), | ||
| 241 | ), | ||
| 242 | 'isPublic' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | ||
| 243 | 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option(), | ||
| 244 | 'sandboxDomain' => JETPACK__SANDBOX_DOMAIN, | ||
| 245 | ), | ||
| 246 | 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | ||
| 247 | ? Jetpack::init()->build_connect_url( true, false, false ) | ||
| 248 | : '', | ||
| 249 | 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), | ||
| 250 | 'isDevVersion' => Jetpack::is_development_version(), | ||
| 251 | 'currentVersion' => JETPACK__VERSION, | ||
| 252 | 'is_gutenberg_available' => true, | ||
| 253 | 'getModules' => $modules, | ||
| 254 | 'rawUrl' => Jetpack::build_raw_urls( get_home_url() ), | ||
| 255 | 'adminUrl' => esc_url( admin_url() ), | ||
| 256 | 'stats' => array( | ||
| 257 | // data is populated asynchronously on page load. | ||
| 258 | 'data' => array( | ||
| 259 | 'general' => false, | ||
| 260 | 'day' => false, | ||
| 261 | 'week' => false, | ||
| 262 | 'month' => false, | ||
| 263 | ), | ||
| 264 | 'roles' => $stats_roles, | ||
| 265 | ), | ||
| 266 | 'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ), | ||
| 267 | 'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ), | ||
| 268 | 'settings' => $this->get_flattened_settings( $modules ), | ||
| 269 | 'userData' => array( | ||
| 270 | 'currentUser' => $current_user_data, | ||
| 271 | ), | ||
| 272 | 'siteData' => array( | ||
| 273 | 'icon' => has_site_icon() | ||
| 274 | ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) | ||
| 275 | : '', | ||
| 276 | 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | ||
| 277 | /** | ||
| 278 | * Whether promotions are visible or not. | ||
| 279 | * | ||
| 280 | * @since 4.8.0 | ||
| 281 | * | ||
| 282 | * @param bool $are_promotions_active Status of promotions visibility. True by default. | ||
| 283 | */ | ||
| 284 | 'showPromotions' => apply_filters( 'jetpack_show_promotions', true ), | ||
| 285 | 'isAtomicSite' => jetpack_is_atomic_site(), | ||
| 286 | 'plan' => Jetpack_Plan::get(), | ||
| 287 | 'showBackups' => Jetpack::show_backups_ui(), | ||
| 288 | 'isMultisite' => is_multisite(), | ||
| 289 | ), | ||
| 290 | 'themeData' => array( | ||
| 291 | 'name' => $current_theme->get( 'Name' ), | ||
| 292 | 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), | ||
| 293 | 'support' => array( | ||
| 294 | 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ), | ||
| 295 | ), | ||
| 296 | ), | ||
| 297 | 'locale' => Jetpack::get_i18n_data_json(), | ||
| 298 | 'localeSlug' => join( '-', explode( '_', get_user_locale() ) ), | ||
| 299 | 'jetpackStateNotices' => array( | ||
| 300 | 'messageCode' => Jetpack::state( 'message' ), | ||
| 301 | 'errorCode' => Jetpack::state( 'error' ), | ||
| 302 | 'errorDescription' => Jetpack::state( 'error_description' ), | ||
| 303 | ), | ||
| 304 | 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), | ||
| 305 | 'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false, | ||
| 306 | 'lastPostUrl' => esc_url( $last_post ), | ||
| 307 | 'externalServicesConnectUrls' => $this->get_external_services_connect_urls(), | ||
| 308 | 'calypsoEnv' => Jetpack::get_calypso_env(), | ||
| 309 | ); | ||
| 310 | } | ||
| 311 | |||
| 385 | 
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.