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 $publicInstanceToStatic; |
||
61 | public static $publicStaticToInstance; |
||
62 | public $publicInstanceToInstance; |
||
63 | public static $publicStaticToStatic; |
||
64 | |||
65 | protected $protectedInstanceToStatic; |
||
66 | protected static $protectedStaticToInstance; |
||
67 | protected $protectedInstanceToInstance; |
||
68 | protected static $protectedStaticToStatic; |
||
69 | |||
70 | private $privateInstanceToStatic; |
||
71 | private static $privateStaticToInstance; |
||
72 | private $privateInstanceToInstance; |
||
73 | private static $privateStaticToStatic; |
||
74 | } |
||
75 | PHP |
||
76 | , |
||
77 | $astLocator |
||
78 | ); |
||
79 | |||
80 | $toLocator = new StringSourceLocator( |
||
81 | <<<'PHP' |
||
82 | <?php |
||
83 | |||
84 | class TheClass { |
||
85 | public static $publicInstanceToStatic; |
||
86 | public $publicStaticToInstance; |
||
87 | public $publicInstanceToInstance; |
||
88 | public static $publicStaticToStatic; |
||
89 | |||
90 | protected static $protectedInstanceToStatic; |
||
91 | protected $protectedStaticToInstance; |
||
92 | protected $protectedInstanceToInstance; |
||
93 | protected static $protectedStaticToStatic; |
||
94 | |||
95 | private static $privateInstanceToStatic; |
||
96 | private $privateStaticToInstance; |
||
97 | private $privateInstanceToInstance; |
||
98 | private static $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: Property $publicInstanceToStatic of TheClass changed scope from instance to static'], |
||
112 | 'publicStaticToInstance' => ['[BC] CHANGED: Property $publicStaticToInstance of TheClass changed scope from static to instance'], |
||
113 | 'publicInstanceToInstance' => [], |
||
114 | 'publicStaticToStatic' => [], |
||
115 | |||
116 | 'protectedInstanceToStatic' => ['[BC] CHANGED: Property $protectedInstanceToStatic of TheClass changed scope from instance to static'], |
||
117 | 'protectedStaticToInstance' => ['[BC] CHANGED: Property $protectedStaticToInstance of TheClass changed scope from static to instance'], |
||
118 | 'protectedInstanceToInstance' => [], |
||
119 | 'protectedStaticToStatic' => [], |
||
120 | |||
121 | 'privateInstanceToStatic' => ['[BC] CHANGED: Property $privateInstanceToStatic of TheClass changed scope from instance to static'], |
||
122 | 'privateStaticToInstance' => ['[BC] CHANGED: Property $privateStaticToInstance of 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 $property, array $errorMessages) use ($fromClass, $toClass) : array { |
||
132 | return [ |
||
133 | TypeRestriction::object($fromClass->getProperty($property)), |
||
134 | TypeRestriction::object($toClass->getProperty($property)), |
||
135 | $errorMessages, |
||
136 | ]; |
||
137 | }, |
||
138 | array_keys($properties), |
||
139 | $properties |
||
140 | ) |
||
144 |