| Total Complexity | 77 | 
| Total Lines | 319 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 1 | 
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 11 | class Standard extends \MySociety\TheyWorkForYou\AlertView { | 
            ||
| 12 | public $data;  | 
            ||
| 13 | |||
| 14 |     public function __construct($THEUSER = null) { | 
            ||
| 15 | parent::__construct($THEUSER);  | 
            ||
| 16 | $this->data = [];  | 
            ||
| 17 | }  | 
            ||
| 18 | |||
| 19 |     public function display() { | 
            ||
| 38 | }  | 
            ||
| 39 | |||
| 40 |     private function processAction() { | 
            ||
| 41 |         $token = get_http_var('t'); | 
            ||
| 42 | $alert = $this->alert->check_token($token);  | 
            ||
| 43 | |||
| 44 | $this->data['results'] = false;  | 
            ||
| 45 |         if ($action = get_http_var('action')) { | 
            ||
| 46 | $success = true;  | 
            ||
| 47 |             if ($action == 'Confirm') { | 
            ||
| 48 | $success = $this->confirmAlert($token);  | 
            ||
| 49 |                 if ($success) { | 
            ||
| 50 | $this->data['results'] = 'alert-confirmed';  | 
            ||
| 51 | $this->data['criteria'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->alert->criteria);  | 
            ||
| 52 | }  | 
            ||
| 53 |             } elseif ($action == 'Suspend') { | 
            ||
| 54 | $success = $this->suspendAlert($token);  | 
            ||
| 55 |                 if ($success) { | 
            ||
| 56 | $this->data['results'] = 'alert-suspended';  | 
            ||
| 57 | }  | 
            ||
| 58 |             } elseif ($action == 'Resume') { | 
            ||
| 59 | $success = $this->resumeAlert($token);  | 
            ||
| 60 |                 if ($success) { | 
            ||
| 61 | $this->data['results'] = 'alert-resumed';  | 
            ||
| 62 | }  | 
            ||
| 63 |             } elseif ($action == 'Delete') { | 
            ||
| 64 | $success = $this->deleteAlert($token);  | 
            ||
| 65 |                 if ($success) { | 
            ||
| 66 | $this->data['results'] = 'alert-deleted';  | 
            ||
| 67 | }  | 
            ||
| 68 |             } elseif ($action == 'Delete All') { | 
            ||
| 69 | $success = $this->deleteAllAlerts($token);  | 
            ||
| 70 |                 if ($success) { | 
            ||
| 71 | $this->data['results'] = 'all-alerts-deleted';  | 
            ||
| 72 | }  | 
            ||
| 73 | }  | 
            ||
| 74 |             if (!$success) { | 
            ||
| 75 | $this->data['results'] = 'alert-fail';  | 
            ||
| 76 | }  | 
            ||
| 77 | }  | 
            ||
| 78 | |||
| 79 | $this->data['alert'] = $alert;  | 
            ||
| 80 | }  | 
            ||
| 81 | |||
| 82 | |||
| 83 |     private function getBasicData() { | 
            ||
| 109 | }  | 
            ||
| 110 | |||
| 111 |     private function checkInput() { | 
            ||
| 156 | }  | 
            ||
| 157 | |||
| 158 |     private function searchForConstituenciesAndMembers() { | 
            ||
| 159 | // Do the search  | 
            ||
| 160 |         if ($this->data['alertsearch']) { | 
            ||
| 161 | $this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['alertsearch'], true);  | 
            ||
| 162 | [$this->data['constituencies'], $this->data['valid_postcode']] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']);  | 
            ||
| 163 |         } else { | 
            ||
| 164 | $this->data['members'] = [];  | 
            ||
| 165 | }  | 
            ||
| 166 | |||
| 167 | # If the above search returned one result for constituency  | 
            ||
| 168 | # search by postcode, use it immediately  | 
            ||
| 169 |         if (isset($this->data['constituencies']) && count($this->data['constituencies']) == 1 && $this->data['valid_postcode']) { | 
            ||
| 170 | $MEMBER = new \MEMBER(['constituency' => $this->data['constituencies'][0], 'house' => 1]);  | 
            ||
| 171 | $this->data['pid'] = $MEMBER->person_id();  | 
            ||
| 172 | $this->data['pc'] = $this->data['alertsearch'];  | 
            ||
| 173 | unset($this->data['constituencies']);  | 
            ||
| 174 | $this->data['alertsearch'] = '';  | 
            ||
| 175 | }  | 
            ||
| 176 | |||
| 177 |         if (isset($this->data['constituencies'])) { | 
            ||
| 178 | $cons = [];  | 
            ||
| 179 |             foreach ($this->data['constituencies'] as $constituency) { | 
            ||
| 180 |                 try { | 
            ||
| 181 | $MEMBER = new \MEMBER(['constituency' => $constituency, 'house' => 1]);  | 
            ||
| 182 | $cons[$constituency] = $MEMBER;  | 
            ||
| 183 |                 } catch (\MySociety\TheyWorkForYou\MemberException $e) { | 
            ||
| 184 | // do nothing  | 
            ||
| 185 | }  | 
            ||
| 186 | }  | 
            ||
| 187 | $this->data['constituencies'] = $cons;  | 
            ||
| 188 | }  | 
            ||
| 189 | }  | 
            ||
| 190 | |||
| 191 |     private function addAlert() { | 
            ||
| 234 | }  | 
            ||
| 235 | |||
| 236 | |||
| 237 |     private function formatSearchTerms() { | 
            ||
| 243 | }  | 
            ||
| 244 | }  | 
            ||
| 245 | |||
| 246 |     private function checkForCommonMistakes() { | 
            ||
| 247 | $mistakes = [];  | 
            ||
| 248 |         if (strstr($this->data['alertsearch'], ',') > -1) { | 
            ||
| 249 | $mistakes['multiple'] = 1;  | 
            ||
| 250 | }  | 
            ||
| 251 | |||
| 252 | if (  | 
            ||
| 253 |             preg_match('#([A-Z]{1,2}\d+[A-Z]? ?\d[A-Z]{2})#i', $this->data['alertsearch'], $m) && | 
            ||
| 254 | strlen($this->data['alertsearch']) > strlen($m[1]) &&  | 
            ||
| 255 | validate_postcode($m[1])  | 
            ||
| 256 |         ) { | 
            ||
| 257 | $this->data['postcode'] = $m[1];  | 
            ||
| 258 | $mistakes['postcode_and'] = 1;  | 
            ||
| 259 | }  | 
            ||
| 260 | |||
| 261 | $this->data['mistakes'] = $mistakes;  | 
            ||
| 262 | }  | 
            ||
| 263 | |||
| 264 |     private function formatSearchMemberData() { | 
            ||
| 302 | }  | 
            ||
| 303 | }  | 
            ||
| 304 | |||
| 305 |     private function setUserData() { | 
            ||
| 335 |