| Conditions | 22 |
| Paths | 106 |
| Total Lines | 61 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 144 | public function tryGotoNextIterationElement() |
||
| 145 | { |
||
| 146 | $r = $this->reader; |
||
| 147 | |||
| 148 | if ($r->nodeType == XMLReader::NONE) { |
||
| 149 | // first time we do a read from the xml |
||
| 150 | if (! $r->tryRead()) { return false; } |
||
| 151 | } else { |
||
| 152 | // if we have already had a match |
||
| 153 | if (! $r->tryNext()) { return false; } |
||
| 154 | } |
||
| 155 | |||
| 156 | while (true) { |
||
| 157 | // search for open tag |
||
| 158 | if (! $this->searchForOpenTag($r)) { return false; } |
||
| 159 | |||
| 160 | // fill crumbs |
||
| 161 | array_splice($this->crumbs, $r->depth, count($this->crumbs), array($r->name)); |
||
| 162 | |||
| 163 | $matching = $this->pathIsMatching(); |
||
| 164 | |||
| 165 | $uf = self::ELEMENT_IS_VALID; |
||
| 166 | if ($this->callback && is_callable($this->callback) |
||
| 167 | && ($uf = call_user_func_array($this->callback, [$r, $this->crumbs])) !== self::ELEMENT_IS_VALID) { |
||
| 168 | |||
| 169 | // extra check for sanity of a value returned by the user filter |
||
| 170 | if ($uf !== self::SIBLINGS_ARE_INVALID && $uf !== self::ELEMENT_IS_INVALID ) { |
||
| 171 | $uf = self::ELEMENT_IS_INVALID; |
||
| 172 | } |
||
| 173 | |||
| 174 | $df = $r->depth; |
||
| 175 | |||
| 176 | if ($uf === self::SIBLINGS_ARE_INVALID) { $df--; } |
||
| 177 | $matching = self::DESCENDANTS_CANT_MATCH; |
||
| 178 | } |
||
| 179 | |||
| 180 | switch ($matching) { |
||
| 181 | |||
| 182 | case self::DESCENDANTS_COULD_MATCH: |
||
| 183 | if (! $r->tryRead()) { return false; } |
||
| 184 | continue 2; |
||
| 185 | |||
| 186 | case self::DESCENDANTS_CANT_MATCH: |
||
| 187 | |||
| 188 | if (! $r->tryNext()) { return false; } |
||
| 189 | if ($uf !== self::ELEMENT_IS_VALID) { |
||
| 190 | if (! $this->searchForOpenTag($r)) { return false; } |
||
| 191 | while ($r->depth > $df) { |
||
| 192 | if (! $r->tryNext()) { return false; } |
||
| 193 | if (! $this->searchForOpenTag($r)) { return false; } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | continue 2; |
||
| 197 | |||
| 198 | case self::IS_MATCH: |
||
| 199 | return true; |
||
| 200 | } |
||
| 201 | |||
| 202 | return false; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | } |
||
| 206 |
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: