| Conditions | 7 |
| Paths | 2 |
| Total Lines | 58 |
| 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 |
||
| 35 | public function get( $display, $filter = false, $exists = false ) { |
||
| 36 | $arr = []; |
||
| 37 | |||
| 38 | $blogs = $this->collection->get_filtered( $filter ); |
||
| 39 | if ( $blogs ) { |
||
|
|
|||
| 40 | $mydata = MslsOptions::create(); |
||
| 41 | $link = MslsLink::create( $display ); |
||
| 42 | |||
| 43 | foreach ( $blogs as $blog ) { |
||
| 44 | $language = $blog->get_language(); |
||
| 45 | |||
| 46 | $link->src = $this->options->get_flag_url( $language ); |
||
| 47 | $link->alt = $language; |
||
| 48 | |||
| 49 | $is_current_blog = $this->collection->is_current_blog( $blog ); |
||
| 50 | if ( $is_current_blog ) { |
||
| 51 | $url = $mydata->get_current_link(); |
||
| 52 | $link->txt = $blog->get_description(); |
||
| 53 | } else { |
||
| 54 | switch_to_blog( $blog->userblog_id ); |
||
| 55 | |||
| 56 | if ( $this->is_requirements_not_fulfilled( $mydata, $exists, $language ) ) { |
||
| 57 | restore_current_blog(); |
||
| 58 | continue; |
||
| 59 | } else { |
||
| 60 | $url = $mydata->get_permalink( $language ); |
||
| 61 | $link->txt = $blog->get_description(); |
||
| 62 | } |
||
| 63 | |||
| 64 | restore_current_blog(); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ( has_filter( 'msls_output_get' ) ) { |
||
| 68 | /** |
||
| 69 | * Returns HTML-link for an item of the output-arr |
||
| 70 | * |
||
| 71 | * @param string $url |
||
| 72 | * @param MslsLink $link |
||
| 73 | * @param bool $is_current_blog |
||
| 74 | * |
||
| 75 | * @since 0.9.8 |
||
| 76 | * |
||
| 77 | */ |
||
| 78 | $arr[] = ( string ) apply_filters( 'msls_output_get', $url, $link, $is_current_blog ); |
||
| 79 | } else { |
||
| 80 | $arr[] = sprintf( |
||
| 81 | '<a href="%s" title="%s"%s>%s</a>', |
||
| 82 | $url, |
||
| 83 | $link->txt, |
||
| 84 | $is_current_blog ? ' class="current_language"' : '', |
||
| 85 | $link |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return $arr; |
||
| 92 | } |
||
| 93 | |||
| 206 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.