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