| Conditions | 1 |
| Paths | 1 |
| Total Lines | 89 |
| Code Lines | 63 |
| 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 |
||
| 42 | public function getTemplateData() : array |
||
| 43 | { |
||
| 44 | // Test refactore Form elements |
||
| 45 | $singleCheckbox = new HtmlFormElement( |
||
| 46 | HtmlFormElement::HTML_ELEMENT_INPUT_CHECKBOX, |
||
| 47 | 'accept', |
||
| 48 | 'Accept terms of usage.', |
||
| 49 | [true] |
||
| 50 | ); |
||
| 51 | |||
| 52 | $multiCheckbox = new HtmlFormElement( |
||
| 53 | HtmlFormElement::HTML_ELEMENT_INPUT_CHECKBOX, |
||
| 54 | 'my_locations', |
||
| 55 | 'I have already been...', |
||
| 56 | ['uk', 'eu'], |
||
| 57 | [ |
||
| 58 | 'The United States' => 'us', |
||
| 59 | 'European Union' => 'eu', |
||
| 60 | 'United Kingdom' => 'uk' |
||
| 61 | ] |
||
| 62 | ); |
||
| 63 | |||
| 64 | $radioGroup = new HtmlFormElement( |
||
| 65 | HtmlFormElement::HTML_ELEMENT_INPUT_RADIO, |
||
| 66 | 'curent_lang', |
||
| 67 | 'Current language', |
||
| 68 | ['hu-HU'], |
||
| 69 | [ |
||
| 70 | 'English' => 'en-GB', |
||
| 71 | 'German' => 'de-DE', |
||
| 72 | 'Hungarian' => 'hu-HU' |
||
| 73 | ] |
||
| 74 | ); |
||
| 75 | |||
| 76 | $select = new HtmlMultipleFormElement( |
||
| 77 | HtmlMultipleFormElement::HTML_ELEMENT_SELECT, |
||
| 78 | 'something', |
||
| 79 | null, |
||
| 80 | ['australia', 'india'], |
||
| 81 | [ |
||
| 82 | 'Default' => [ |
||
| 83 | 'Europe' => 'europe', |
||
| 84 | 'America' => 'america', |
||
| 85 | 'Australia' => 'australia' |
||
| 86 | ], |
||
| 87 | 'Africa' => 'africa', |
||
| 88 | 'Asia' => 'asia', |
||
| 89 | 'Antarctica' => 'antarctica', |
||
| 90 | 'India' => 'india' |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | $select->setMultiple(true); |
||
| 94 | |||
| 95 | $form = new HtmlForm('test', '', 'POST'); |
||
| 96 | $form->addElement( |
||
| 97 | new HtmlFormElement( |
||
| 98 | HtmlFormElement::HTML_ELEMENT_INPUT_HIDDEN, |
||
| 99 | 'csrf', |
||
| 100 | null, |
||
| 101 | [md5('something')] |
||
| 102 | ) |
||
| 103 | ) |
||
| 104 | ->addElement( |
||
| 105 | new HtmlFormElement( |
||
| 106 | HtmlFormElement::HTML_ELEMENT_INPUT_TEXT, |
||
| 107 | 'name', |
||
| 108 | 'Login name', |
||
| 109 | ['Joker'] |
||
| 110 | ) |
||
| 111 | ) |
||
| 112 | ->addElement( |
||
| 113 | new HtmlFormElement( |
||
| 114 | HtmlFormElement::HTML_ELEMENT_INPUT_PASSWORD, |
||
| 115 | 'password', |
||
| 116 | 'Password' |
||
| 117 | ) |
||
| 118 | ) |
||
| 119 | ->addElement($singleCheckbox) |
||
| 120 | ->addElement($multiCheckbox) |
||
| 121 | ->addElement($radioGroup) |
||
| 122 | ->addElement($select) |
||
| 123 | ->addElement(new Html5FormElement(Html5FormElement::HTML_ELEMENT_INPUT_NUMBER, 'num', 'Num',[4], [1, 16])) |
||
| 124 | ->addElement(new Html5FormElement(Html5FormElement::HTML_ELEMENT_INPUT_RANGE, 'range', 'Range',[4], [1, 6, 0.2])) |
||
| 125 | ->addElement(new HtmlFormElement(HtmlFormElement::HTML_ELEMENT_BUTTON, 'submit', 'Submit')); |
||
| 126 | |||
| 127 | return [ |
||
| 128 | 'form' => $form |
||
| 129 | ]; |
||
| 130 | } |
||
| 131 | } |
||
| 132 |