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