| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 49 |
| 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 |
||
| 12 | public function testOptimizedOhm() { |
||
| 13 | $node = new BinaryOperatorASTNode( |
||
| 14 | '*', |
||
| 15 | new BinaryOperatorASTNode( |
||
| 16 | '*', |
||
| 17 | new BinaryOperatorASTNode( |
||
| 18 | '*', |
||
| 19 | new UnitASTNode('kg'), |
||
| 20 | new BinaryOperatorASTNode( |
||
| 21 | '^', |
||
| 22 | new UnitASTNode('m'), |
||
| 23 | new DigitASTNode('2') |
||
| 24 | ) |
||
| 25 | ), |
||
| 26 | new BinaryOperatorASTNode( |
||
| 27 | '^', |
||
| 28 | new UnitASTNode('s'), |
||
| 29 | new DigitASTNode('-3') |
||
| 30 | ) |
||
| 31 | ), |
||
| 32 | new BinaryOperatorASTNode( |
||
| 33 | '^', |
||
| 34 | new UnitASTNode('A'), |
||
| 35 | new DigitASTNode('-2') |
||
| 36 | ) |
||
| 37 | ); |
||
| 38 | |||
| 39 | $optimizer = new Optimizer(); |
||
| 40 | |||
| 41 | $optimized = $optimizer->optimize($node); |
||
| 42 | |||
| 43 | $this->assertEquals( |
||
| 44 | new BinaryOperatorASTNode( |
||
| 45 | '*', |
||
| 46 | new BinaryOperatorASTNode( |
||
| 47 | '*', |
||
| 48 | new BinaryOperatorASTNode( |
||
| 49 | '*', |
||
| 50 | new UnitASTNode('kg'), |
||
| 51 | new BinaryOperatorASTNode( |
||
| 52 | '^', |
||
| 53 | new UnitASTNode('m'), |
||
| 54 | new DigitASTNode(2) |
||
| 55 | ) |
||
| 56 | ), |
||
| 57 | new BinaryOperatorASTNode( |
||
| 58 | '/', |
||
| 59 | new DigitASTNode(1), |
||
| 60 | new BinaryOperatorASTNode( |
||
| 61 | '^', |
||
| 62 | new UnitASTNode('s'), |
||
| 63 | new DigitASTNode(3) |
||
| 64 | ) |
||
| 65 | ) |
||
| 66 | ), |
||
| 67 | new BinaryOperatorASTNode( |
||
| 68 | '/', |
||
| 69 | new DigitASTNode(1), |
||
| 70 | new BinaryOperatorASTNode( |
||
| 71 | '^', |
||
| 72 | new UnitASTNode('A'), |
||
| 73 | new DigitASTNode(2) |
||
| 74 | ) |
||
| 75 | ) |
||
| 76 | ), |
||
| 77 | $optimized |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | } |