Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 31 |
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 |
||
39 | public function classesToBeTested() : array |
||
40 | { |
||
41 | $locator = (new BetterReflection())->astLocator(); |
||
42 | $fromReflector = new ClassReflector(new StringSourceLocator( |
||
43 | <<<'PHP' |
||
44 | <?php |
||
45 | |||
46 | class ConcreteToAbstract {} |
||
47 | abstract class AbstractToConcrete {} |
||
48 | class ConcreteToConcrete {} |
||
49 | abstract class AbstractToAbstract {} |
||
50 | class ConcreteToInterface {} |
||
51 | interface InterfaceToConcrete {} |
||
52 | interface InterfaceToInterface {} |
||
53 | interface InterfaceToAbstract {} |
||
54 | abstract class AbstractToInterface {} |
||
55 | PHP |
||
56 | , |
||
57 | $locator |
||
58 | )); |
||
59 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
60 | <<<'PHP' |
||
61 | <?php |
||
62 | |||
63 | abstract class ConcreteToAbstract {} |
||
64 | class AbstractToConcrete {} |
||
65 | class ConcreteToConcrete {} |
||
66 | abstract class AbstractToAbstract {} |
||
67 | interface ConcreteToInterface {} |
||
68 | class InterfaceToConcrete {} |
||
69 | interface InterfaceToInterface {} |
||
70 | abstract class InterfaceToAbstract {} |
||
71 | interface AbstractToInterface {} |
||
72 | PHP |
||
73 | , |
||
74 | $locator |
||
75 | )); |
||
76 | |||
77 | $classes = [ |
||
78 | 'ConcreteToAbstract' => [], |
||
79 | 'AbstractToConcrete' => [], |
||
80 | 'ConcreteToConcrete' => [], |
||
81 | 'AbstractToAbstract' => [], |
||
82 | 'ConcreteToInterface' => [], |
||
83 | 'InterfaceToConcrete' => ['[BC] CHANGED: Interface InterfaceToConcrete became a class'], |
||
84 | 'InterfaceToInterface' => [], |
||
85 | 'InterfaceToAbstract' => ['[BC] CHANGED: Interface InterfaceToAbstract became a class'], |
||
86 | 'AbstractToInterface' => [], |
||
87 | ]; |
||
88 | |||
89 | return array_combine( |
||
90 | array_keys($classes), |
||
91 | array_map( |
||
92 | function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
||
93 | return [ |
||
94 | $fromReflector->reflect($className), |
||
95 | $toReflector->reflect($className), |
||
96 | $errors, |
||
97 | ]; |
||
98 | }, |
||
99 | array_keys($classes), |
||
100 | $classes |
||
101 | ) |
||
105 |