| Conditions | 5 |
| Paths | 16 |
| Total Lines | 78 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 74 | public function getCMSFields() { |
||
| 75 | $fields = parent::getCMSFields(); |
||
| 76 | $fields->removeFieldFromTab('Root', 'Pages'); |
||
| 77 | $fields->removeFieldsFromTab('Root.Main', array( |
||
| 78 | 'SortOrder', |
||
| 79 | 'showBlockbyClass', |
||
| 80 | 'shownInClass', |
||
| 81 | 'MemberVisibility' |
||
| 82 | )); |
||
| 83 | |||
| 84 | $memberGroups = Group::get(); |
||
| 85 | $sourcemap = $memberGroups->map('Code', 'Title'); |
||
| 86 | $source = array( |
||
| 87 | 'anonymous' => 'Anonymous visitors' |
||
| 88 | ); |
||
| 89 | foreach ($sourcemap as $mapping => $key) { |
||
| 90 | $source[$mapping] = $key; |
||
| 91 | } |
||
| 92 | |||
| 93 | $memberVisibility = new CheckboxSetField( |
||
| 94 | $name = "MemberVisibility", |
||
| 95 | $title = "Show block for specific groups", |
||
| 96 | $source |
||
| 97 | ); |
||
| 98 | |||
| 99 | $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
||
| 100 | |||
| 101 | $availabelClasses = $this->availableClasses(); |
||
| 102 | $inClass = new CheckboxSetField( |
||
| 103 | $name = "shownInClass", |
||
| 104 | $title = "Show block for specific content types", |
||
| 105 | $availabelClasses |
||
| 106 | ); |
||
| 107 | |||
| 108 | $filterSelector = OptionsetField::create( |
||
| 109 | 'showBlockbyClass', |
||
| 110 | 'Choose filter set', |
||
| 111 | array( |
||
| 112 | '0' => 'by page', |
||
| 113 | '1' => 'by page/data type' |
||
| 114 | ) |
||
| 115 | )->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>'); |
||
| 116 | |||
| 117 | $availablePages = Page::get()->exclude('ClassName', array( |
||
| 118 | 'ErrorPage', |
||
| 119 | 'RedirectorPage', |
||
| 120 | 'VirtualPage' |
||
| 121 | )); |
||
| 122 | $pageSelector = new CheckboxSetField( |
||
| 123 | $name = "Pages", |
||
| 124 | $title = "Show on Page(s)", |
||
| 125 | $availablePages->map('ID','Title') |
||
| 126 | ); |
||
| 127 | |||
| 128 | |||
| 129 | if ($this->canConfigPageAndType(Member::currentUser())) { |
||
| 130 | $fields->addFieldsToTab('Root.VisibilitySettings', array( |
||
| 131 | $filterSelector, |
||
| 132 | $pageSelector, |
||
| 133 | $inClass |
||
| 134 | )); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($this->canConfigMemberVisibility(Member::currentUser())) { |
||
| 138 | $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (!$fields->fieldByName('Options')) { |
||
| 142 | $fields->insertBefore($right = RightSidebar::create('Options'), 'Root'); |
||
| 143 | } |
||
| 144 | |||
| 145 | $fields->addFieldsToTab('Options', array( |
||
| 146 | CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), |
||
| 147 | CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper') |
||
| 148 | )); |
||
| 149 | |||
| 150 | return $fields; |
||
| 151 | } |
||
| 152 | |||
| 204 | } |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.