| 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 |
||
| 50 | public function propertiesToBeTested() : array |
||
| 51 | { |
||
| 52 | $astLocator = (new BetterReflection())->astLocator(); |
||
| 53 | |||
| 54 | $fromLocator = new StringSourceLocator( |
||
| 55 | <<<'PHP' |
||
| 56 | <?php |
||
| 57 | |||
| 58 | class TheClass { |
||
| 59 | public $nonInternal; |
||
| 60 | public $becameInternal; |
||
| 61 | /** @internal */ |
||
| 62 | public $becameNonInternal; |
||
| 63 | /** @internal */ |
||
| 64 | public $stayedInternal; |
||
| 65 | } |
||
| 66 | PHP |
||
| 67 | , |
||
| 68 | $astLocator |
||
| 69 | ); |
||
| 70 | |||
| 71 | $toLocator = new StringSourceLocator( |
||
| 72 | <<<'PHP' |
||
| 73 | <?php |
||
| 74 | |||
| 75 | class TheClass { |
||
| 76 | public $nonInternal; |
||
| 77 | /** @internal */ |
||
| 78 | public $becameInternal; |
||
| 79 | public $becameNonInternal; |
||
| 80 | /** @internal */ |
||
| 81 | public $stayedInternal; |
||
| 82 | } |
||
| 83 | PHP |
||
| 84 | , |
||
| 85 | $astLocator |
||
| 86 | ); |
||
| 87 | |||
| 88 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 89 | $toClassReflector = new ClassReflector($toLocator); |
||
| 90 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
| 91 | $toClass = $toClassReflector->reflect('TheClass'); |
||
| 92 | |||
| 93 | $properties = [ |
||
| 94 | 'nonInternal' => [], |
||
| 95 | 'becameInternal' => ['[BC] CHANGED: Property TheClass#$becameInternal was marked "@internal"'], |
||
| 96 | 'becameNonInternal' => [], |
||
| 97 | 'stayedInternal' => [], |
||
| 98 | ]; |
||
| 99 | |||
| 100 | return array_combine( |
||
| 101 | array_keys($properties), |
||
| 102 | array_map( |
||
| 103 | static function (string $property, array $errorMessages) use ($fromClass, $toClass) : array { |
||
| 104 | return [ |
||
| 105 | $fromClass->getProperty($property), |
||
| 106 | $toClass->getProperty($property), |
||
| 107 | $errorMessages, |
||
| 108 | ]; |
||
| 109 | }, |
||
| 110 | array_keys($properties), |
||
| 111 | $properties |
||
| 112 | ) |
||
| 116 |