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