Conditions | 1 |
Paths | 1 |
Total Lines | 74 |
Code Lines | 35 |
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 |
||
46 | public function propertiesToBeTested() : array |
||
47 | { |
||
48 | $astLocator = (new BetterReflection())->astLocator(); |
||
49 | |||
50 | $fromLocator = new StringSourceLocator( |
||
51 | <<<'PHP' |
||
52 | <?php |
||
53 | |||
54 | class TheClass { |
||
55 | public function publicMaintainedPublic() {} |
||
56 | public function publicReducedToProtected() {} |
||
57 | public function publicReducedToPrivate() {} |
||
58 | protected function protectedMaintainedProtected() {} |
||
59 | protected function protectedReducedToPrivate() {} |
||
60 | protected function protectedIncreasedToPublic() {} |
||
61 | private function privateMaintainedPrivate() {} |
||
62 | private function privateIncreasedToProtected() {} |
||
63 | private function privateIncreasedToPublic() {} |
||
64 | } |
||
65 | PHP |
||
66 | , |
||
67 | $astLocator |
||
68 | ); |
||
69 | |||
70 | $toLocator = new StringSourceLocator( |
||
71 | <<<'PHP' |
||
72 | <?php |
||
73 | |||
74 | class TheClass { |
||
75 | public function publicMaintainedPublic() {} |
||
76 | protected function publicReducedToProtected() {} |
||
77 | private function publicReducedToPrivate() {} |
||
78 | protected function protectedMaintainedProtected() {} |
||
79 | private function protectedReducedToPrivate() {} |
||
80 | public function protectedIncreasedToPublic() {} |
||
81 | private function privateMaintainedPrivate() {} |
||
82 | protected function privateIncreasedToProtected() {} |
||
83 | public function privateIncreasedToPublic() {} |
||
84 | } |
||
85 | PHP |
||
86 | , |
||
87 | $astLocator |
||
88 | ); |
||
89 | |||
90 | $fromClassReflector = new ClassReflector($fromLocator); |
||
91 | $toClassReflector = new ClassReflector($toLocator); |
||
92 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
93 | $toClass = $toClassReflector->reflect('TheClass'); |
||
94 | |||
95 | $properties = [ |
||
96 | |||
97 | 'publicMaintainedPublic' => [], |
||
98 | 'publicReducedToProtected' => ['[BC] CHANGED: Method publicReducedToProtected() of class TheClass visibility reduced from public to protected'], |
||
99 | 'publicReducedToPrivate' => ['[BC] CHANGED: Method publicReducedToPrivate() of class TheClass visibility reduced from public to private'], |
||
100 | 'protectedMaintainedProtected' => [], |
||
101 | 'protectedReducedToPrivate' => ['[BC] CHANGED: Method protectedReducedToPrivate() of class TheClass visibility reduced from protected to private'], |
||
102 | 'protectedIncreasedToPublic' => [], |
||
103 | 'privateMaintainedPrivate' => [], |
||
104 | 'privateIncreasedToProtected' => [], |
||
105 | 'privateIncreasedToPublic' => [], |
||
106 | ]; |
||
107 | |||
108 | return array_combine( |
||
109 | array_keys($properties), |
||
110 | array_map( |
||
111 | function (string $method, array $errorMessages) use ($fromClass, $toClass) : array { |
||
112 | return [ |
||
113 | $fromClass->getMethod($method), |
||
114 | $toClass->getMethod($method), |
||
115 | $errorMessages, |
||
116 | ]; |
||
117 | }, |
||
118 | array_keys($properties), |
||
119 | $properties |
||
120 | ) |
||
124 |