| Conditions | 10 |
| Paths | 13 |
| Total Lines | 39 |
| Code Lines | 29 |
| 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 |
||
| 10 | function theme_commons_events_attending_event($variables = array()) { |
||
| 11 | global $user; |
||
| 12 | $event = $variables['event']; |
||
| 13 | if (!$event->nid) { |
||
| 14 | return ''; |
||
| 15 | } |
||
| 16 | |||
| 17 | $attendee_count = isset($variables['attendee_count']) ? $variables['attendee_count'] : 0; |
||
| 18 | |||
| 19 | $registration_type = registration_get_entity_registration_type('node', $event); |
||
| 20 | $registration = entity_get_controller('registration')->create(array( |
||
| 21 | 'entity_type' => 'node', |
||
| 22 | 'entity_id' => $event->nid, |
||
| 23 | 'type' => $registration_type, |
||
| 24 | 'author_uid' => $user->uid, |
||
| 25 | )); |
||
| 26 | |||
| 27 | if (!function_exists('commons_events_attend_event_form') |
||
| 28 | || !function_exists('commons_events_cancel_event_form')) { |
||
| 29 | module_load_include('inc', 'commons_events', 'includes/commons_events.forms'); |
||
| 30 | } |
||
| 31 | if (!registration_is_registered($registration, NULL, $user->uid) |
||
| 32 | && registration_access('create', $registration, $user, $registration->type) |
||
| 33 | && registration_status('node', $event->nid, TRUE)) { |
||
| 34 | return drupal_get_form('commons_events_attend_event_form_' . $event->nid, $event, $registration, $attendee_count); |
||
| 35 | } |
||
| 36 | elseif (registration_is_registered($registration, NULL, $user->uid) && |
||
| 37 | registration_access('delete', $registration, $user, $registration->type)) { |
||
| 38 | $query = new EntityFieldQuery(); |
||
| 39 | $query->entityCondition('entity_type', 'registration') |
||
| 40 | ->propertyCondition('user_uid', $user->uid) |
||
| 41 | ->propertyCondition('entity_id', $event->nid) |
||
| 42 | ->propertyCondition('entity_type', 'node'); |
||
| 43 | $result = $query->execute(); |
||
| 44 | |||
| 45 | return drupal_get_form('commons_events_cancel_event_form_' . $event->nid, $event, $result['registration']); |
||
| 46 | } |
||
| 47 | return ""; |
||
| 48 | } |
||
| 49 | |||
| 67 |