| Conditions | 10 |
| Paths | 192 |
| Total Lines | 45 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 89 | public function getHTML() : string |
||
| 90 | { |
||
| 91 | if (strlen($this->strDefault) > 0) { |
||
| 92 | $this->addAttribute('data-default', $this->strDefault); |
||
| 93 | } |
||
| 94 | |||
| 95 | $strStyle = ''; |
||
| 96 | if ($this->oFlags->isSet(FormFlags::ALIGN_CENTER)) { |
||
| 97 | $strStyle = 'text-align: center;'; |
||
| 98 | } else if ($this->oFlags->isSet(FormFlags::ALIGN_RIGHT)) { |
||
| 99 | $strStyle = 'text-align: right;'; |
||
| 100 | } |
||
| 101 | $strHTML = $this->buildContainerDiv($strStyle); |
||
| 102 | |||
| 103 | if (strlen($this->strBoundTo) > 0) { |
||
| 104 | $this->addAttribute('data-bound-to', $this->strBoundTo); |
||
| 105 | $strImg = $this->oFG->getData()->getValue($this->strBoundTo); |
||
| 106 | } else if (is_numeric($this->img)) { |
||
| 107 | [$strImg, $strTitle] = $this->oFG->getStdImage(intval($this->img)); |
||
| 108 | if (strlen($strTitle) > 0) { |
||
| 109 | $this->addAttribute('title', $strTitle); |
||
| 110 | } |
||
| 111 | } else { |
||
| 112 | $strImg = $this->img; |
||
| 113 | } |
||
| 114 | |||
| 115 | if (strlen($strImg) == 0) { |
||
| 116 | $strImg = $this->strDefault; |
||
| 117 | } |
||
| 118 | |||
| 119 | $strAlt = 'Image'; |
||
| 120 | $strHTML .= '<img src="' . $strImg . '" alt="' . $strAlt . '"'; |
||
| 121 | if (!empty($this->strName)) { |
||
| 122 | $strHTML .= ' id="' . $this->strName . '"'; |
||
| 123 | } |
||
| 124 | $strHTML .= $this->buildStyle(); |
||
| 125 | if (!empty($this->strOnClick)) { |
||
| 126 | $strHTML .= ' onclick="' . $this->strOnClick . ';"'; |
||
| 127 | } |
||
| 128 | $strHTML .= $this->buildClass(); |
||
| 129 | $strHTML .= $this->buildID(); |
||
| 130 | $strHTML .= $this->buildAttributes(); |
||
| 131 | $strHTML .= '></div>' . PHP_EOL; |
||
| 132 | |||
| 133 | return $strHTML; |
||
| 134 | } |
||
| 136 |