| Conditions | 11 |
| Paths | 9 |
| Total Lines | 47 |
| Lines | 24 |
| Ratio | 51.06 % |
| 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 |
||
| 7 | public function load( $file_path ) { |
||
| 8 | $row = 1; |
||
| 9 | if ( ( $handle = fopen( $file_path , "r" ) ) !== FALSE ) { |
||
| 10 | while ( ( $data = fgetcsv( $handle, 1000, "," ) ) !== FALSE ) { |
||
| 11 | $num = count( $data ); |
||
|
|
|||
| 12 | list( $type, $file, $line, $class_name, $name, $static, $params_json ) = $data; |
||
| 13 | |||
| 14 | switch( $type ) { |
||
| 15 | case 'class': |
||
| 16 | $this->add( new Declarations\Class_( $file, $line, $class_name ) ); |
||
| 17 | break; |
||
| 18 | |||
| 19 | case 'property': |
||
| 20 | $this->add( new Declarations\Class_Property( $file, $line, $class_name, $name, $static ) ); |
||
| 21 | break; |
||
| 22 | |||
| 23 | View Code Duplication | case 'method': |
|
| 24 | $params = json_decode( $params_json, TRUE ); |
||
| 25 | $declaration = new Declarations\Class_Method( $file, $line, $class_name, $name, $static ); |
||
| 26 | if ( is_array( $params ) ) { |
||
| 27 | foreach( $params as $param ) { |
||
| 28 | $declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | $this->add( $declaration ); |
||
| 33 | |||
| 34 | break; |
||
| 35 | |||
| 36 | View Code Duplication | case 'function': |
|
| 37 | $params = json_decode( $params_json, TRUE ); |
||
| 38 | $declaration = new Declarations\Function_( $file, $line, $name ); |
||
| 39 | if ( is_array( $params ) ) { |
||
| 40 | foreach( $params as $param ) { |
||
| 41 | $declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | $this->add( $declaration ); |
||
| 46 | |||
| 47 | break; |
||
| 48 | } |
||
| 49 | $row++; |
||
| 50 | } |
||
| 51 | fclose( $handle ); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 78 | } |
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.