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