Conditions | 1 |
Paths | 1 |
Total Lines | 96 |
Code Lines | 42 |
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 |
||
44 | public function propertiesToBeTested() : array |
||
45 | { |
||
46 | $astLocator = (new BetterReflection())->astLocator(); |
||
47 | |||
48 | $fromLocator = new StringSourceLocator( |
||
49 | <<<'PHP' |
||
50 | <?php |
||
51 | |||
52 | class TheClass { |
||
53 | public function publicInstanceToStatic() {} |
||
54 | public static function publicStaticToInstance() {} |
||
55 | public function publicInstanceToInstance() {} |
||
56 | public static function publicStaticToStatic() {} |
||
57 | |||
58 | protected function protectedInstanceToStatic() {} |
||
59 | protected static function protectedStaticToInstance() {} |
||
60 | protected function protectedInstanceToInstance() {} |
||
61 | protected static function protectedStaticToStatic() {} |
||
62 | |||
63 | private function privateInstanceToStatic() {} |
||
64 | private static function privateStaticToInstance() {} |
||
65 | private function privateInstanceToInstance() {} |
||
66 | private static function privateStaticToStatic() {} |
||
67 | } |
||
68 | PHP |
||
69 | , |
||
70 | $astLocator |
||
71 | ); |
||
72 | |||
73 | $toLocator = new StringSourceLocator( |
||
74 | <<<'PHP' |
||
75 | <?php |
||
76 | |||
77 | class TheClass { |
||
78 | public static function publicInstanceToStatic() {} |
||
79 | public function publicStaticToInstance() {} |
||
80 | public function publicInstanceToInstance() {} |
||
81 | public static function publicStaticToStatic() {} |
||
82 | |||
83 | protected static function protectedInstanceToStatic() {} |
||
84 | protected function protectedStaticToInstance() {} |
||
85 | protected function protectedInstanceToInstance() {} |
||
86 | protected static function protectedStaticToStatic() {} |
||
87 | |||
88 | private static function privateInstanceToStatic() {} |
||
89 | private function privateStaticToInstance() {} |
||
90 | private function privateInstanceToInstance() {} |
||
91 | private static function privateStaticToStatic() {} |
||
92 | } |
||
93 | PHP |
||
94 | , |
||
95 | $astLocator |
||
96 | ); |
||
97 | |||
98 | $fromClassReflector = new ClassReflector($fromLocator); |
||
99 | $toClassReflector = new ClassReflector($toLocator); |
||
100 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
101 | $toClass = $toClassReflector->reflect('TheClass'); |
||
102 | |||
103 | $properties = [ |
||
104 | 'publicInstanceToStatic' => [ |
||
105 | '[BC] CHANGED: Method publicInstanceToStatic() of class TheClass changed scope from instance to static', |
||
106 | ], |
||
107 | 'publicStaticToInstance' => [ |
||
108 | '[BC] CHANGED: Method publicStaticToInstance() of class TheClass changed scope from static to instance', |
||
109 | ], |
||
110 | 'publicInstanceToInstance' => [], |
||
111 | 'publicStaticToStatic' => [], |
||
112 | |||
113 | 'protectedInstanceToStatic' => [ |
||
114 | '[BC] CHANGED: Method protectedInstanceToStatic() of class TheClass changed scope from instance to static', |
||
115 | ], |
||
116 | 'protectedStaticToInstance' => [ |
||
117 | '[BC] CHANGED: Method protectedStaticToInstance() of class TheClass changed scope from static to instance', |
||
118 | ], |
||
119 | 'protectedInstanceToInstance' => [], |
||
120 | 'protectedStaticToStatic' => [], |
||
121 | |||
122 | 'privateInstanceToStatic' => [], |
||
123 | 'privateStaticToInstance' => [], |
||
124 | 'privateInstanceToInstance' => [], |
||
125 | 'privateStaticToStatic' => [], |
||
126 | ]; |
||
127 | |||
128 | return array_combine( |
||
129 | array_keys($properties), |
||
130 | array_map( |
||
131 | function (string $methodName, array $errorMessages) use ($fromClass, $toClass) : array { |
||
132 | return [ |
||
133 | $fromClass->getMethod($methodName), |
||
134 | $toClass->getMethod($methodName), |
||
135 | $errorMessages, |
||
136 | ]; |
||
137 | }, |
||
138 | array_keys($properties), |
||
139 | $properties |
||
140 | ) |
||
144 |