| 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 $publicInstanceToStatic; |
||
| 56 | public static $publicStaticToInstance; |
||
| 57 | public $publicInstanceToInstance; |
||
| 58 | public static $publicStaticToStatic; |
||
| 59 | |||
| 60 | protected $protectedInstanceToStatic; |
||
| 61 | protected static $protectedStaticToInstance; |
||
| 62 | protected $protectedInstanceToInstance; |
||
| 63 | protected static $protectedStaticToStatic; |
||
| 64 | |||
| 65 | private $privateInstanceToStatic; |
||
| 66 | private static $privateStaticToInstance; |
||
| 67 | private $privateInstanceToInstance; |
||
| 68 | private static $privateStaticToStatic; |
||
| 69 | } |
||
| 70 | PHP |
||
| 71 | , |
||
| 72 | $astLocator |
||
| 73 | ); |
||
| 74 | |||
| 75 | $toLocator = new StringSourceLocator( |
||
| 76 | <<<'PHP' |
||
| 77 | <?php |
||
| 78 | |||
| 79 | class TheClass { |
||
| 80 | public static $publicInstanceToStatic; |
||
| 81 | public $publicStaticToInstance; |
||
| 82 | public $publicInstanceToInstance; |
||
| 83 | public static $publicStaticToStatic; |
||
| 84 | |||
| 85 | protected static $protectedInstanceToStatic; |
||
| 86 | protected $protectedStaticToInstance; |
||
| 87 | protected $protectedInstanceToInstance; |
||
| 88 | protected static $protectedStaticToStatic; |
||
| 89 | |||
| 90 | private static $privateInstanceToStatic; |
||
| 91 | private $privateStaticToInstance; |
||
| 92 | private $privateInstanceToInstance; |
||
| 93 | private static $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: Property $publicInstanceToStatic of TheClass changed scope from instance to static'], |
||
| 107 | 'publicStaticToInstance' => ['[BC] CHANGED: Property $publicStaticToInstance of TheClass changed scope from static to instance'], |
||
| 108 | 'publicInstanceToInstance' => [], |
||
| 109 | 'publicStaticToStatic' => [], |
||
| 110 | |||
| 111 | 'protectedInstanceToStatic' => ['[BC] CHANGED: Property $protectedInstanceToStatic of TheClass changed scope from instance to static'], |
||
| 112 | 'protectedStaticToInstance' => ['[BC] CHANGED: Property $protectedStaticToInstance of TheClass changed scope from static to instance'], |
||
| 113 | 'protectedInstanceToInstance' => [], |
||
| 114 | 'protectedStaticToStatic' => [], |
||
| 115 | |||
| 116 | 'privateInstanceToStatic' => ['[BC] CHANGED: Property $privateInstanceToStatic of TheClass changed scope from instance to static'], |
||
| 117 | 'privateStaticToInstance' => ['[BC] CHANGED: Property $privateStaticToInstance of 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 $property, array $errorMessages) use ($fromClass, $toClass) : array { |
||
| 126 | return [ |
||
| 127 | $fromClass->getProperty($property), |
||
| 128 | $toClass->getProperty($property), |
||
| 129 | $errorMessages, |
||
| 130 | ]; |
||
| 131 | }, |
||
| 132 | array_keys($properties), |
||
| 133 | $properties |
||
| 134 | ) |
||
| 138 |