| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| Code Lines | 33 |
| 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 |
||
| 43 | public function interfacesToBeTested() : array |
||
| 44 | { |
||
| 45 | $astLocator = (new BetterReflection())->astLocator(); |
||
| 46 | |||
| 47 | $fromLocator = new StringSourceLocator( |
||
| 48 | <<<'PHP' |
||
| 49 | <?php |
||
| 50 | |||
| 51 | interface A {} |
||
| 52 | interface B { |
||
| 53 | function removed() {} |
||
| 54 | } |
||
| 55 | interface C { |
||
| 56 | function kept() {} |
||
| 57 | } |
||
| 58 | interface D { |
||
| 59 | function casingChanged() {} |
||
| 60 | } |
||
| 61 | interface E {} |
||
| 62 | PHP |
||
| 63 | , |
||
| 64 | $astLocator |
||
| 65 | ); |
||
| 66 | |||
| 67 | $toLocator = new StringSourceLocator( |
||
| 68 | <<<'PHP' |
||
| 69 | <?php |
||
| 70 | |||
| 71 | interface A { |
||
| 72 | function added() {} |
||
| 73 | } |
||
| 74 | interface B {} |
||
| 75 | interface C { |
||
| 76 | function kept() {} |
||
| 77 | } |
||
| 78 | interface D { |
||
| 79 | function casingchanged() {} |
||
| 80 | } |
||
| 81 | interface E { |
||
| 82 | function added1() {} |
||
| 83 | function added2() {} |
||
| 84 | function ADDED3() {} |
||
| 85 | } |
||
| 86 | PHP |
||
| 87 | , |
||
| 88 | $astLocator |
||
| 89 | ); |
||
| 90 | |||
| 91 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 92 | $toClassReflector = new ClassReflector($toLocator); |
||
| 93 | |||
| 94 | $properties = [ |
||
| 95 | 'A' => ['[BC] ADDED: Method added() was added to interface A'], |
||
| 96 | 'B' => [], |
||
| 97 | 'C' => [], |
||
| 98 | 'D' => [], |
||
| 99 | 'E' => [ |
||
| 100 | '[BC] ADDED: Method added1() was added to interface E', |
||
| 101 | '[BC] ADDED: Method added2() was added to interface E', |
||
| 102 | '[BC] ADDED: Method ADDED3() was added to interface E', |
||
| 103 | ], |
||
| 104 | ]; |
||
| 105 | |||
| 106 | return array_combine( |
||
| 107 | array_keys($properties), |
||
| 108 | array_map( |
||
| 109 | function (string $className, array $errorMessages) use ($fromClassReflector, $toClassReflector |
||
| 110 | ) : array { |
||
| 111 | return [ |
||
| 112 | $fromClassReflector->reflect($className), |
||
| 113 | $toClassReflector->reflect($className), |
||
| 114 | $errorMessages, |
||
| 115 | ]; |
||
| 116 | }, |
||
| 117 | array_keys($properties), |
||
| 118 | $properties |
||
| 119 | ) |
||
| 123 |