Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
50 | public function functionsToBeTested() : array |
||
51 | { |
||
52 | $astLocator = (new BetterReflection())->astLocator(); |
||
53 | |||
54 | $fromLocator = new StringSourceLocator( |
||
55 | <<<'PHP' |
||
56 | <?php |
||
57 | |||
58 | function a() {} |
||
59 | function b() {} |
||
60 | /** @internal */ |
||
61 | function c() {} |
||
62 | /** @internal */ |
||
63 | function d() {} |
||
64 | PHP |
||
65 | , |
||
66 | $astLocator |
||
67 | ); |
||
68 | |||
69 | $toLocator = new StringSourceLocator( |
||
70 | <<<'PHP' |
||
71 | <?php |
||
72 | |||
73 | function a() {} |
||
74 | /** @internal */ |
||
75 | function b() {} |
||
76 | function c() {} |
||
77 | /** @internal */ |
||
78 | function d() {} |
||
79 | PHP |
||
80 | , |
||
81 | $astLocator |
||
82 | ); |
||
83 | |||
84 | $fromClassReflector = new ClassReflector($fromLocator); |
||
85 | $toClassReflector = new ClassReflector($toLocator); |
||
86 | $fromReflector = new FunctionReflector($fromLocator, $fromClassReflector); |
||
87 | $toReflector = new FunctionReflector($toLocator, $toClassReflector); |
||
88 | |||
89 | $functions = [ |
||
90 | 'a' => [], |
||
91 | 'b' => ['[BC] CHANGED: b() was marked "@internal"'], |
||
92 | 'c' => [], |
||
93 | 'd' => [], |
||
94 | ]; |
||
95 | |||
96 | return array_combine( |
||
97 | array_keys($functions), |
||
98 | array_map( |
||
99 | static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { |
||
100 | return [ |
||
101 | $fromReflector->reflect($function), |
||
102 | $toReflector->reflect($function), |
||
103 | $errorMessages, |
||
104 | ]; |
||
105 | }, |
||
106 | array_keys($functions), |
||
107 | $functions |
||
108 | ) |
||
112 |