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