| Conditions | 16 |
| Paths | 32 |
| Total Lines | 40 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 20 | public function get_notification_data() { |
||
| 21 | require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
||
| 22 | |||
| 23 | $data = array(); |
||
| 24 | $report = $this->get_report(); |
||
| 25 | $sessions = isset( $report['data']['infobox']['sessions']['value'] ) ? $report['data']['infobox']['sessions']['value'] : 0; |
||
| 26 | $countries = isset( $report['data']['countries'] ) ? $report['data']['countries'] : 0; |
||
| 27 | $english_speaking_countries = monsterinsights_get_english_speaking_countries(); |
||
| 28 | |||
| 29 | if ( $sessions > 0 && is_array( $countries ) && ! empty( $countries ) ) { |
||
| 30 | foreach ( $countries as $country ) { |
||
| 31 | if ( empty( $country['iso'] ) || array_key_exists( $country['iso'], $english_speaking_countries ) ) { |
||
| 32 | continue; |
||
| 33 | } |
||
| 34 | |||
| 35 | if ( $country['sessions'] > 0 ) { |
||
| 36 | // get the country's session percentage by comparing with the total sessions |
||
| 37 | $country_session_percentage = round( $country['sessions'] * 100 / $sessions ); |
||
| 38 | |||
| 39 | if ( $country_session_percentage < 15 ) { |
||
| 40 | continue; |
||
| 41 | } |
||
| 42 | |||
| 43 | $site_language = get_locale(); |
||
| 44 | $translations = wp_get_available_translations(); |
||
| 45 | |||
| 46 | if ( is_array( $translations ) && ! empty( $translations ) ) { |
||
| 47 | $site_iso = isset( $translations[ $site_language ]['iso'] ) ? $translations[ $site_language ]['iso'] : array(); // keep empty array, because site language has no iso setup for en_US language |
||
| 48 | |||
| 49 | if ( is_array( $site_iso ) && ! in_array( $country['iso'], $site_iso ) ) { |
||
| 50 | $data['country'] = $country['name']; |
||
| 51 | $data['percentage'] = $country_session_percentage; |
||
| 52 | break; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | return $data; |
||
| 60 | } |
||
| 101 |