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