| Conditions | 18 |
| Paths | 21 |
| Total Lines | 68 |
| 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 |
||
| 121 | function getWord() { |
||
| 122 | while (true) { |
||
| 123 | if ($this->iHtmlParser->iNodeType == NODE_TYPE_TEXT) { |
||
| 124 | if (!$this->iInText) { |
||
| 125 | $words = $this->splitWords($this->iHtmlParser->iNodeValue); |
||
| 126 | $this->iCurrentWordArray = $words; |
||
| 127 | $this->iCurrentWordIndex = 0; |
||
| 128 | $this->iInText = true; |
||
| 129 | } |
||
| 130 | if ($this->iCurrentWordIndex < count($this->iCurrentWordArray)) { |
||
| 131 | $this->iCurrentWord = $this->iCurrentWordArray[$this->iCurrentWordIndex++]; |
||
| 132 | return $this->iCurrentWord; |
||
| 133 | } |
||
| 134 | else { |
||
| 135 | $this->iInText = false; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) { |
||
| 139 | if (strcasecmp ($this->iHtmlParser->iNodeName, "br") == 0) { |
||
| 140 | $this->iHtmlParser->parse(); |
||
| 141 | $this->iCurrentWord = $this->TOKEN_BR; |
||
| 142 | return $this->iCurrentWord; |
||
| 143 | } |
||
| 144 | else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) { |
||
| 145 | $this->iHtmlParser->parse(); |
||
| 146 | $this->iCurrentWord = $this->TOKEN_P; |
||
| 147 | return $this->iCurrentWord; |
||
| 148 | } |
||
| 149 | else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) { |
||
| 150 | $this->iHtmlParser->parse(); |
||
| 151 | $this->iCurrentWord = ""; |
||
| 152 | $this->iInScript = true; |
||
| 153 | return $this->iCurrentWord; |
||
| 154 | } |
||
| 155 | else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) { |
||
| 156 | $this->iHtmlParser->parse(); |
||
| 157 | $this->iCurrentWord = $this->TOKEN_UL; |
||
| 158 | $this->iListLevel++; |
||
| 159 | return $this->iCurrentWord; |
||
| 160 | } |
||
| 161 | else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) { |
||
| 162 | $this->iHtmlParser->parse(); |
||
| 163 | $this->iCurrentWord = $this->TOKEN_LI; |
||
| 164 | return $this->iCurrentWord; |
||
| 165 | } |
||
| 166 | } |
||
| 167 | else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) { |
||
| 168 | if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) { |
||
| 169 | $this->iHtmlParser->parse(); |
||
| 170 | $this->iCurrentWord = ""; |
||
| 171 | $this->iInScript = false; |
||
| 172 | return $this->iCurrentWord; |
||
| 173 | } |
||
| 174 | else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) { |
||
| 175 | $this->iHtmlParser->parse(); |
||
| 176 | $this->iCurrentWord = $this->TOKEN_ENDUL; |
||
| 177 | if ($this->iListLevel > 0) { |
||
| 178 | $this->iListLevel--; |
||
| 179 | } |
||
| 180 | return $this->iCurrentWord; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | if (!$this->iHtmlParser->parse()) { |
||
| 184 | break; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | return false; |
||
| 188 | } |
||
| 189 | |||
| 215 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: