| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| Code Lines | 34 |
| 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 |
||
| 48 | public function interfacesToBeTested() : array |
||
| 49 | { |
||
| 50 | $astLocator = (new BetterReflection())->astLocator(); |
||
| 51 | |||
| 52 | $fromLocator = new StringSourceLocator( |
||
| 53 | <<<'PHP' |
||
| 54 | <?php |
||
| 55 | |||
| 56 | interface A {} |
||
| 57 | interface B { |
||
| 58 | function removed() {} |
||
| 59 | } |
||
| 60 | interface C { |
||
| 61 | function kept() {} |
||
| 62 | } |
||
| 63 | interface D { |
||
| 64 | function casingChanged() {} |
||
| 65 | } |
||
| 66 | interface E {} |
||
| 67 | interface F { |
||
| 68 | public function a() {} |
||
| 69 | public function c() {} |
||
| 70 | } |
||
| 71 | PHP |
||
| 72 | , |
||
| 73 | $astLocator |
||
| 74 | ); |
||
| 75 | |||
| 76 | $toLocator = new StringSourceLocator( |
||
| 77 | <<<'PHP' |
||
| 78 | <?php |
||
| 79 | |||
| 80 | interface A { |
||
| 81 | function added() {} |
||
| 82 | } |
||
| 83 | interface B {} |
||
| 84 | interface C { |
||
| 85 | function kept() {} |
||
| 86 | } |
||
| 87 | interface D { |
||
| 88 | function casingchanged() {} |
||
| 89 | } |
||
| 90 | interface E { |
||
| 91 | function added1() {} |
||
| 92 | function added2() {} |
||
| 93 | function ADDED3() {} |
||
| 94 | } |
||
| 95 | interface F { |
||
| 96 | public function a() {} |
||
| 97 | public function b() {} |
||
| 98 | public function c() {} |
||
| 99 | } |
||
| 100 | PHP |
||
| 101 | , |
||
| 102 | $astLocator |
||
| 103 | ); |
||
| 104 | |||
| 105 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 106 | $toClassReflector = new ClassReflector($toLocator); |
||
| 107 | |||
| 108 | $properties = [ |
||
| 109 | 'A' => ['[BC] ADDED: Method added() was added to interface A'], |
||
| 110 | 'B' => [], |
||
| 111 | 'C' => [], |
||
| 112 | 'D' => [], |
||
| 113 | 'E' => [ |
||
| 114 | '[BC] ADDED: Method added1() was added to interface E', |
||
| 115 | '[BC] ADDED: Method added2() was added to interface E', |
||
| 116 | '[BC] ADDED: Method ADDED3() was added to interface E', |
||
| 117 | ], |
||
| 118 | 'F' => ['[BC] ADDED: Method b() was added to interface F'], |
||
| 119 | ]; |
||
| 120 | |||
| 121 | return TypeRestriction::array(array_combine( |
||
| 122 | array_keys($properties), |
||
| 123 | array_map( |
||
| 124 | /** @psalm-param list<string> $errorMessages https://github.com/vimeo/psalm/issues/2772 */ |
||
| 125 | static function (string $className, array $errorMessages) use ($fromClassReflector, $toClassReflector |
||
| 126 | ) : array { |
||
| 127 | return [ |
||
| 128 | $fromClassReflector->reflect($className), |
||
| 129 | $toClassReflector->reflect($className), |
||
| 130 | $errorMessages, |
||
| 131 | ]; |
||
| 132 | }, |
||
| 133 | array_keys($properties), |
||
| 134 | $properties |
||
| 135 | ) |
||
| 139 |