| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Code Lines | 73 |
| Lines | 0 |
| Ratio | 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 |
||
| 8 | public function setUp() |
||
| 9 | { |
||
| 10 | Config::inst()->update('UserDefinedForm', 'upgrade_on_build', false); |
||
| 11 | parent::setUp(); |
||
| 12 | |||
| 13 | // Assign rules programatically |
||
| 14 | $field1 = $this->objFromFixture('EditableTextField', 'text1'); |
||
| 15 | $field2 = $this->objFromFixture('EditableTextField', 'text2'); |
||
| 16 | $field3 = $this->objFromFixture('EditableTextField', 'text3'); |
||
| 17 | |||
| 18 | $field3->CustomRules = serialize(array( |
||
| 19 | array( |
||
| 20 | 'Display' => 'Show', |
||
| 21 | 'ConditionField' => $field1->Name, |
||
| 22 | 'ConditionOption' => 'IsBlank', |
||
| 23 | 'Value' => '' |
||
| 24 | ), |
||
| 25 | array( |
||
| 26 | 'Display' => 'Hide', |
||
| 27 | 'ConditionField' => $field2->Name, |
||
| 28 | 'ConditionOption' => 'HasValue', |
||
| 29 | 'Value' => 'bob' |
||
| 30 | ) |
||
| 31 | )); |
||
| 32 | $field3->write(); |
||
| 33 | |||
| 34 | // Assign settings programatically |
||
| 35 | $field4 = $this->objFromFixture('EditableTextField', 'text4'); |
||
| 36 | $field4->CustomSettings = serialize(array( |
||
| 37 | 'MinLength' => 20, |
||
| 38 | 'MaxLength' => 100, |
||
| 39 | 'Rows' => 4, |
||
| 40 | 'ExtraClass' => 'special class', |
||
| 41 | 'RightTitle' => 'My Field', |
||
| 42 | 'ShowOnLoad' => '', |
||
| 43 | 'Default' => 'Enter your text here' |
||
| 44 | )); |
||
| 45 | $field4->write(); |
||
| 46 | |||
| 47 | $numeric1 = $this->objFromFixture('EditableNumericField', 'numeric1'); |
||
| 48 | $numeric1->CustomSettings = serialize(array( |
||
| 49 | 'RightTitle' => 'Number of %', |
||
| 50 | 'Default' => 1, |
||
| 51 | 'MinValue' => 1, |
||
| 52 | 'MaxValue' => 100, |
||
| 53 | 'ShowOnLoad' => 'Show' |
||
| 54 | )); |
||
| 55 | $numeric1->write(); |
||
| 56 | |||
| 57 | $group1 = $this->objFromFixture('Group', 'group1'); |
||
| 58 | $members1 = $this->objFromFixture('EditableMemberListField', 'members1'); |
||
| 59 | $members1->CustomSettings = serialize(array( |
||
| 60 | 'RightTitle' => 'Select group', |
||
| 61 | 'GroupID' => $group1->ID, |
||
| 62 | 'ShowOnLoad' => 'Hide' |
||
| 63 | )); |
||
| 64 | $members1->write(); |
||
| 65 | |||
| 66 | $literal1 = $this->objFromFixture('EditableLiteralField', 'literal1'); |
||
| 67 | $literal1->CustomSettings = serialize(array( |
||
| 68 | 'HideFromReports' => 1, |
||
| 69 | 'RightTitle' => 'Literal', |
||
| 70 | 'Content' => '<p>Content</p>', |
||
| 71 | 'ShowOnLoad' => true |
||
| 72 | )); |
||
| 73 | $literal1->write(); |
||
| 74 | |||
| 75 | $heading1 = $this->objFromFixture('EditableFormHeading', 'heading1'); |
||
| 76 | $heading1->CustomSettings = serialize(array( |
||
| 77 | 'RightTitle' => 'Right', |
||
| 78 | 'Level' => 3, |
||
| 79 | 'HideFromReports' => true, |
||
| 80 | 'ShowOnLoad' => false |
||
| 81 | )); |
||
| 82 | $heading1->write(); |
||
| 83 | |||
| 84 | $folder = $this->objFromFixture('Folder', 'folder1'); |
||
| 85 | $file1 = $this->objFromFixture('EditableFileField', 'file1'); |
||
| 86 | $file1->CustomSettings = serialize(array( |
||
| 87 | 'RightTitle' => 'File field', |
||
| 88 | 'Folder' => $folder->ID |
||
| 89 | )); |
||
| 90 | $file1->write(); |
||
| 91 | |||
| 92 | $date1 = $this->objFromFixture('EditableDateField', 'date1'); |
||
| 93 | $date1->CustomSettings = serialize(array( |
||
| 94 | 'RightTitle' => 'Date field', |
||
| 95 | 'DefaultToToday' => '1' |
||
| 96 | )); |
||
| 97 | $date1->write(); |
||
| 98 | |||
| 99 | $checkbox1 = $this->objFromFixture('EditableCheckbox', 'checkbox1'); |
||
| 100 | $checkbox1->CustomSettings = serialize(array( |
||
| 101 | 'Default' => true, |
||
| 102 | 'RightTitle' => 'Check this' |
||
| 103 | )); |
||
| 104 | $checkbox1->write(); |
||
| 105 | } |
||
| 106 | |||
| 221 |
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.