| Conditions | 10 |
| Paths | 82 |
| Total Lines | 49 |
| Code Lines | 28 |
| 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 |
||
| 38 | public function __construct( |
||
| 39 | $id, |
||
| 40 | $displayName = '' |
||
| 41 | ) { |
||
| 42 | parent::__construct($id, self::TYPE, $displayName); |
||
| 43 | $this->icon = self::ICON; |
||
| 44 | |||
| 45 | if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) { |
||
| 46 | $this->contact = []; |
||
|
|
|||
| 47 | |||
| 48 | $parts = explode(":", $this->id); |
||
| 49 | $this->id = end($parts); |
||
| 50 | |||
| 51 | // Search for UID and FN |
||
| 52 | // Before this implementation contacts where stored with their FN property |
||
| 53 | // From now on, the contact's UID is used as identifier |
||
| 54 | // TODO: Remove FN as search range for loading a contact in a polls version later than 1.6 |
||
| 55 | $contacts = \OC::$server->getContactsManager()->search($this->id, ['UID', 'FN']); |
||
| 56 | |||
| 57 | if (count($contacts) === 1) { |
||
| 58 | $this->contact = $contacts[0]; |
||
| 59 | $this->id = $this->contact['UID']; |
||
| 60 | $this->displayName = isset($this->contact['FN']) ? $this->contact['FN'] : $this->displayName; |
||
| 61 | $this->emailAddress = isset($this->contact['EMAIL'][0]) ? $this->contact['EMAIL'][0] : $this->emailAddress; |
||
| 62 | } elseif (count($contacts) > 1) { |
||
| 63 | throw new MultipleContactsFound('Multiple contacts found for id ' . $this->id); |
||
| 64 | } |
||
| 65 | |||
| 66 | $this->organisation = isset($this->contact['ORG']) ? $this->contact['ORG'] : ''; |
||
| 67 | |||
| 68 | if (isset($this->contact['CATEGORIES'])) { |
||
| 69 | $this->categories = explode(',', $this->contact['CATEGORIES']); |
||
| 70 | } else { |
||
| 71 | $this->categories = []; |
||
| 72 | } |
||
| 73 | |||
| 74 | $description = $this->categories; |
||
| 75 | |||
| 76 | if (isset($this->contact['ORG'])) { |
||
| 77 | array_unshift($description, $this->organisation); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (count($description) > 0) { |
||
| 81 | $this->description = implode(", ", $description); |
||
| 82 | } else { |
||
| 83 | $this->description = \OC::$server->getL10N('polls')->t('Contact'); |
||
| 84 | } |
||
| 85 | } else { |
||
| 86 | throw new ContactsNotEnabled(); |
||
| 87 | } |
||
| 132 |