| Conditions | 7 |
| Paths | 3 |
| Total Lines | 51 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 77 | public function updateCMSFields(FieldList $fields) |
||
| 78 | { |
||
| 79 | // Redo LDAP metadata fields as read-only and move to LDAP tab. |
||
| 80 | $ldapMetadata = array(); |
||
| 81 | $fields->replaceField('IsImportedFromLDAP', $ldapMetadata[] = new ReadonlyField( |
||
| 82 | 'IsImportedFromLDAP', |
||
| 83 | _t('LDAPMemberExtension.ISIMPORTEDFROMLDAP', 'Is user imported from LDAP/AD?') |
||
| 84 | )); |
||
| 85 | $fields->replaceField('GUID', $ldapMetadata[] = new ReadonlyField('GUID')); |
||
| 86 | $fields->replaceField('IsExpired', $ldapMetadata[] = new ReadonlyField( |
||
| 87 | 'IsExpired', |
||
| 88 | _t('LDAPMemberExtension.ISEXPIRED', 'Has user\'s LDAP/AD login expired?')) |
||
| 89 | ); |
||
| 90 | $fields->replaceField('LastSynced', $ldapMetadata[] = new ReadonlyField( |
||
| 91 | 'LastSynced', |
||
| 92 | _t('LDAPMemberExtension.LASTSYNCED', 'Last synced')) |
||
| 93 | ); |
||
| 94 | $fields->addFieldsToTab('Root.LDAP', $ldapMetadata); |
||
| 95 | |||
| 96 | if ($this->owner->IsImportedFromLDAP && $this->owner->config()->update_ldap_from_local) { |
||
| 97 | $message = _t('LDAPMemberExtension.INFOIMPORTEDCANCHANGE', |
||
| 98 | 'This user is automatically imported from LDAP. '. |
||
| 99 | 'Changing fields here will update them in LDAP.' |
||
| 100 | ); |
||
| 101 | } elseif ($this->owner->IsImportedFromLDAP && !$this->owner->config()->update_ldap_from_local) { |
||
| 102 | // Transform the automatically mapped fields into read-only. This doesn't |
||
| 103 | // apply if updating LDAP from local is enabled, as changing data locally can be written back. |
||
| 104 | foreach ($this->owner->config()->ldap_field_mappings as $name) { |
||
| 105 | $field = $fields->dataFieldByName($name); |
||
| 106 | if (!empty($field)) { |
||
| 107 | // Set to readonly, but not disabled so that the data is still sent to the |
||
| 108 | // server and doesn't break Member_Validator |
||
| 109 | $field->setReadonly(true); |
||
| 110 | $field->setTitle($field->Title()._t('LDAPMemberExtension.IMPORTEDFIELD', ' (imported)')); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | $message = _t( |
||
| 114 | 'LDAPMemberExtension.INFOIMPORTED', |
||
| 115 | 'This user is automatically imported from LDAP. '. |
||
| 116 | 'Manual changes to imported fields will be removed upon sync.' |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | $fields->addFieldToTab( |
||
| 120 | 'Root.Main', |
||
| 121 | new LiteralField( |
||
| 122 | 'Info', |
||
| 123 | sprintf('<p class="message warning">%s</p>', $message) |
||
| 124 | ), |
||
| 125 | 'FirstName' |
||
| 126 | ); |
||
| 127 | } |
||
| 128 | |||
| 205 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.