| Conditions | 4 |
| Paths | 4 |
| Total Lines | 87 |
| 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 |
||
| 50 | public function getPanel() { |
||
| 51 | $this->lfactory = \OC::$server->getL10NFactory(); |
||
|
|
|||
| 52 | $activeLangCode = $this->config->getAppValue( |
||
| 53 | 'core', |
||
| 54 | 'shareapi_public_notification_lang', |
||
| 55 | 'owner' |
||
| 56 | ); |
||
| 57 | $this->localeHelper = new LocaleHelper(); |
||
| 58 | list($userLang, $commonLanguages, $languages) = $this->localeHelper->getNormalizedLanguages( |
||
| 59 | $this->lfactory, |
||
| 60 | $activeLangCode |
||
| 61 | ); |
||
| 62 | |||
| 63 | // Allow reset to the defaults when mail notification is sent in the lang of owner |
||
| 64 | if ($userLang['code'] === "owner") { |
||
| 65 | $userLang['name'] = $this->l->t("Owner language"); |
||
| 66 | } else { |
||
| 67 | \array_push( |
||
| 68 | $commonLanguages, |
||
| 69 | [ |
||
| 70 | 'code' => 'owner', |
||
| 71 | 'name' => $this->l->t("Owner language") |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | $selector = new Template('settings', 'language'); |
||
| 77 | $selector->assign('selectName', 'shareapi_public_notification_lang'); |
||
| 78 | $selector->assign('selectId', 'shareapiPublicNotificationLang'); |
||
| 79 | $selector->assign('activelanguage', $userLang); |
||
| 80 | $selector->assign('commonlanguages', $commonLanguages); |
||
| 81 | $selector->assign('languages', $languages); |
||
| 82 | |||
| 83 | $template = new Template('settings', 'panels/admin/filesharing'); |
||
| 84 | $template->assign('allowResharing', $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes')); |
||
| 85 | $template->assign('shareAPIEnabled', $this->config->getAppValue('core', 'shareapi_enabled', 'yes')); |
||
| 86 | $template->assign('allowLinks', $this->config->getAppValue('core', 'shareapi_allow_links', 'yes')); |
||
| 87 | $template->assign('allowPublicUpload', $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes')); |
||
| 88 | $template->assign('enforceLinkPasswordReadOnly', $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no')); |
||
| 89 | $template->assign('enforceLinkPasswordReadWrite', $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no')); |
||
| 90 | $template->assign('enforceLinkPasswordWriteOnly', $this->config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no')); |
||
| 91 | $template->assign('shareDefaultExpireDateSet', $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no')); |
||
| 92 | $template->assign('allowPublicMailNotification', $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no')); |
||
| 93 | $template->assign('publicMailNotificationLang', $selector->fetchPage()); |
||
| 94 | $template->assign('allowSocialShare', $this->config->getAppValue('core', 'shareapi_allow_social_share', 'yes')); |
||
| 95 | $template->assign('allowGroupSharing', $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes')); |
||
| 96 | $template->assign('onlyShareWithGroupMembers', $this->helper->shareWithGroupMembersOnly()); |
||
| 97 | $template->assign('onlyShareWithMembershipGroups', $this->config->getAppValue('core', 'shareapi_only_share_with_membership_groups', 'no') === 'yes'); |
||
| 98 | $template->assign('allowMailNotification', $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no')); |
||
| 99 | $template->assign('allowShareDialogUserEnumeration', $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')); |
||
| 100 | $template->assign('shareDialogUserEnumerationGroupMembers', $this->config->getAppValue('core', 'shareapi_share_dialog_user_enumeration_group_members', 'no')); |
||
| 101 | $excludeGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false; |
||
| 102 | $template->assign('shareExcludeGroups', $excludeGroups); |
||
| 103 | $excludedGroupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
||
| 104 | $excludedGroupsList = \json_decode($excludedGroupsList); |
||
| 105 | $template->assign('shareExcludedGroupsList', $excludedGroupsList !== null ? \implode('|', $excludedGroupsList) : ''); |
||
| 106 | $template->assign('shareExpireAfterNDays', $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7')); |
||
| 107 | $template->assign('shareEnforceExpireDate', $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no')); |
||
| 108 | $template->assign('autoAcceptShare', $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes')); |
||
| 109 | |||
| 110 | $permList = [ |
||
| 111 | [ |
||
| 112 | 'id' => 'cancreate', |
||
| 113 | 'label' => $this->l->t('Create'), |
||
| 114 | 'value' => \OCP\Constants::PERMISSION_CREATE |
||
| 115 | ], |
||
| 116 | [ |
||
| 117 | 'id' => 'canupdate', |
||
| 118 | 'label' => $this->l->t('Change'), |
||
| 119 | 'value' => \OCP\Constants::PERMISSION_UPDATE |
||
| 120 | ], |
||
| 121 | [ |
||
| 122 | 'id' => 'candelete', |
||
| 123 | 'label' => $this->l->t('Delete'), |
||
| 124 | 'value' => \OCP\Constants::PERMISSION_DELETE |
||
| 125 | ], |
||
| 126 | [ |
||
| 127 | 'id' => 'canshare', |
||
| 128 | 'label' => $this->l->t('Share'), |
||
| 129 | 'value' => \OCP\Constants::PERMISSION_SHARE |
||
| 130 | ], |
||
| 131 | ]; |
||
| 132 | $template->assign('shareApiDefaultPermissions', $this->config->getAppValue('core', 'shareapi_default_permissions', \OCP\Constants::PERMISSION_ALL)); |
||
| 133 | $template->assign('shareApiDefaultPermissionsCheckboxes', $permList); |
||
| 134 | $template->assign('coreUserAdditionalInfo', $this->config->getAppValue('core', 'user_additional_info_field', '')); |
||
| 135 | return $template; |
||
| 136 | } |
||
| 137 | |||
| 142 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: