| Conditions | 5 |
| Paths | 16 |
| Total Lines | 82 |
| Code Lines | 55 |
| 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 |
||
| 81 | public function getCMSFields() { |
||
| 82 | $fields = parent::getCMSFields(); |
||
| 83 | $fields->removeFieldFromTab('Root', 'Pages'); |
||
| 84 | $fields->removeFieldsFromTab('Root.Main', array( |
||
| 85 | 'SortOrder', |
||
| 86 | 'showBlockbyClass', |
||
| 87 | 'shownInClass', |
||
| 88 | 'MemberVisibility' |
||
| 89 | )); |
||
| 90 | |||
| 91 | $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title'); |
||
| 92 | |||
| 93 | $memberGroups = Group::get(); |
||
| 94 | $sourcemap = $memberGroups->map('Code', 'Title'); |
||
| 95 | $source = array( |
||
| 96 | 'anonymous' => 'Anonymous visitors' |
||
| 97 | ); |
||
| 98 | foreach ($sourcemap as $mapping => $key) { |
||
| 99 | $source[$mapping] = $key; |
||
| 100 | } |
||
| 101 | |||
| 102 | $memberVisibility = new CheckboxSetField( |
||
| 103 | $name = "MemberVisibility", |
||
| 104 | $title = "Show block for specific groups", |
||
| 105 | $source |
||
| 106 | ); |
||
| 107 | |||
| 108 | $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
||
| 109 | |||
| 110 | $availabelClasses = $this->availableClasses(); |
||
| 111 | $inClass = new CheckboxSetField( |
||
| 112 | $name = "shownInClass", |
||
| 113 | $title = "Show block for specific content types", |
||
| 114 | $availabelClasses |
||
| 115 | ); |
||
| 116 | |||
| 117 | $filterSelector = OptionsetField::create( |
||
| 118 | 'showBlockbyClass', |
||
| 119 | 'Choose filter set', |
||
| 120 | array( |
||
| 121 | '0' => 'by page', |
||
| 122 | '1' => 'by page/data type' |
||
| 123 | ) |
||
| 124 | )->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); |
||
| 125 | |||
| 126 | $availablePages = Page::get()->exclude('ClassName', array( |
||
| 127 | 'ErrorPage', |
||
| 128 | 'RedirectorPage', |
||
| 129 | 'VirtualPage' |
||
| 130 | )); |
||
| 131 | $pageSelector = new CheckboxSetField( |
||
| 132 | $name = "Pages", |
||
| 133 | $title = "Show on Page(s)", |
||
| 134 | $availablePages->map('ID','Title') |
||
| 135 | ); |
||
| 136 | |||
| 137 | |||
| 138 | if ($this->canConfigPageAndType(Member::currentUser())) { |
||
| 139 | $fields->addFieldsToTab('Root.VisibilitySettings', array( |
||
| 140 | $filterSelector, |
||
| 141 | $pageSelector, |
||
| 142 | $inClass |
||
| 143 | )); |
||
| 144 | } |
||
| 145 | |||
| 146 | if ($this->canConfigMemberVisibility(Member::currentUser())) { |
||
| 147 | $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
||
| 148 | } |
||
| 149 | |||
| 150 | if (!$fields->fieldByName('Options')) { |
||
| 151 | $fields->insertBefore($right = RightSidebar::create('Options'), 'Root'); |
||
| 152 | } |
||
| 153 | |||
| 154 | $fields->addFieldsToTab('Options', array( |
||
| 155 | CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), |
||
| 156 | CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper'), |
||
| 157 | CheckboxField::create('addPaddingTop', 'add "padding-top" class to block wrapper'), |
||
| 158 | CheckboxField::create('addPaddingBottom', 'add "padding-bottom" class to block wrapper') |
||
| 159 | )); |
||
| 160 | |||
| 161 | return $fields; |
||
| 162 | } |
||
| 163 | |||
| 262 |
This check marks private properties in classes that are never used. Those properties can be removed.