| Conditions | 21 | 
| Paths | 41 | 
| Total Lines | 65 | 
| 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  | 
            ||
| 146 | public function process($calls)  | 
            ||
| 147 |     { | 
            ||
| 148 | // open first paragraph  | 
            ||
| 149 | $this->openParagraph(0);  | 
            ||
| 150 |         foreach ($calls as $key => $call) { | 
            ||
| 151 | $cname = $call[0];  | 
            ||
| 152 |             if ($cname == 'plugin') { | 
            ||
| 153 | $cname='plugin_'.$call[1][0];  | 
            ||
| 154 | $plugin = true;  | 
            ||
| 155 | $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));  | 
            ||
| 156 | $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));  | 
            ||
| 157 |             } else { | 
            ||
| 158 | $plugin = false;  | 
            ||
| 159 | }  | 
            ||
| 160 | /* stack */  | 
            ||
| 161 |             if (in_array($cname, $this->stackClose) && (!$plugin || $plugin_close)) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 162 | $this->closeParagraph($call[2]);  | 
            ||
| 163 | $this->storeCall($call);  | 
            ||
| 164 | $this->openParagraph($call[2]);  | 
            ||
| 165 | continue;  | 
            ||
| 166 | }  | 
            ||
| 167 |             if (in_array($cname, $this->stackOpen) && (!$plugin || $plugin_open)) { | 
            ||
| 168 | $this->closeParagraph($call[2]);  | 
            ||
| 169 | $this->storeCall($call);  | 
            ||
| 170 | $this->openParagraph($call[2]);  | 
            ||
| 171 | continue;  | 
            ||
| 172 | }  | 
            ||
| 173 | /* block */  | 
            ||
| 174 | // If it's a substition it opens and closes at the same call.  | 
            ||
| 175 | // To make sure next paragraph is correctly started, let close go first.  | 
            ||
| 176 |             if (in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { | 
            ||
| 177 | $this->closeParagraph($call[2]);  | 
            ||
| 178 | $this->storeCall($call);  | 
            ||
| 179 | $this->openParagraph($call[2]);  | 
            ||
| 180 | continue;  | 
            ||
| 181 | }  | 
            ||
| 182 |             if (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) { | 
            ||
| 183 | $this->closeParagraph($call[2]);  | 
            ||
| 184 | $this->storeCall($call);  | 
            ||
| 185 | continue;  | 
            ||
| 186 | }  | 
            ||
| 187 | /* eol */  | 
            ||
| 188 |             if ($cname == 'eol') { | 
            ||
| 189 | // Check this isn't an eol instruction to skip...  | 
            ||
| 190 |                 if (!$this->skipEol) { | 
            ||
| 191 | // Next is EOL => double eol => mark as paragraph  | 
            ||
| 192 |                     if (isset($calls[$key+1]) && $calls[$key+1][0] == 'eol') { | 
            ||
| 193 | $this->closeParagraph($call[2]);  | 
            ||
| 194 | $this->openParagraph($call[2]);  | 
            ||
| 195 |                     } else { | 
            ||
| 196 | //if this is just a single eol make a space from it  | 
            ||
| 197 |                         $this->addCall(array('cdata',array("\n"), $call[2])); | 
            ||
| 198 | }  | 
            ||
| 199 | }  | 
            ||
| 200 | continue;  | 
            ||
| 201 | }  | 
            ||
| 202 | /* normal */  | 
            ||
| 203 | $this->addCall($call);  | 
            ||
| 204 | $this->skipEol = false;  | 
            ||
| 205 | }  | 
            ||
| 206 | // close last paragraph  | 
            ||
| 207 | $call = end($this->calls);  | 
            ||
| 208 | $this->closeParagraph($call[2]);  | 
            ||
| 209 | return $this->calls;  | 
            ||
| 210 | }  | 
            ||
| 211 | }  | 
            ||
| 212 | 
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: