| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Code Lines | 46 |
| 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 changed($a = 1) {} |
||
| 55 | function defaultAdded($a) {} |
||
| 56 | function defaultRemoved($a = null) {} |
||
| 57 | function defaultTypeChanged($a = '1') {} |
||
| 58 | function notChanged($a = 1, $b = 2, $c = 3) {} |
||
| 59 | function namesChanged($a = 1, $b = 2, $c = 3) {} |
||
| 60 | function orderChanged($a = 1, $b = 2, $c = 3) {} |
||
| 61 | class C { |
||
| 62 | static function changed1($a = 1) {} |
||
| 63 | function changed2($a = 1) {} |
||
| 64 | } |
||
| 65 | } |
||
| 66 | PHP |
||
| 67 | , |
||
| 68 | $astLocator |
||
| 69 | ); |
||
| 70 | |||
| 71 | $toLocator = new StringSourceLocator( |
||
| 72 | <<<'PHP' |
||
| 73 | <?php |
||
| 74 | |||
| 75 | namespace { |
||
| 76 | function changed($a = 2) {} |
||
| 77 | function defaultAdded($a = 1) {} |
||
| 78 | function defaultRemoved($a) {} |
||
| 79 | function defaultTypeChanged($a = 1) {} |
||
| 80 | function notChanged($a = 1, $b = 2, $c = 3) {} |
||
| 81 | function namesChanged($d = 1, $e = 2, $f = 3) {} |
||
| 82 | function orderChanged($c = 3, $b = 2, $a = 1) {} |
||
| 83 | class C { |
||
| 84 | static function changed1($a = 2) {} |
||
| 85 | function changed2($a = 2) {} |
||
| 86 | } |
||
| 87 | } |
||
| 88 | PHP |
||
| 89 | , |
||
| 90 | $astLocator |
||
| 91 | ); |
||
| 92 | |||
| 93 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 94 | $toClassReflector = new ClassReflector($toLocator); |
||
| 95 | $fromReflector = new FunctionReflector($fromLocator, $fromClassReflector); |
||
| 96 | $toReflector = new FunctionReflector($toLocator, $toClassReflector); |
||
| 97 | |||
| 98 | $functions = [ |
||
| 99 | 'changed' => [ |
||
| 100 | '[BC] CHANGED: Default parameter value for for parameter $a of changed() changed from 1 to 2', |
||
| 101 | ], |
||
| 102 | 'defaultAdded' => [], |
||
| 103 | 'defaultRemoved' => [], |
||
| 104 | 'defaultTypeChanged' => [ |
||
| 105 | '[BC] CHANGED: Default parameter value for for parameter $a of defaultTypeChanged() changed from \'1\' to 1', |
||
| 106 | ], |
||
| 107 | 'notChanged' => [], |
||
| 108 | 'namesChanged' => [], |
||
| 109 | 'orderChanged' => [ |
||
| 110 | '[BC] CHANGED: Default parameter value for for parameter $a of orderChanged() changed from 1 to 3', |
||
| 111 | '[BC] CHANGED: Default parameter value for for parameter $c of orderChanged() changed from 3 to 1', |
||
| 112 | ], |
||
| 113 | ]; |
||
| 114 | |||
| 115 | return array_merge( |
||
| 116 | array_combine( |
||
| 117 | array_keys($functions), |
||
| 118 | array_map( |
||
| 119 | function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { |
||
| 120 | return [ |
||
| 121 | $fromReflector->reflect($function), |
||
| 122 | $toReflector->reflect($function), |
||
| 123 | $errorMessages, |
||
| 124 | ]; |
||
| 125 | }, |
||
| 126 | array_keys($functions), |
||
| 127 | $functions |
||
| 128 | ) |
||
| 129 | ), |
||
| 130 | [ |
||
| 131 | 'C::changed1' => [ |
||
| 132 | $fromClassReflector->reflect('C')->getMethod('changed1'), |
||
| 133 | $toClassReflector->reflect('C')->getMethod('changed1'), |
||
| 134 | [ |
||
| 135 | '[BC] CHANGED: Default parameter value for for parameter $a of C::changed1() changed from 1 to 2', |
||
| 136 | ], |
||
| 137 | ], |
||
| 138 | 'C#changed2' => [ |
||
| 139 | $fromClassReflector->reflect('C')->getMethod('changed2'), |
||
| 140 | $toClassReflector->reflect('C')->getMethod('changed2'), |
||
| 141 | [ |
||
| 142 | '[BC] CHANGED: Default parameter value for for parameter $a of C#changed2() changed from 1 to 2', |
||
| 143 | ], |
||
| 149 |