Conditions | 17 |
Paths | 181 |
Total Lines | 64 |
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 |
||
12 | public function find( $new_declarations, $prev_declarations ) { |
||
13 | $total = 0; |
||
14 | // for each declaration, see if it exists in the current analyzer's declarations |
||
15 | // if not, add it to the list of differences - either as missing or different |
||
16 | foreach ( $prev_declarations->get() as $prev_declaration ) { |
||
17 | $matched = false; |
||
18 | $moved = false; |
||
19 | foreach ( $new_declarations->get() as $new_declaration ) { |
||
20 | if ( $prev_declaration->match( $new_declaration ) ) { |
||
21 | // echo "Comparing " . $prev_declaration->path . " to " . $new_declaration->path . "\n"; |
||
22 | if ( $prev_declaration->path !== $new_declaration->path ) { |
||
23 | $moved = true; |
||
24 | } |
||
25 | $matched = true; |
||
26 | break; |
||
27 | } elseif ( $prev_declaration->partial_match( $new_declaration ) ) { |
||
28 | // TODO this is to catch things like function args changed, method the same |
||
29 | } |
||
30 | } |
||
31 | |||
32 | if ( $matched && $moved ) { |
||
33 | switch ( $prev_declaration->type() ) { |
||
34 | case 'class': |
||
35 | $this->add( new Differences\Class_Moved( $prev_declaration, $new_declaration ) ); |
||
|
|||
36 | break; |
||
37 | case 'method': |
||
38 | $this->add( new Differences\Class_Method_Moved( $prev_declaration, $new_declaration ) ); |
||
39 | break; |
||
40 | case 'property': |
||
41 | $this->add( new Differences\Class_Property_Moved( $prev_declaration, $new_declaration ) ); |
||
42 | break; |
||
43 | case 'function': |
||
44 | $this->add( new Differences\Function_Moved( $prev_declaration, $new_declaration ) ); |
||
45 | break; |
||
46 | default: |
||
47 | echo 'Unknown moved type ' . $prev_declaration->type() . "\n"; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | if ( ! $matched ) { |
||
52 | switch ( $prev_declaration->type() ) { |
||
53 | case 'class': |
||
54 | $this->add( new Differences\Class_Missing( $prev_declaration ) ); |
||
55 | break; |
||
56 | case 'method': |
||
57 | $this->add( new Differences\Class_Method_Missing( $prev_declaration ) ); |
||
58 | break; |
||
59 | case 'property': |
||
60 | $this->add( new Differences\Class_Property_Missing( $prev_declaration ) ); |
||
61 | break; |
||
62 | case 'function': |
||
63 | $this->add( new Differences\Function_Missing( $prev_declaration ) ); |
||
64 | break; |
||
65 | default: |
||
66 | echo 'Unknown unmatched type ' . $prev_declaration->type() . "\n"; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | $total += 1; |
||
71 | } |
||
72 | |||
73 | echo "Total: $total\n"; |
||
74 | echo 'Missing: ' . count( $this->get() ) . "\n"; |
||
75 | } |
||
76 | } |
||
77 |
It seems like you are relying on a variable being defined by an iteration: