| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 29 |
| 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 |
||
| 51 | public function classesToBeTested() : array |
||
| 52 | { |
||
| 53 | $locator = (new BetterReflection())->astLocator(); |
||
| 54 | $fromReflector = new ClassReflector(new StringSourceLocator( |
||
| 55 | <<<'PHP' |
||
| 56 | <?php |
||
| 57 | |||
| 58 | trait TraitToClass {} |
||
| 59 | trait TraitToInterface {} |
||
| 60 | class ClassToTrait {} |
||
| 61 | trait TraitToTrait {} |
||
| 62 | class ClassToClass {} |
||
| 63 | interface InterfaceToTrait {} |
||
| 64 | interface InterfaceToInterface {} |
||
| 65 | PHP |
||
| 66 | , |
||
| 67 | $locator |
||
| 68 | )); |
||
| 69 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
| 70 | <<<'PHP' |
||
| 71 | <?php |
||
| 72 | |||
| 73 | class TraitToClass {} |
||
| 74 | interface TraitToInterface {} |
||
| 75 | trait ClassToTrait {} |
||
| 76 | trait TraitToTrait {} |
||
| 77 | class ClassToClass {} |
||
| 78 | trait InterfaceToTrait {} |
||
| 79 | interface InterfaceToInterface {} |
||
| 80 | PHP |
||
| 81 | , |
||
| 82 | $locator |
||
| 83 | )); |
||
| 84 | |||
| 85 | $classes = [ |
||
| 86 | 'TraitToClass' => ['[BC] CHANGED: Trait TraitToClass became a class'], |
||
| 87 | 'TraitToInterface' => [], |
||
| 88 | 'ClassToTrait' => [], |
||
| 89 | 'TraitToTrait' => [], |
||
| 90 | 'ClassToClass' => [], |
||
| 91 | 'InterfaceToTrait' => [], |
||
| 92 | 'InterfaceToInterface' => [], |
||
| 93 | ]; |
||
| 94 | |||
| 95 | return TypeRestriction::array(array_combine( |
||
| 96 | array_keys($classes), |
||
| 97 | array_map( |
||
| 98 | /** @psalm-param list<string> $errors https://github.com/vimeo/psalm/issues/2772 */ |
||
| 99 | static function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
||
| 100 | return [ |
||
| 101 | $fromReflector->reflect($className), |
||
| 102 | $toReflector->reflect($className), |
||
| 103 | $errors, |
||
| 104 | ]; |
||
| 105 | }, |
||
| 106 | array_keys($classes), |
||
| 107 | $classes |
||
| 108 | ) |
||
| 112 |