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