| Conditions | 6 |
| Paths | 16 |
| Total Lines | 143 |
| Code Lines | 102 |
| 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 |
||
| 89 | public function getCMSFields() |
||
| 90 | { |
||
| 91 | $mapFn = function ($groups = []) { |
||
| 92 | $map = []; |
||
| 93 | foreach ($groups as $group) { |
||
| 94 | // Listboxfield values are escaped, use ASCII char instead of » |
||
| 95 | $map[$group->ID] = $group->getBreadcrumbs(' > '); |
||
| 96 | } |
||
| 97 | asort($map); |
||
| 98 | return $map; |
||
| 99 | }; |
||
| 100 | $groupsMap = $mapFn(Group::get()); |
||
| 101 | $viewAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_VIEW_ALL', 'ADMIN'])); |
||
| 102 | $editAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_EDIT_ALL', 'ADMIN'])); |
||
| 103 | |||
| 104 | $fields = FieldList::create( |
||
| 105 | TabSet::create( |
||
| 106 | "Root", |
||
| 107 | $tabMain = Tab::create( |
||
| 108 | 'Main', |
||
| 109 | $titleField = TextField::create("Title", _t(self::class . '.SITETITLE', "Site title")), |
||
| 110 | $taglineField = TextField::create( |
||
| 111 | "Tagline", |
||
| 112 | _t(self::class . '.SITETAGLINE', "Site Tagline/Slogan") |
||
| 113 | ) |
||
| 114 | ), |
||
| 115 | $tabAccess = Tab::create( |
||
| 116 | 'Access', |
||
| 117 | $viewersOptionsField = OptionsetField::create( |
||
| 118 | "CanViewType", |
||
| 119 | _t(self::class . '.VIEWHEADER', "Who can view pages on this site?") |
||
| 120 | ), |
||
| 121 | $viewerGroupsField = ListboxField::create( |
||
| 122 | "ViewerGroups", |
||
| 123 | _t('SilverStripe\\CMS\\Model\\SiteTree.VIEWERGROUPS', "Viewer Groups") |
||
| 124 | ) |
||
| 125 | ->setSource($groupsMap) |
||
| 126 | ->setAttribute( |
||
| 127 | 'data-placeholder', |
||
| 128 | _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
||
| 129 | ), |
||
| 130 | $editorsOptionsField = OptionsetField::create( |
||
| 131 | "CanEditType", |
||
| 132 | _t(self::class . '.EDITHEADER', "Who can edit pages on this site?") |
||
| 133 | ), |
||
| 134 | $editorGroupsField = ListboxField::create( |
||
| 135 | "EditorGroups", |
||
| 136 | _t('SilverStripe\\CMS\\Model\\SiteTree.EDITORGROUPS', "Editor Groups") |
||
| 137 | ) |
||
| 138 | ->setSource($groupsMap) |
||
| 139 | ->setAttribute( |
||
| 140 | 'data-placeholder', |
||
| 141 | _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
||
| 142 | ), |
||
| 143 | $topLevelCreatorsOptionsField = OptionsetField::create( |
||
| 144 | "CanCreateTopLevelType", |
||
| 145 | _t(self::class . '.TOPLEVELCREATE', "Who can create pages in the root of the site?") |
||
| 146 | ), |
||
| 147 | $topLevelCreatorsGroupsField = ListboxField::create( |
||
| 148 | "CreateTopLevelGroups", |
||
| 149 | _t(self::class . '.TOPLEVELCREATORGROUPS', "Top level creators") |
||
| 150 | ) |
||
| 151 | ->setSource($groupsMap) |
||
| 152 | ->setAttribute( |
||
| 153 | 'data-placeholder', |
||
| 154 | _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
||
| 155 | ) |
||
| 156 | ) |
||
| 157 | ), |
||
| 158 | HiddenField::create('ID') |
||
| 159 | ); |
||
| 160 | |||
| 161 | $viewersOptionsSource = []; |
||
| 162 | $viewersOptionsSource["Anyone"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSANYONE', "Anyone"); |
||
| 163 | $viewersOptionsSource["LoggedInUsers"] = _t( |
||
| 164 | 'SilverStripe\\CMS\\Model\\SiteTree.ACCESSLOGGEDIN', |
||
| 165 | "Logged-in users" |
||
| 166 | ); |
||
| 167 | $viewersOptionsSource["OnlyTheseUsers"] = _t( |
||
| 168 | 'SilverStripe\\CMS\\Model\\SiteTree.ACCESSONLYTHESE', |
||
| 169 | "Only these groups (choose from list)" |
||
| 170 | ); |
||
| 171 | $viewersOptionsField->setSource($viewersOptionsSource); |
||
| 172 | |||
| 173 | if ($viewAllGroupsMap) { |
||
| 174 | $viewerGroupsField->setDescription(_t( |
||
| 175 | 'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC', |
||
| 176 | 'Groups with global view permissions: {groupList}', |
||
| 177 | ['groupList' => implode(', ', array_values($viewAllGroupsMap))] |
||
| 178 | )); |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($editAllGroupsMap) { |
||
| 182 | $editorGroupsField->setDescription(_t( |
||
| 183 | 'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC', |
||
| 184 | 'Groups with global edit permissions: {groupList}', |
||
| 185 | ['groupList' => implode(', ', array_values($editAllGroupsMap))] |
||
| 186 | )); |
||
| 187 | } |
||
| 188 | |||
| 189 | $editorsOptionsSource = []; |
||
| 190 | $editorsOptionsSource["LoggedInUsers"] = _t( |
||
| 191 | 'SilverStripe\\CMS\\Model\\SiteTree.EDITANYONE', |
||
| 192 | "Anyone who can log-in to the CMS" |
||
| 193 | ); |
||
| 194 | $editorsOptionsSource["OnlyTheseUsers"] = _t( |
||
| 195 | 'SilverStripe\\CMS\\Model\\SiteTree.EDITONLYTHESE', |
||
| 196 | "Only these groups (choose from list)" |
||
| 197 | ); |
||
| 198 | $editorsOptionsField->setSource($editorsOptionsSource); |
||
| 199 | |||
| 200 | $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); |
||
| 201 | |||
| 202 | if (!Permission::check('EDIT_SITECONFIG')) { |
||
| 203 | $fields->makeFieldReadonly($viewersOptionsField); |
||
| 204 | $fields->makeFieldReadonly($viewerGroupsField); |
||
| 205 | $fields->makeFieldReadonly($editorsOptionsField); |
||
| 206 | $fields->makeFieldReadonly($editorGroupsField); |
||
| 207 | $fields->makeFieldReadonly($topLevelCreatorsOptionsField); |
||
| 208 | $fields->makeFieldReadonly($topLevelCreatorsGroupsField); |
||
| 209 | $fields->makeFieldReadonly($taglineField); |
||
| 210 | $fields->makeFieldReadonly($titleField); |
||
| 211 | } |
||
| 212 | |||
| 213 | if (file_exists(BASE_PATH . '/install.php')) { |
||
| 214 | $fields->addFieldToTab( |
||
| 215 | 'Root.Main', |
||
| 216 | LiteralField::create( |
||
| 217 | 'InstallWarningHeader', |
||
| 218 | '<div class="alert alert-warning">' . _t( |
||
| 219 | 'SilverStripe\\CMS\\Model\\SiteTree.REMOVE_INSTALL_WARNING', |
||
| 220 | 'Warning: You should remove install.php from this SilverStripe install for security reasons.' |
||
| 221 | ) . '</div>' |
||
| 222 | ), |
||
| 223 | 'Title' |
||
| 224 | ); |
||
| 225 | } |
||
| 226 | |||
| 227 | $tabMain->setTitle(_t(self::class . '.TABMAIN', "Main")); |
||
| 228 | $tabAccess->setTitle(_t(self::class . '.TABACCESS', "Access")); |
||
| 229 | $this->extend('updateCMSFields', $fields); |
||
| 230 | |||
| 231 | return $fields; |
||
| 232 | } |
||
| 498 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths