| 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 |
||
| 87 | public function load( $file_path ) { |
||
| 88 | $row = 1; |
||
| 89 | if ( ( $handle = fopen( $file_path , "r" ) ) !== FALSE ) { |
||
| 90 | while ( ( $data = fgetcsv( $handle, 1000, "," ) ) !== FALSE ) { |
||
| 91 | $num = count( $data ); |
||
| 92 | list( $type, $file, $line, $class_name, $name, $static, $params_json ) = $data; |
||
| 93 | |||
| 94 | switch( $type ) { |
||
| 95 | case 'class': |
||
| 96 | $this->add( new Declarations\Class_( $file, $line, $class_name ) ); |
||
| 97 | break; |
||
| 98 | |||
| 99 | case 'property': |
||
| 100 | $this->add( new Declarations\Class_Property( $file, $line, $class_name, $name, $static ) ); |
||
| 101 | break; |
||
| 102 | |||
| 103 | View Code Duplication | case 'method': |
|
| 104 | $params = json_decode( $params_json, TRUE ); |
||
| 105 | $declaration = new Declarations\Class_Method( $file, $line, $class_name, $name, $static ); |
||
| 106 | if ( is_array( $params ) ) { |
||
| 107 | foreach( $params as $param ) { |
||
| 108 | $declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $this->add( $declaration ); |
||
| 113 | |||
| 114 | break; |
||
| 115 | |||
| 116 | View Code Duplication | case 'function': |
|
| 117 | $params = json_decode( $params_json, TRUE ); |
||
| 118 | $declaration = new Declarations\Function_( $file, $line, $name ); |
||
| 119 | if ( is_array( $params ) ) { |
||
| 120 | foreach( $params as $param ) { |
||
| 121 | $declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $this->add( $declaration ); |
||
| 126 | |||
| 127 | break; |
||
| 128 | } |
||
| 129 | $row++; |
||
| 130 | } |
||
| 131 | fclose( $handle ); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |