Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
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 const publicNullToNull = null; |
||
61 | public const publicValueChanged = 1; |
||
62 | public const publicValueToSimilarValue = '1'; |
||
63 | public const publicExpressionToExpressionValue = 101 + 5; |
||
64 | |||
65 | protected const protectedNullToNull = null; |
||
66 | protected const protectedValueChanged = 1; |
||
67 | protected const protectedValueToSimilarValue = '1'; |
||
68 | protected const protectedExpressionToExpressionValue = 101 + 5; |
||
69 | |||
70 | private const privateNullToNull = null; |
||
71 | private const privateValueChanged = 1; |
||
72 | private const privateValueToSimilarValue = '1'; |
||
73 | private const privateExpressionToExpressionValue = 101 + 5; |
||
74 | } |
||
75 | PHP |
||
76 | , |
||
77 | $astLocator |
||
78 | ); |
||
79 | |||
80 | $toLocator = new StringSourceLocator( |
||
81 | <<<'PHP' |
||
82 | <?php |
||
83 | |||
84 | class TheClass { |
||
85 | public const publicNullToNull = null; |
||
86 | public const publicValueChanged = 2; |
||
87 | public const publicValueToSimilarValue = 1; |
||
88 | public const publicExpressionToExpressionValue = 106; |
||
89 | |||
90 | protected const protectedNullToNull = null; |
||
91 | protected const protectedValueChanged = 2; |
||
92 | protected const protectedValueToSimilarValue = 1; |
||
93 | protected const protectedExpressionToExpressionValue = 106; |
||
94 | |||
95 | private const privateNullToNull = null; |
||
96 | private const privateValueChanged = 2; |
||
97 | private const privateValueToSimilarValue = 1; |
||
98 | private const privateExpressionToExpressionValue = 106; |
||
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 | 'publicNullToNull' => [], |
||
112 | 'publicValueChanged' => ['[BC] CHANGED: Value of constant TheClass::publicValueChanged changed from 1 to 2'], |
||
113 | 'publicValueToSimilarValue' => ['[BC] CHANGED: Value of constant TheClass::publicValueToSimilarValue changed from \'1\' to 1'], |
||
114 | 'publicExpressionToExpressionValue' => [], |
||
115 | 'protectedNullToNull' => [], |
||
116 | 'protectedValueChanged' => ['[BC] CHANGED: Value of constant TheClass::protectedValueChanged changed from 1 to 2'], |
||
117 | 'protectedValueToSimilarValue' => ['[BC] CHANGED: Value of constant TheClass::protectedValueToSimilarValue changed from \'1\' to 1'], |
||
118 | 'protectedExpressionToExpressionValue' => [], |
||
119 | 'privateNullToNull' => [], |
||
120 | 'privateValueChanged' => [], |
||
121 | 'privateValueToSimilarValue' => [], |
||
122 | 'privateExpressionToExpressionValue' => [], |
||
123 | ]; |
||
124 | |||
125 | return TypeRestriction::array(array_combine( |
||
126 | array_keys($properties), |
||
127 | array_map( |
||
128 | /** @psalm-param list<string> $errorMessages https://github.com/vimeo/psalm/issues/2772 */ |
||
129 | static function (string $constant, array $errorMessages) use ($fromClass, $toClass) : array { |
||
130 | return [ |
||
131 | $fromClass->getReflectionConstant($constant), |
||
132 | $toClass->getReflectionConstant($constant), |
||
133 | $errorMessages, |
||
134 | ]; |
||
135 | }, |
||
136 | array_keys($properties), |
||
137 | $properties |
||
138 | ) |
||
142 |