Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 $nonInternal; |
||
61 | public $becameInternal; |
||
62 | /** @internal */ |
||
63 | public $becameNonInternal; |
||
64 | /** @internal */ |
||
65 | public $stayedInternal; |
||
66 | } |
||
67 | PHP |
||
68 | , |
||
69 | $astLocator |
||
70 | ); |
||
71 | |||
72 | $toLocator = new StringSourceLocator( |
||
73 | <<<'PHP' |
||
74 | <?php |
||
75 | |||
76 | class TheClass { |
||
77 | public $nonInternal; |
||
78 | /** @internal */ |
||
79 | public $becameInternal; |
||
80 | public $becameNonInternal; |
||
81 | /** @internal */ |
||
82 | public $stayedInternal; |
||
83 | } |
||
84 | PHP |
||
85 | , |
||
86 | $astLocator |
||
87 | ); |
||
88 | |||
89 | $fromClassReflector = new ClassReflector($fromLocator); |
||
90 | $toClassReflector = new ClassReflector($toLocator); |
||
91 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
92 | $toClass = $toClassReflector->reflect('TheClass'); |
||
93 | |||
94 | $properties = [ |
||
95 | 'nonInternal' => [], |
||
96 | 'becameInternal' => ['[BC] CHANGED: Property TheClass#$becameInternal was marked "@internal"'], |
||
97 | 'becameNonInternal' => [], |
||
98 | 'stayedInternal' => [], |
||
99 | ]; |
||
100 | |||
101 | return TypeRestriction::array(array_combine( |
||
102 | array_keys($properties), |
||
103 | array_map( |
||
104 | /** @psalm-param list<string> $errorMessages https://github.com/vimeo/psalm/issues/2772 */ |
||
105 | static function (string $property, array $errorMessages) use ($fromClass, $toClass) : array { |
||
106 | return [ |
||
107 | TypeRestriction::object($fromClass->getProperty($property)), |
||
108 | TypeRestriction::object($toClass->getProperty($property)), |
||
109 | $errorMessages, |
||
110 | ]; |
||
111 | }, |
||
112 | array_keys($properties), |
||
113 | $properties |
||
114 | ) |
||
118 |