| Conditions | 8 |
| Paths | 12 |
| Total Lines | 55 |
| Code Lines | 34 |
| 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 |
||
| 47 | protected function display_front_senedd() { |
||
| 48 | global $this_page; |
||
| 49 | $this_page = "seneddoverview"; |
||
| 50 | |||
| 51 | $data = array(); |
||
| 52 | |||
| 53 | $data['popular_searches'] = null; |
||
| 54 | |||
| 55 | |||
| 56 | $data['urls'] = $this->getURLs($data); |
||
| 57 | |||
| 58 | $DEBATELIST = new $this->class(); |
||
| 59 | |||
| 60 | $debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); |
||
| 61 | $MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront'); |
||
| 62 | $MOREURL->insert( array( 'more' => 1 ) ); |
||
| 63 | |||
| 64 | // this makes sure that we don't repeat this debate in the list below |
||
| 65 | $random_debate = null; |
||
| 66 | if ( isset($debates['data']) && count($debates['data']) ) { |
||
| 67 | $random_debate = $debates['data'][0]; |
||
| 68 | } |
||
| 69 | |||
| 70 | $recent = array(); |
||
| 71 | if ( isset($debates['data']) && count($debates['data']) ) { |
||
| 72 | // at the start of a session there may be less than 6 |
||
| 73 | // debates |
||
| 74 | $max = 6; |
||
| 75 | if ( count($debates['data']) < 6 ) { |
||
| 76 | $max = count($debates['data']); |
||
| 77 | } |
||
| 78 | for ( $i = 1; $i < $max; $i++ ) { |
||
| 79 | $debate = $debates['data'][$i]; |
||
| 80 | $debate['desc'] = "Senedd"; |
||
| 81 | $debate['more_url'] = $MOREURL->generate(); |
||
| 82 | $recent[] = $debate; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $featured = array(); |
||
| 87 | if ( $random_debate ) { |
||
| 88 | $featured = $random_debate; |
||
| 89 | $featured['more_url'] = $MOREURL->generate(); |
||
| 90 | $featured['desc'] = 'Senedd'; |
||
| 91 | $featured['related'] = array(); |
||
| 92 | $featured['featured'] = false; |
||
| 93 | } |
||
| 94 | |||
| 95 | $data['featured'] = $featured; |
||
| 96 | $data['debates'] = array( 'recent' => $recent); |
||
| 97 | |||
| 98 | $data['regional'] = $this->getMSList(); |
||
| 99 | $data['template'] = 'senedd/index'; |
||
| 100 | |||
| 101 | return $data; |
||
| 102 | } |
||
| 118 |