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