Conditions | 1 |
Paths | 1 |
Total Lines | 102 |
Code Lines | 45 |
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 |
||
45 | public function functionsToBeTested() : array |
||
46 | { |
||
47 | $astLocator = (new BetterReflection())->astLocator(); |
||
48 | |||
49 | $fromLocator = new StringSourceLocator( |
||
50 | <<<'PHP' |
||
51 | <?php |
||
52 | |||
53 | namespace { |
||
54 | function valueToReference($a) {} |
||
55 | function referenceToValue(& $a) {} |
||
56 | function valueToValue($a) {} |
||
57 | function referenceToReference(& $a) {} |
||
58 | function referenceOnRemovedParameter($a, & $b) {} |
||
59 | function referenceToValueOnRenamedParameter(& $a, & $b) {} |
||
60 | function addedParameter(& $a, & $b) {} |
||
61 | } |
||
62 | namespace N1 { |
||
63 | class C { |
||
64 | static function changed1($a) {} |
||
65 | function changed2($a) {} |
||
66 | } |
||
67 | } |
||
68 | PHP |
||
69 | , |
||
70 | $astLocator |
||
71 | ); |
||
72 | |||
73 | $toLocator = new StringSourceLocator( |
||
74 | <<<'PHP' |
||
75 | <?php |
||
76 | |||
77 | namespace { |
||
78 | function valueToReference(& $a) {} |
||
79 | function referenceToValue($a) {} |
||
80 | function valueToValue($a) {} |
||
81 | function referenceToReference(& $a) {} |
||
82 | function referenceOnRemovedParameter($a) {} |
||
83 | function referenceToValueOnRenamedParameter(& $b, $a) {} |
||
84 | function addedParameter(& $a, & $b, $c) {} |
||
85 | } |
||
86 | namespace N1 { |
||
87 | class C { |
||
88 | static function changed1(& $a) {} |
||
89 | function changed2(& $a) {} |
||
90 | } |
||
91 | } |
||
92 | PHP |
||
93 | , |
||
94 | $astLocator |
||
95 | ); |
||
96 | |||
97 | $fromClassReflector = new ClassReflector($fromLocator); |
||
98 | $toClassReflector = new ClassReflector($toLocator); |
||
99 | $fromReflector = new FunctionReflector($fromLocator, $fromClassReflector); |
||
100 | $toReflector = new FunctionReflector($toLocator, $toClassReflector); |
||
101 | |||
102 | $functions = [ |
||
103 | 'valueToReference' => [ |
||
104 | '[BC] CHANGED: The parameter $a of valueToReference() changed from by-value to by-reference', |
||
105 | ], |
||
106 | 'referenceToValue' => [ |
||
107 | '[BC] CHANGED: The parameter $a of referenceToValue() changed from by-reference to by-value', |
||
108 | ], |
||
109 | 'valueToValue' => [], |
||
110 | 'referenceToReference' => [], |
||
111 | 'referenceOnRemovedParameter' => [], |
||
112 | 'referenceToValueOnRenamedParameter' => [ |
||
113 | '[BC] CHANGED: The parameter $b of referenceToValueOnRenamedParameter() changed from by-reference to by-value', |
||
114 | ], |
||
115 | 'addedParameter' => [], |
||
116 | ]; |
||
117 | |||
118 | return array_merge( |
||
119 | array_combine( |
||
120 | array_keys($functions), |
||
121 | array_map( |
||
122 | function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { |
||
123 | return [ |
||
124 | $fromReflector->reflect($function), |
||
125 | $toReflector->reflect($function), |
||
126 | $errorMessages, |
||
127 | ]; |
||
128 | }, |
||
129 | array_keys($functions), |
||
130 | $functions |
||
131 | ) |
||
132 | ), |
||
133 | [ |
||
134 | 'N1\C::changed1' => [ |
||
135 | $fromClassReflector->reflect('N1\C')->getMethod('changed1'), |
||
136 | $toClassReflector->reflect('N1\C')->getMethod('changed1'), |
||
137 | [ |
||
138 | '[BC] CHANGED: The parameter $a of N1\C::changed1() changed from by-value to by-reference', |
||
139 | |||
140 | ], |
||
141 | ], |
||
142 | 'N1\C#changed2' => [ |
||
143 | $fromClassReflector->reflect('N1\C')->getMethod('changed2'), |
||
144 | $toClassReflector->reflect('N1\C')->getMethod('changed2'), |
||
145 | [ |
||
146 | '[BC] CHANGED: The parameter $a of N1\C#changed2() changed from by-value to by-reference', |
||
147 | ], |
||
153 |