| Conditions | 8 |
| Paths | 6 |
| Total Lines | 56 |
| 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 |
||
| 93 | public function updateCMSFields(FieldList $fields) |
||
| 94 | { |
||
| 95 | // Redo LDAP metadata fields as read-only and move to LDAP tab. |
||
| 96 | $ldapMetadata = []; |
||
| 97 | $fields->replaceField('GUID', $ldapMetadata[] = ReadonlyField::create('GUID')); |
||
| 98 | $fields->replaceField( |
||
| 99 | 'IsExpired', |
||
| 100 | $ldapMetadata[] = ReadonlyField::create( |
||
| 101 | 'IsExpired', |
||
| 102 | _t('LDAPMemberExtension.ISEXPIRED', 'Has user\'s LDAP/AD login expired?') |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | $fields->replaceField( |
||
| 106 | 'LastSynced', |
||
| 107 | $ldapMetadata[] = ReadonlyField::create( |
||
| 108 | 'LastSynced', |
||
| 109 | _t('LDAPMemberExtension.LASTSYNCED', 'Last synced') |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | $fields->addFieldsToTab('Root.LDAP', $ldapMetadata); |
||
| 113 | |||
| 114 | $message = ''; |
||
| 115 | if ($this->owner->GUID && $this->owner->config()->update_ldap_from_local) { |
||
| 116 | $message = _t( |
||
| 117 | 'LDAPMemberExtension.CHANGEFIELDSUPDATELDAP', |
||
| 118 | 'Changing fields here will update them in LDAP.' |
||
| 119 | ); |
||
| 120 | } elseif ($this->owner->GUID && !$this->owner->config()->update_ldap_from_local) { |
||
| 121 | // Transform the automatically mapped fields into read-only. This doesn't |
||
| 122 | // apply if updating LDAP from local is enabled, as changing data locally can be written back. |
||
| 123 | foreach ($this->owner->config()->ldap_field_mappings as $name) { |
||
| 124 | $field = $fields->dataFieldByName($name); |
||
| 125 | if (!empty($field)) { |
||
| 126 | // Set to readonly, but not disabled so that the data is still sent to the |
||
| 127 | // server and doesn't break Member_Validator |
||
| 128 | $field->setReadonly(true); |
||
| 129 | $field->setTitle($field->Title()._t('LDAPMemberExtension.IMPORTEDFIELD', ' (imported)')); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | $message = _t( |
||
| 133 | 'LDAPMemberExtension.INFOIMPORTED', |
||
| 134 | 'This user is automatically imported from LDAP. '. |
||
| 135 | 'Manual changes to imported fields will be removed upon sync.' |
||
| 136 | ); |
||
| 137 | } |
||
| 138 | if ($message) { |
||
| 139 | $fields->addFieldToTab( |
||
| 140 | 'Root.Main', |
||
| 141 | LiteralField::create( |
||
| 142 | 'Info', |
||
| 143 | sprintf('<p class="message warning">%s</p>', $message) |
||
| 144 | ), |
||
| 145 | 'FirstName' |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 234 |
This check marks private properties in classes that are never used. Those properties can be removed.