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