| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 42 |
| 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 A {} |
||
| 54 | class B extends A {} |
||
| 55 | class C extends A {} |
||
| 56 | class D extends C {} |
||
| 57 | interface IA {} |
||
| 58 | interface IB extends IA {} |
||
| 59 | interface IC extends IA {} |
||
| 60 | interface ID extends IB, IE {} |
||
| 61 | interface IE {} |
||
| 62 | interface IG {} |
||
| 63 | class ClassWithNoAncestors {} |
||
| 64 | class ClassWithAddedAncestors {} |
||
| 65 | class ClassWithAddedInterface {} |
||
| 66 | class ClassWithRemovedAncestor extends A {} |
||
| 67 | class ClassWithRemovedIndirectAncestor extends B {} |
||
| 68 | class ClassWithRemovedVeryIndirectAncestor extends D {} |
||
| 69 | class ClassWithRemovedInterface implements IA {} |
||
| 70 | class ClassWithRemovedIndirectInterface implements IB {} |
||
| 71 | class ClassWithRemovedVeryIndirectInterface implements ID {} |
||
| 72 | class ClassWithInvertedInterfaceNames implements IE, IG {} |
||
| 73 | PHP |
||
| 74 | , |
||
| 75 | $locator |
||
| 76 | )); |
||
| 77 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
| 78 | <<<'PHP' |
||
| 79 | <?php |
||
| 80 | |||
| 81 | class A {} |
||
| 82 | class B {} |
||
| 83 | class C {} |
||
| 84 | class D extends C {} |
||
| 85 | interface IA {} |
||
| 86 | interface IB {} |
||
| 87 | interface IC extends IA {} |
||
| 88 | interface ID extends IB, IE {} |
||
| 89 | interface IE {} |
||
| 90 | interface IG {} |
||
| 91 | class ClassWithNoAncestors {} |
||
| 92 | class ClassWithAddedAncestors extends A {} |
||
| 93 | class ClassWithAddedInterface implements IA {} |
||
| 94 | class ClassWithRemovedAncestor {} |
||
| 95 | class ClassWithRemovedIndirectAncestor extends B {} |
||
| 96 | class ClassWithRemovedVeryIndirectAncestor extends D {} |
||
| 97 | class ClassWithRemovedInterface {} |
||
| 98 | class ClassWithRemovedIndirectInterface implements IB {} |
||
| 99 | class ClassWithRemovedVeryIndirectInterface implements ID {} |
||
| 100 | class ClassWithInvertedInterfaceNames implements IG, IE {} |
||
| 101 | PHP |
||
| 102 | , |
||
| 103 | $locator |
||
| 104 | )); |
||
| 105 | |||
| 106 | $classes = [ |
||
| 107 | 'A' => [], |
||
| 108 | 'B' => ['[BC] REMOVED: These ancestors of B have been removed: ["A"]'], |
||
| 109 | 'C' => ['[BC] REMOVED: These ancestors of C have been removed: ["A"]'], |
||
| 110 | 'D' => ['[BC] REMOVED: These ancestors of D have been removed: ["A"]'], |
||
| 111 | 'IA' => [], |
||
| 112 | 'IB' => ['[BC] REMOVED: These ancestors of IB have been removed: ["IA"]'], |
||
| 113 | 'IC' => [], |
||
| 114 | 'ID' => ['[BC] REMOVED: These ancestors of ID have been removed: ["IA"]'], |
||
| 115 | 'IE' => [], |
||
| 116 | 'IG' => [], |
||
| 117 | 'ClassWithNoAncestors' => [], |
||
| 118 | 'ClassWithAddedAncestors' => [], |
||
| 119 | 'ClassWithAddedInterface' => [], |
||
| 120 | 'ClassWithRemovedAncestor' => ['[BC] REMOVED: These ancestors of ClassWithRemovedAncestor have been removed: ["A"]'], |
||
| 121 | 'ClassWithRemovedIndirectAncestor' => ['[BC] REMOVED: These ancestors of ClassWithRemovedIndirectAncestor have been removed: ["A"]'], |
||
| 122 | 'ClassWithRemovedVeryIndirectAncestor' => ['[BC] REMOVED: These ancestors of ClassWithRemovedVeryIndirectAncestor have been removed: ["A"]'], |
||
| 123 | 'ClassWithRemovedInterface' => ['[BC] REMOVED: These ancestors of ClassWithRemovedInterface have been removed: ["IA"]'], |
||
| 124 | 'ClassWithRemovedIndirectInterface' => ['[BC] REMOVED: These ancestors of ClassWithRemovedIndirectInterface have been removed: ["IA"]'], |
||
| 125 | 'ClassWithRemovedVeryIndirectInterface' => ['[BC] REMOVED: These ancestors of ClassWithRemovedVeryIndirectInterface have been removed: ["IA"]'], |
||
| 126 | 'ClassWithInvertedInterfaceNames' => [], |
||
| 127 | ]; |
||
| 128 | |||
| 129 | return array_combine( |
||
| 130 | array_keys($classes), |
||
| 131 | array_map( |
||
| 132 | function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
||
| 133 | return [ |
||
| 134 | $fromReflector->reflect($className), |
||
| 135 | $toReflector->reflect($className), |
||
| 136 | $errors, |
||
| 137 | ]; |
||
| 138 | }, |
||
| 139 | array_keys($classes), |
||
| 140 | $classes |
||
| 141 | ) |
||
| 145 |