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