| Conditions | 9 |
| Paths | 72 |
| Total Lines | 66 |
| 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 |
||
| 41 | public function __construct($controller, $name, $moduleProductID = 0) |
||
| 42 | { |
||
| 43 | $fields = new FieldList(); |
||
| 44 | $moduleProduct = null; |
||
| 45 | if ($moduleProductID) { |
||
| 46 | $fields->push(new HeaderField('AddEditModule', 'Edit '.$controller->dataRecord->Title, 2)); |
||
| 47 | $fields->push(new HiddenField('ModuleProductID', $moduleProductID, $moduleProductID)); |
||
| 48 | $moduleProduct = ModuleProduct::get()->byID($moduleProductID); |
||
| 49 | } else { |
||
| 50 | $fields->push(new HeaderField('AddEditModule', $controller->dataRecord->Title, 2)); |
||
| 51 | $fields->push(new HiddenField('ModuleProductID', 0, 0)); |
||
| 52 | } |
||
| 53 | $fields->push(new TextField('Code', 'Code (folder name)')); |
||
| 54 | $moduleProductGroups = ModuleProductGroup::get() |
||
| 55 | ->filter(array("ParentID:GreaterThan" => 0)); |
||
| 56 | if (ModuleProductGroup::get()->count()) { |
||
| 57 | $types = array("" => " --- please select ---"); |
||
| 58 | $types += ModuleProductGroup::get()->map($index = 'ID', $titleField = 'MenuTitle')->toArray(); |
||
| 59 | } else { |
||
| 60 | $types = array(); |
||
| 61 | } |
||
| 62 | //$fields->push(new DropdownField('ParentID','Type', $types, $controller->dataRecord->ID)); |
||
| 63 | $fields->push(new TextField('Title', 'Title')); |
||
| 64 | $fields->push(new TextareaField('MetaDescription', 'Three sentence Introduction')); |
||
| 65 | $fields->push(new HtmlEditorField('Content', 'Long Description')); |
||
| 66 | $fields->push(new TextField('AdditionalTags', 'Additional Keyword(s), comma separated')); |
||
| 67 | $fields->push(new HeaderField('LinkHeader', 'Links', 4)); |
||
| 68 | $fields->push(new TextField('MainURL', 'Home page')); |
||
| 69 | $fields->push(new TextField('ReadMeURL', 'Read me file - e.g. http://www.mymodule.com/readme.md')); |
||
| 70 | $fields->push(new TextField('DemoURL', 'Demo - e.g. http://demo.mymodule.com/')); |
||
| 71 | $fields->push(new TextField('SvnURL', 'SVN repository - allowing you to checkout trunk or latest version - e.g. http://svn.mymodule.com/svn/trunk/')); |
||
| 72 | $fields->push(new TextField('GitURL', 'GIT repository - e.g. https://github.com/my-github-username/silverstripe-my-module')); |
||
| 73 | $fields->push(new TextField('OtherURL', 'Link to other repository or download URL - e.g. http://www.mymodule.com/downloads/')); |
||
| 74 | $fields->push(new CheckboxSetField('EcommerceProductTags', 'Tags', EcommerceProductTag::get()->map()->toArray())); |
||
| 75 | $member = Member::currentUser(); |
||
| 76 | if ($member->inGroup("ADMIN")) { |
||
| 77 | $fields->push(new CheckboxSetField('Authors', 'Author(s)', Member::get()->exclude("Email", "")->map("ID", "Email")->toArray())); |
||
| 78 | $fields->push(new DropdownField('ParentID', 'Move to', ProductGroup::get()->map()->toArray())); |
||
| 79 | $fields->push(new CheckboxField('ShowInMenus', 'Show in menus (unticking both boxes here will hide the module)')); |
||
| 80 | $fields->push(new CheckboxField('ShowInSearch', 'Show in search (unticking both boxes here will hide the module)')); |
||
| 81 | } else { |
||
| 82 | $fields->push(new HiddenField('ShowInMenus', '', 0)); |
||
| 83 | $fields->push(new HiddenField('ShowInSearch', '', 0)); |
||
| 84 | $fields->push(new HiddenField('ParentID', '', $controller->dataRecord->ID)); |
||
| 85 | if ($moduleProduct) { |
||
| 86 | $moduleProduct->ParentID = $controller->dataRecord->ID; |
||
| 87 | $moduleProduct->ShowInSearch = 0; |
||
| 88 | $moduleProduct->ShowInMenus = 0; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | if ($moduleProduct && $moduleProduct->canEdit()) { |
||
| 92 | if ($authors = $moduleProduct->Authors()) { |
||
| 93 | $authorsIDArray = $authors->map("ID", "ID")->toArray(); |
||
| 94 | $authorsIDArray[0] = 0; |
||
| 95 | $fields->push($this->ManyManyComplexTableFieldAuthorsField($controller, $authorsIDArray)); |
||
| 96 | //$controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "" |
||
| 97 | } |
||
| 98 | } |
||
| 99 | $actions = new FieldList(new FormAction("submit", "submit")); |
||
| 100 | $validator = new AddingModuleProduct_RequiredFields($moduleProductID, array('Code', 'Name', 'ParentID', 'MainURL')); |
||
| 101 | parent::__construct($controller, $name, $fields, $actions, $validator); |
||
| 102 | if ($moduleProduct) { |
||
| 103 | $this->loadDataFrom($moduleProduct); |
||
| 104 | } |
||
| 105 | return $this; |
||
| 106 | } |
||
| 107 | |||
| 291 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.