| Conditions | 4 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 82 | public function updateCMSFields(FieldList $fields) |
||
| 83 | { |
||
| 84 | $owner = $this->getOwner(); |
||
| 85 | $viewAllGroupsMap = PermissionCanViewListMaker::get_list(); |
||
| 86 | $fields->removeFieldFromTab('Root', 'ViewerGroups'); |
||
| 87 | $fields->addFieldsToTab( |
||
| 88 | 'Root.Permissions', |
||
| 89 | [ |
||
| 90 | $viewersOptionsField = (new OptionsetField( |
||
| 91 | 'CanViewType', |
||
| 92 | _t(__CLASS__ . '.ACCESSHEADER', 'Who can view this elemental block?') |
||
| 93 | )) |
||
| 94 | ->setDescription(' |
||
| 95 | As an Administrator, |
||
| 96 | you can always see ALL blocks - no matter what - otherwise you could not edit them.'), |
||
| 97 | $viewerGroupsField = TreeMultiselectField::create( |
||
| 98 | 'ViewerGroups', |
||
| 99 | _t(__CLASS__ . '.VIEWERGROUPS', 'Viewer Groups'), |
||
| 100 | Group::class |
||
| 101 | ), |
||
| 102 | ] |
||
| 103 | ); |
||
| 104 | |||
| 105 | $viewersOptionsSource = [ |
||
| 106 | InheritedPermissions::ANYONE => _t(__CLASS__ . '.ACCESSANYONEWITHPAGEACCESS', 'Anyone who can view the parent page'), |
||
| 107 | self::NOT_LOGGED_IN_USERS => _t(__CLASS__ . '.ACCESSNOTLOGGEDIN', 'Logged-out users'), |
||
| 108 | InheritedPermissions::LOGGED_IN_USERS => _t(__CLASS__ . '.ACCESSLOGGEDIN', 'Logged-in users'), |
||
| 109 | InheritedPermissions::ONLY_THESE_USERS => _t( |
||
| 110 | __CLASS__ . '.ACCESSONLYTHESE', |
||
| 111 | 'Only these groups (choose from list)' |
||
| 112 | ), |
||
| 113 | ]; |
||
| 114 | $viewersOptionsField->setSource($viewersOptionsSource); |
||
| 115 | |||
| 116 | if ($viewAllGroupsMap) { |
||
| 117 | $viewerGroupsField->setDescription(_t( |
||
| 118 | __CLASS__ . '.VIEWER_GROUPS_FIELD_DESC', |
||
| 119 | 'Groups with global view permissions: {groupList}', |
||
| 120 | ['groupList' => implode(', ', array_values($viewAllGroupsMap))] |
||
| 121 | )); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (! Permission::check('SITETREE_GRANT_ACCESS')) { |
||
| 125 | $fields->makeFieldReadonly($viewersOptionsField); |
||
| 126 | if (InheritedPermissions::ONLY_THESE_USERS === $owner->CanEditType) { |
||
| 127 | $fields->makeFieldReadonly($viewerGroupsField); |
||
| 128 | } else { |
||
| 129 | $fields->removeByName('ViewerGroups'); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | return $fields; |
||
| 134 | } |
||
| 136 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.