| Conditions | 3 |
| Paths | 3 |
| Total Lines | 65 |
| Code Lines | 44 |
| 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 |
||
| 31 | public function __construct($children = null) { |
||
| 32 | if (is_string($children)) throw new InvalidArgumentException('DocumentConversionField::__construct does not accept a name as its parameter, it defaults to "ImportedFromFile" instead. Use DocumentConversionField::getInnerField()->setName() if you want to change it.'); |
||
| 33 | if ($children) throw new InvalidArgumentException('DocumentConversionField::__construct provides its own fields and does not accept additional children.'); |
||
| 34 | |||
| 35 | // Add JS specific to this field. |
||
| 36 | Requirements::javascript('silverstripe/documentconverter: javascript/DocumentConversionField.js'); |
||
| 37 | |||
| 38 | $fields = FieldList::create(array( |
||
| 39 | HeaderField::create( |
||
| 40 | 'FileWarningHeader', |
||
| 41 | _t( |
||
| 42 | __CLASS__ . '.FileWarningHeader', |
||
| 43 | 'Warning: import will remove all content and subpages of this page.' |
||
| 44 | ), |
||
| 45 | 4 |
||
| 46 | ), |
||
| 47 | $splitHeader = DropdownField::create( |
||
| 48 | 'DocumentConversionField-SplitHeader', |
||
| 49 | _t( |
||
| 50 | __CLASS__ . '.SplitHeader', |
||
| 51 | 'Split document into pages' |
||
| 52 | ), |
||
| 53 | array( |
||
| 54 | 0 => _t(__CLASS__ . '.No','no'), |
||
| 55 | 1 => _t(__CLASS__ . '.EachH1','for each heading 1'), |
||
| 56 | 2 => _t(__CLASS__ . '.EachH2','for each heading 2') |
||
| 57 | ) |
||
| 58 | ), |
||
| 59 | $keepSource = CheckboxField::create( |
||
| 60 | 'DocumentConversionField-KeepSource', |
||
| 61 | _t( |
||
| 62 | __CLASS__ . '.KeepSource', |
||
| 63 | 'Keep the original document. Adds a link to it on TOC, if enabled.' |
||
| 64 | ) |
||
| 65 | ), |
||
| 66 | $chosenFolderID = TreeDropdownField::create( |
||
| 67 | 'DocumentConversionField-ChosenFolderID', |
||
| 68 | _t(__CLASS__ . '.ChooseFolder', 'Choose a folder to save this file'), |
||
| 69 | Folder::class |
||
| 70 | ), |
||
| 71 | $includeTOC = CheckboxField::create( |
||
| 72 | 'DocumentConversionField-IncludeTOC', |
||
| 73 | _t(__CLASS__ . '.IncludeTOC', 'Replace this page with a Table of Contents.') |
||
| 74 | ), |
||
| 75 | $publishPages = CheckboxField::create( |
||
| 76 | 'DocumentConversionField-PublishPages', |
||
| 77 | _t( |
||
| 78 | __CLASS__ . '.publishPages', |
||
| 79 | 'Publish modified pages (not recommended unless you are sure about the conversion outcome)' |
||
| 80 | ) |
||
| 81 | ), |
||
| 82 | $this->innerField = DocumentImporterField::create( |
||
| 83 | 'ImportedFromFile', |
||
| 84 | _t(__CLASS__ . '.ImportedFromFile','Import content from a word document') |
||
| 85 | ), |
||
| 86 | )); |
||
| 87 | |||
| 88 | // Prevent the warning popup that appears when navigating away from the page. |
||
| 89 | $splitHeader->addExtraClass('no-change-track'); |
||
| 90 | $keepSource->addExtraClass('no-change-track'); |
||
| 91 | $chosenFolderID->addExtraClass('no-change-track'); |
||
| 92 | $includeTOC->addExtraClass('no-change-track'); |
||
| 93 | $publishPages->addExtraClass('no-change-track'); |
||
| 94 | |||
| 95 | return parent::__construct($fields); |
||
| 96 | } |
||
| 102 |