Conditions | 1 |
Paths | 1 |
Total Lines | 94 |
Code Lines | 41 |
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 | abstract class TheClass { |
||
53 | public function publicConcreteToAbstract() {} |
||
54 | public abstract function publicAbstractToConcrete() {} |
||
55 | public function publicConcreteToConcrete() {} |
||
56 | public abstract function publicAbstractToAbstract() {} |
||
57 | |||
58 | protected function protectedConcreteToAbstract() {} |
||
59 | protected abstract function protectedAbstractToConcrete() {} |
||
60 | protected function protectedConcreteToConcrete() {} |
||
61 | protected abstract function protectedAbstractToAbstract() {} |
||
62 | |||
63 | private function privateConcreteToAbstract() {} |
||
64 | private abstract function privateAbstractToConcrete() {} |
||
65 | private function privateConcreteToConcrete() {} |
||
66 | private abstract function privateAbstractToAbstract() {} |
||
67 | } |
||
68 | PHP |
||
69 | , |
||
70 | $astLocator |
||
71 | ); |
||
72 | |||
73 | $toLocator = new StringSourceLocator( |
||
74 | <<<'PHP' |
||
75 | <?php |
||
76 | |||
77 | abstract class TheClass { |
||
78 | public abstract function publicConcreteToAbstract() {} |
||
79 | public function publicAbstractToConcrete() {} |
||
80 | public function publicConcreteToConcrete() {} |
||
81 | public abstract function publicAbstractToAbstract() {} |
||
82 | |||
83 | protected abstract function protectedConcreteToAbstract() {} |
||
84 | protected function protectedAbstractToConcrete() {} |
||
85 | protected function protectedConcreteToConcrete() {} |
||
86 | protected abstract function protectedAbstractToAbstract() {} |
||
87 | |||
88 | private abstract function privateConcreteToAbstract() {} |
||
89 | private function privateAbstractToConcrete() {} |
||
90 | private function privateConcreteToConcrete() {} |
||
91 | private abstract function privateAbstractToAbstract() {} |
||
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 | 'publicConcreteToAbstract' => [ |
||
105 | '[BC] CHANGED: Method publicConcreteToAbstract() of class TheClass changed from concrete to abstract', |
||
106 | ], |
||
107 | 'publicAbstractToConcrete' => [], |
||
108 | 'publicConcreteToConcrete' => [], |
||
109 | 'publicAbstractToAbstract' => [], |
||
110 | |||
111 | 'protectedConcreteToAbstract' => [ |
||
112 | '[BC] CHANGED: Method protectedConcreteToAbstract() of class TheClass changed from concrete to abstract', |
||
113 | ], |
||
114 | 'protectedAbstractToConcrete' => [], |
||
115 | 'protectedConcreteToConcrete' => [], |
||
116 | 'protectedAbstractToAbstract' => [], |
||
117 | |||
118 | 'privateConcreteToAbstract' => [ |
||
119 | '[BC] CHANGED: Method privateConcreteToAbstract() of class TheClass changed from concrete to abstract', |
||
120 | ], |
||
121 | 'privateAbstractToConcrete' => [], |
||
122 | 'privateConcreteToConcrete' => [], |
||
123 | 'privateAbstractToAbstract' => [], |
||
124 | ]; |
||
125 | |||
126 | return array_combine( |
||
127 | array_keys($properties), |
||
128 | array_map( |
||
129 | function (string $methodName, array $errorMessages) use ($fromClass, $toClass) : array { |
||
130 | return [ |
||
131 | $fromClass->getMethod($methodName), |
||
132 | $toClass->getMethod($methodName), |
||
133 | $errorMessages, |
||
134 | ]; |
||
135 | }, |
||
136 | array_keys($properties), |
||
137 | $properties |
||
138 | ) |
||
142 |