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