| Conditions | 48 | 
| Paths | 253 | 
| Total Lines | 173 | 
| Lines | 32 | 
| Ratio | 18.5 % | 
| 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  | 
            ||
| 24 | public function getFunctions(array $constants = [])  | 
            ||
| 25 |     { | 
            ||
| 26 | $length = strlen($this->code);  | 
            ||
| 27 | $line = 1;  | 
            ||
| 28 | $buffer = '';  | 
            ||
| 29 | $functions = [];  | 
            ||
| 30 | $bufferFunctions = [];  | 
            ||
| 31 | $char = null;  | 
            ||
| 32 | |||
| 33 |         for ($pos = 0; $pos < $length; ++$pos) { | 
            ||
| 34 | $prev = $char;  | 
            ||
| 35 | $char = $this->code[$pos];  | 
            ||
| 36 | $next = isset($this->code[$pos + 1]) ? $this->code[$pos + 1] : null;  | 
            ||
| 37 | |||
| 38 |             switch ($char) { | 
            ||
| 39 | case '\\':  | 
            ||
| 40 |                     switch ($this->status()) { | 
            ||
| 41 | case 'simple-quote':  | 
            ||
| 42 | break 2;  | 
            ||
| 43 | case 'double-quote':  | 
            ||
| 44 | break 2;  | 
            ||
| 45 | |||
| 46 | default:  | 
            ||
| 47 | |||
| 48 | $prev = $char;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 49 | $char = $next;  | 
            ||
| 50 | $pos++;  | 
            ||
| 51 | $next = isset($this->code[$pos]) ? $this->code[$pos] : null;  | 
            ||
| 52 | |||
| 53 | break;  | 
            ||
| 54 | }  | 
            ||
| 55 | |||
| 56 | case "\n":  | 
            ||
| 57 | ++$line;  | 
            ||
| 58 | |||
| 59 |                     if ($this->status('line-comment')) { | 
            ||
| 60 | $this->upStatus();  | 
            ||
| 61 | }  | 
            ||
| 62 | break;  | 
            ||
| 63 | |||
| 64 | case '/':  | 
            ||
| 65 |                     switch ($this->status()) { | 
            ||
| 66 | case 'simple-quote':  | 
            ||
| 67 | case 'double-quote':  | 
            ||
| 68 | case 'line-comment':  | 
            ||
| 69 | break;  | 
            ||
| 70 | |||
| 71 | case 'block-comment':  | 
            ||
| 72 |                             if ($prev === '*') { | 
            ||
| 73 | $this->upStatus();  | 
            ||
| 74 | }  | 
            ||
| 75 | break;  | 
            ||
| 76 | |||
| 77 | default:  | 
            ||
| 78 |                             if ($next === '/') { | 
            ||
| 79 |                                 $this->downStatus('line-comment'); | 
            ||
| 80 |                             } elseif ($next === '*') { | 
            ||
| 81 |                                 $this->downStatus('block-comment'); | 
            ||
| 82 | }  | 
            ||
| 83 | break;  | 
            ||
| 84 | }  | 
            ||
| 85 | break;  | 
            ||
| 86 | |||
| 87 | View Code Duplication | case "'":  | 
            |
| 88 |                     switch ($this->status()) { | 
            ||
| 89 | case 'simple-quote':  | 
            ||
| 90 | $this->upStatus();  | 
            ||
| 91 | break;  | 
            ||
| 92 | |||
| 93 | case 'line-comment':  | 
            ||
| 94 | case 'block-comment':  | 
            ||
| 95 | case 'double-quote':  | 
            ||
| 96 | break;  | 
            ||
| 97 | |||
| 98 | default:  | 
            ||
| 99 |                             $this->downStatus('simple-quote'); | 
            ||
| 100 | break;  | 
            ||
| 101 | }  | 
            ||
| 102 | break;  | 
            ||
| 103 | |||
| 104 | View Code Duplication | case '"':  | 
            |
| 105 |                     switch ($this->status()) { | 
            ||
| 106 | case 'double-quote':  | 
            ||
| 107 | $this->upStatus();  | 
            ||
| 108 | break;  | 
            ||
| 109 | |||
| 110 | case 'line-comment':  | 
            ||
| 111 | case 'block-comment':  | 
            ||
| 112 | case 'simple-quote':  | 
            ||
| 113 | break;  | 
            ||
| 114 | |||
| 115 | default:  | 
            ||
| 116 |                             $this->downStatus('double-quote'); | 
            ||
| 117 | break;  | 
            ||
| 118 | }  | 
            ||
| 119 | break;  | 
            ||
| 120 | |||
| 121 |                 case '(': | 
            ||
| 122 |                     switch ($this->status()) { | 
            ||
| 123 | case 'simple-quote':  | 
            ||
| 124 | case 'double-quote':  | 
            ||
| 125 | case 'line-comment':  | 
            ||
| 126 | case 'block-comment':  | 
            ||
| 127 | case 'line-comment':  | 
            ||
| 128 | break;  | 
            ||
| 129 | |||
| 130 | default:  | 
            ||
| 131 |                             if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) { | 
            ||
| 132 |                                 $this->downStatus('function'); | 
            ||
| 133 | array_unshift($bufferFunctions, [$matches[1], $line, []]);  | 
            ||
| 134 | $buffer = '';  | 
            ||
| 135 | continue 3;  | 
            ||
| 136 | }  | 
            ||
| 137 | break;  | 
            ||
| 138 | }  | 
            ||
| 139 | break;  | 
            ||
| 140 | |||
| 141 | case ')':  | 
            ||
| 142 |                     switch ($this->status()) { | 
            ||
| 143 | case 'function':  | 
            ||
| 144 |                             if (($argument = self::prepareArgument($buffer))) { | 
            ||
| 145 | $bufferFunctions[0][2][] = $argument;  | 
            ||
| 146 | }  | 
            ||
| 147 | |||
| 148 |                             if (!empty($bufferFunctions)) { | 
            ||
| 149 | $functions[] = array_shift($bufferFunctions);  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | $this->upStatus();  | 
            ||
| 153 | $buffer = '';  | 
            ||
| 154 | continue 3;  | 
            ||
| 155 | }  | 
            ||
| 156 | break;  | 
            ||
| 157 | |||
| 158 | case ',':  | 
            ||
| 159 |                     switch ($this->status()) { | 
            ||
| 160 | case 'function':  | 
            ||
| 161 |                             if (($argument = self::prepareArgument($buffer))) { | 
            ||
| 162 | $bufferFunctions[0][2][] = $argument;  | 
            ||
| 163 | }  | 
            ||
| 164 | |||
| 165 | $buffer = '';  | 
            ||
| 166 | continue 3;  | 
            ||
| 167 | }  | 
            ||
| 168 | break;  | 
            ||
| 169 | |||
| 170 | case ' ':  | 
            ||
| 171 | case '\t':  | 
            ||
| 172 |                     switch ($this->status()) { | 
            ||
| 173 | case 'double-quote':  | 
            ||
| 174 | case 'simple-quote':  | 
            ||
| 175 | break;  | 
            ||
| 176 | |||
| 177 | default:  | 
            ||
| 178 | $buffer = '';  | 
            ||
| 179 | continue 3;  | 
            ||
| 180 | }  | 
            ||
| 181 | break;  | 
            ||
| 182 | }  | 
            ||
| 183 | |||
| 184 |             switch ($this->status()) { | 
            ||
| 185 | case 'line-comment':  | 
            ||
| 186 | case 'block-comment':  | 
            ||
| 187 | break;  | 
            ||
| 188 | |||
| 189 | default:  | 
            ||
| 190 | $buffer .= $char;  | 
            ||
| 191 | break;  | 
            ||
| 192 | }  | 
            ||
| 193 | }  | 
            ||
| 194 | |||
| 195 | return $functions;  | 
            ||
| 196 | }  | 
            ||
| 197 | |||
| 263 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.