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