Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 35 |
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 |
||
58 | public function updateCMSFields(FieldList $fields) |
||
59 | { |
||
60 | // Add read-only LDAP metadata fields. |
||
61 | $fields->addFieldToTab('Root.LDAP', ReadonlyField::create('GUID')); |
||
62 | $fields->addFieldToTab('Root.LDAP', ReadonlyField::create('DN')); |
||
63 | $fields->addFieldToTab( |
||
64 | 'Root.LDAP', |
||
65 | ReadonlyField::create( |
||
66 | 'LastSynced', |
||
67 | _t('LDAPGroupExtension.LASTSYNCED', 'Last synced') |
||
68 | ) |
||
69 | ); |
||
70 | |||
71 | if ($this->owner->GUID) { |
||
72 | $fields->replaceField('Title', ReadonlyField::create('Title')); |
||
73 | $fields->replaceField('Description', ReadonlyField::create('Description')); |
||
74 | // Surface the code which is normally hidden from the CMS user. |
||
75 | $fields->addFieldToTab('Root.Members', ReadonlyField::create('Code'), 'Members'); |
||
76 | |||
77 | $message = _t( |
||
78 | 'LDAPGroupExtension.INFOIMPORTED', |
||
79 | 'This group is automatically imported from LDAP.' |
||
80 | ); |
||
81 | $fields->addFieldToTab( |
||
82 | 'Root.Members', |
||
83 | LiteralField::create( |
||
84 | 'Info', |
||
85 | sprintf('<p class="message warning">%s</p>', $message) |
||
86 | ), |
||
87 | 'Title' |
||
88 | ); |
||
89 | |||
90 | $fields->addFieldToTab('Root.LDAP', ReadonlyField::create( |
||
91 | 'LDAPGroupMappingsRO', |
||
92 | _t('LDAPGroupExtension.AUTOMAPPEDGROUPS', 'Automatically mapped LDAP Groups'), |
||
93 | implode('; ', $this->owner->LDAPGroupMappings()->column('DN')) |
||
94 | )); |
||
95 | } else { |
||
96 | $field = GridField::create( |
||
97 | 'LDAPGroupMappings', |
||
98 | _t('LDAPGroupExtension.MAPPEDGROUPS', 'Mapped LDAP Groups'), |
||
99 | $this->owner->LDAPGroupMappings() |
||
100 | ); |
||
101 | $config = GridFieldConfig_RecordEditor::create(); |
||
102 | $config->getComponentByType('GridFieldAddNewButton') |
||
103 | ->setButtonName(_t('LDAPGroupExtension.ADDMAPPEDGROUP', 'Add LDAP group mapping')); |
||
104 | |||
105 | $field->setConfig($config); |
||
106 | $fields->addFieldToTab('Root.LDAP', $field); |
||
107 | } |
||
108 | } |
||
109 | |||
120 |
This check marks private properties in classes that are never used. Those properties can be removed.