Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 29 |
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 classesToBeTested() : array |
||
47 | { |
||
48 | $locator = (new BetterReflection())->astLocator(); |
||
49 | $fromReflector = new ClassReflector(new StringSourceLocator( |
||
50 | <<<'PHP' |
||
51 | <?php |
||
52 | |||
53 | trait TraitToClass {} |
||
54 | trait TraitToInterface {} |
||
55 | class ClassToTrait {} |
||
56 | trait TraitToTrait {} |
||
57 | class ClassToClass {} |
||
58 | interface InterfaceToTrait {} |
||
59 | interface InterfaceToInterface {} |
||
60 | PHP |
||
61 | , |
||
62 | $locator |
||
63 | )); |
||
64 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
65 | <<<'PHP' |
||
66 | <?php |
||
67 | |||
68 | class TraitToClass {} |
||
69 | interface TraitToInterface {} |
||
70 | trait ClassToTrait {} |
||
71 | trait TraitToTrait {} |
||
72 | class ClassToClass {} |
||
73 | trait InterfaceToTrait {} |
||
74 | interface InterfaceToInterface {} |
||
75 | PHP |
||
76 | , |
||
77 | $locator |
||
78 | )); |
||
79 | |||
80 | $classes = [ |
||
81 | 'TraitToClass' => ['[BC] CHANGED: Trait TraitToClass became a class'], |
||
82 | 'TraitToInterface' => [], |
||
83 | 'ClassToTrait' => [], |
||
84 | 'TraitToTrait' => [], |
||
85 | 'ClassToClass' => [], |
||
86 | 'InterfaceToTrait' => [], |
||
87 | 'InterfaceToInterface' => [], |
||
88 | ]; |
||
89 | |||
90 | return array_combine( |
||
91 | array_keys($classes), |
||
92 | array_map( |
||
93 | function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
||
94 | return [ |
||
95 | $fromReflector->reflect($className), |
||
96 | $toReflector->reflect($className), |
||
97 | $errors, |
||
98 | ]; |
||
99 | }, |
||
100 | array_keys($classes), |
||
101 | $classes |
||
102 | ) |
||
106 |