Conditions | 12 |
Paths | 30 |
Total Lines | 38 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
113 | public function tryGotoNextIterationElement() |
||
114 | { |
||
115 | $r = $this->reader; |
||
116 | |||
117 | if ($r->nodeType == XMLReader::NONE) { |
||
118 | // first time we do a read from the xml |
||
119 | if (! $r->tryRead()) { return false; } |
||
120 | } else { |
||
121 | // if we have already had a match |
||
122 | if (! $r->tryNext()) { return false; } |
||
123 | } |
||
124 | |||
125 | while (true) { |
||
126 | // search for open tag |
||
127 | while ($r->nodeType != XMLReader::ELEMENT) { |
||
128 | if (! $r->tryRead()) { return false; } |
||
129 | } |
||
130 | |||
131 | // fill crumbs |
||
132 | array_splice($this->crumbs, $r->depth, count($this->crumbs), array($r->name)); |
||
133 | |||
134 | switch ($this->pathIsMatching()) { |
||
135 | |||
136 | case self::DESCENDANTS_COULD_MATCH: |
||
137 | if (! $r->tryRead()) { return false; } |
||
138 | continue 2; |
||
139 | |||
140 | case self::DESCENDANTS_CANT_MATCH: |
||
141 | if (! $r->tryNext()) { return false; } |
||
142 | continue 2; |
||
143 | |||
144 | case self::IS_MATCH: |
||
145 | return true; |
||
146 | } |
||
147 | |||
148 | return false; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 |
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: