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