| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 30 |
| 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 interfacesToBeTested() : array |
||
| 47 | { |
||
| 48 | $locator = (new BetterReflection())->astLocator(); |
||
| 49 | $fromReflector = new ClassReflector(new StringSourceLocator( |
||
| 50 | <<<'PHP' |
||
| 51 | <?php |
||
| 52 | |||
| 53 | interface IA {} |
||
| 54 | interface IB extends IA {} |
||
| 55 | interface IC extends IB {} |
||
| 56 | interface ID {} |
||
| 57 | interface ParentInterfaceAdded {} |
||
| 58 | interface ParentInterfaceRemoved extends IA {} |
||
| 59 | interface ParentInterfaceIndirectlyRemoved extends IB {} |
||
| 60 | interface ParentInterfaceVeryIndirectlyRemoved extends IC {} |
||
| 61 | interface ParentInterfaceOrderSwapped extends IA, ID {} |
||
| 62 | PHP |
||
| 63 | , |
||
| 64 | $locator |
||
| 65 | )); |
||
| 66 | $toReflector = new ClassReflector(new StringSourceLocator( |
||
| 67 | <<<'PHP' |
||
| 68 | <?php |
||
| 69 | |||
| 70 | interface IA {} |
||
| 71 | interface IB {} |
||
| 72 | interface IC extends IB {} |
||
| 73 | interface ID {} |
||
| 74 | interface ParentInterfaceAdded extends IA {} |
||
| 75 | interface ParentInterfaceRemoved {} |
||
| 76 | interface ParentInterfaceIndirectlyRemoved extends IB {} |
||
| 77 | interface ParentInterfaceVeryIndirectlyRemoved extends IC {} |
||
| 78 | interface ParentInterfaceOrderSwapped extends ID, IA {} |
||
| 79 | PHP |
||
| 80 | , |
||
| 81 | $locator |
||
| 82 | )); |
||
| 83 | |||
| 84 | $interfaces = [ |
||
| 85 | 'IA' => [], |
||
| 86 | 'IB' => ['[BC] REMOVED: These ancestors of IB have been removed: ["IA"]'], |
||
| 87 | 'IC' => ['[BC] REMOVED: These ancestors of IC have been removed: ["IA"]'], |
||
| 88 | 'ParentInterfaceAdded' => [], |
||
| 89 | 'ParentInterfaceRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceRemoved have been removed: ["IA"]'], |
||
| 90 | 'ParentInterfaceIndirectlyRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceIndirectlyRemoved have been removed: ["IA"]'], |
||
| 91 | 'ParentInterfaceVeryIndirectlyRemoved' => ['[BC] REMOVED: These ancestors of ParentInterfaceVeryIndirectlyRemoved have been removed: ["IA"]'], |
||
| 92 | 'ParentInterfaceOrderSwapped' => [], |
||
| 93 | ]; |
||
| 94 | |||
| 95 | return array_combine( |
||
| 96 | array_keys($interfaces), |
||
| 97 | array_map( |
||
| 98 | function (string $interfaceName, array $errors) use ($fromReflector, $toReflector) : array { |
||
| 99 | return [ |
||
| 100 | $fromReflector->reflect($interfaceName), |
||
| 101 | $toReflector->reflect($interfaceName), |
||
| 102 | $errors, |
||
| 103 | ]; |
||
| 104 | }, |
||
| 105 | array_keys($interfaces), |
||
| 106 | $interfaces |
||
| 107 | ) |
||
| 111 |