Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
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 interfacesToBeTested() : array |
||
52 | { |
||
53 | $locator = (new BetterReflection())->astLocator(); |
||
54 | $fromReflector = new ClassReflector(new StringSourceLocator( |
||
55 | <<<'PHP' |
||
56 | <?php |
||
57 | |||
58 | interface IA {} |
||
59 | interface IB extends IA {} |
||
60 | interface IC extends IB {} |
||
61 | interface ID {} |
||
62 | interface ParentInterfaceAdded {} |
||
63 | interface ParentInterfaceRemoved extends IA {} |
||
64 | interface ParentInterfaceIndirectlyRemoved extends IB {} |
||
65 | interface ParentInterfaceVeryIndirectlyRemoved extends IC {} |
||
66 | interface ParentInterfaceOrderSwapped extends IA, ID {} |
||
67 | PHP |
||
68 | , |
||
69 | $locator |
||
70 | )); |
||
71 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
72 | <<<'PHP' |
||
73 | <?php |
||
74 | |||
75 | interface IA {} |
||
76 | interface IB {} |
||
77 | interface IC extends IB {} |
||
78 | interface ID {} |
||
79 | interface ParentInterfaceAdded extends IA {} |
||
80 | interface ParentInterfaceRemoved {} |
||
81 | interface ParentInterfaceIndirectlyRemoved extends IB {} |
||
82 | interface ParentInterfaceVeryIndirectlyRemoved extends IC {} |
||
83 | interface ParentInterfaceOrderSwapped extends ID, IA {} |
||
84 | PHP |
||
85 | , |
||
86 | $locator |
||
87 | )); |
||
88 | |||
89 | $interfaces = [ |
||
90 | 'IA' => [], |
||
91 | 'IB' => ['[BC] REMOVED: These ancestors of IB have been removed: ["IA"]'], |
||
92 | 'IC' => ['[BC] REMOVED: These ancestors of IC have been removed: ["IA"]'], |
||
93 | 'ParentInterfaceAdded' => [], |
||
94 | 'ParentInterfaceRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceRemoved have been removed: ["IA"]'], |
||
95 | 'ParentInterfaceIndirectlyRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceIndirectlyRemoved have been removed: ["IA"]'], |
||
96 | 'ParentInterfaceVeryIndirectlyRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceVeryIndirectlyRemoved have been removed: ["IA"]'], |
||
97 | 'ParentInterfaceOrderSwapped' => [], |
||
98 | ]; |
||
99 | |||
100 | return TypeRestriction::array(array_combine( |
||
101 | array_keys($interfaces), |
||
102 | array_map( |
||
103 | /** @psalm-param list<string> $errors https://github.com/vimeo/psalm/issues/2772 */ |
||
104 | static function (string $interfaceName, array $errors) use ($fromReflector, $toReflector) : array { |
||
105 | return [ |
||
106 | $fromReflector->reflect($interfaceName), |
||
107 | $toReflector->reflect($interfaceName), |
||
108 | $errors, |
||
109 | ]; |
||
110 | }, |
||
111 | array_keys($interfaces), |
||
112 | $interfaces |
||
113 | ) |
||
117 |