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