| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| Code Lines | 64 |
| 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 | protected function init() : void |
||
| 43 | { |
||
| 44 | $this->initAdapter(); |
||
| 45 | |||
| 46 | $csrf = $this->createElement( |
||
| 47 | HtmlElement::class, |
||
| 48 | HtmlElement::HTML_ELEMENT_HIDDEN, |
||
| 49 | CSRFInterface::SESSION_KEY, |
||
| 50 | '' |
||
| 51 | ); |
||
| 52 | |||
| 53 | $name = $this->createElement( |
||
| 54 | HtmlElement::class, |
||
| 55 | HtmlElement::HTML_ELEMENT_INPUT_TEXT, |
||
| 56 | 'name', |
||
| 57 | 'Application name' |
||
| 58 | ); |
||
| 59 | $name->addValidator($this->validatorCollection->getValidator(Validator\NotEmptyValidator::class)); |
||
| 60 | |||
| 61 | $title = $this->createElement( |
||
| 62 | HtmlElement::class, |
||
| 63 | HtmlElement::HTML_ELEMENT_INPUT_TEXT, |
||
| 64 | 'title', |
||
| 65 | 'Display name (title)' |
||
| 66 | ); |
||
| 67 | $title->addValidator($this->validatorCollection->getValidator(Validator\NotEmptyValidator::class)); |
||
| 68 | |||
| 69 | $introduction = $this->createElement( |
||
| 70 | HtmlElement::class, |
||
| 71 | HtmlElement::HTML_ELEMENT_TEXTAREA, |
||
| 72 | 'introduction', |
||
| 73 | 'Introduction' |
||
| 74 | ); |
||
| 75 | |||
| 76 | $subject = $this->createElement( |
||
| 77 | HtmlElement::class, |
||
| 78 | HtmlElement::HTML_ELEMENT_TEXTAREA, |
||
| 79 | 'subject', |
||
| 80 | 'Subject' |
||
| 81 | ); |
||
| 82 | |||
| 83 | $description = $this->createElement( |
||
| 84 | HtmlElement::class, |
||
| 85 | HtmlElement::HTML_ELEMENT_TEXTAREA, |
||
| 86 | 'description', |
||
| 87 | 'Description' |
||
| 88 | ); |
||
| 89 | |||
| 90 | $keywords = $this->createElement( |
||
| 91 | HtmlElement::class, |
||
| 92 | HtmlElement::HTML_ELEMENT_INPUT_TEXT, |
||
| 93 | 'keywords', |
||
| 94 | 'Keywords' |
||
| 95 | ); |
||
| 96 | |||
| 97 | $copyright = $this->createElement( |
||
| 98 | HtmlElement::class, |
||
| 99 | HtmlElement::HTML_ELEMENT_INPUT_TEXT, |
||
| 100 | 'copyright', |
||
| 101 | 'Copyright' |
||
| 102 | ); |
||
| 103 | |||
| 104 | $cancel = $this->createElement( |
||
| 105 | HtmlElement::class, |
||
| 106 | HtmlElement::HTML_ELEMENT_BUTTON, |
||
| 107 | 'cancel', |
||
| 108 | 'Cancel' |
||
| 109 | ); |
||
| 110 | |||
| 111 | $submit = $this->createElement( |
||
| 112 | HtmlElement::class, |
||
| 113 | HtmlElement::HTML_ELEMENT_SUBMIT, |
||
| 114 | 'submit', |
||
| 115 | 'Save' |
||
| 116 | ); |
||
| 117 | |||
| 118 | $this->formAdapter |
||
| 119 | ->addElement($csrf) |
||
| 120 | ->addElement($name) |
||
| 121 | ->addElement($title) |
||
| 122 | ->addElement($introduction) |
||
| 123 | ->addElement($subject) |
||
| 124 | ->addElement($description) |
||
| 125 | ->addElement($keywords) |
||
| 126 | ->addElement($copyright) |
||
| 127 | ->addElement($cancel) |
||
| 128 | ->addElement($submit); |
||
| 129 | } |
||
| 131 |