| Conditions | 2 |
| Paths | 2 |
| Total Lines | 76 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 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 |
||
| 60 | public function validInputProvider() { |
||
| 61 | $amounts = [ |
||
| 62 | // amounts in various styles and forms |
||
| 63 | '0' => UnboundedQuantityValue::newFromNumber( 0 ), |
||
| 64 | '-0' => UnboundedQuantityValue::newFromNumber( 0 ), |
||
| 65 | '-00.00' => UnboundedQuantityValue::newFromNumber( '+0.00' ), |
||
| 66 | '+00.00' => UnboundedQuantityValue::newFromNumber( '+0.00' ), |
||
| 67 | '0001' => UnboundedQuantityValue::newFromNumber( 1 ), |
||
| 68 | '+01' => UnboundedQuantityValue::newFromNumber( 1 ), |
||
| 69 | '-1' => UnboundedQuantityValue::newFromNumber( -1 ), |
||
| 70 | '+42' => UnboundedQuantityValue::newFromNumber( 42 ), |
||
| 71 | ' - 42' => UnboundedQuantityValue::newFromNumber( -42 ), |
||
| 72 | '9001' => UnboundedQuantityValue::newFromNumber( 9001 ), |
||
| 73 | '.5' => UnboundedQuantityValue::newFromNumber( '+0.5' ), |
||
| 74 | '-.125' => UnboundedQuantityValue::newFromNumber( '-0.125' ), |
||
| 75 | '3.' => UnboundedQuantityValue::newFromNumber( 3 ), |
||
| 76 | ' 3 ' => UnboundedQuantityValue::newFromNumber( 3 ), |
||
| 77 | '2.125' => UnboundedQuantityValue::newFromNumber( '+2.125' ), |
||
| 78 | '2.1250' => UnboundedQuantityValue::newFromNumber( '+2.1250' ), |
||
| 79 | |||
| 80 | '1.4e-2' => UnboundedQuantityValue::newFromNumber( '+0.014' ), |
||
| 81 | '-1.4e-2' => UnboundedQuantityValue::newFromNumber( '-0.014' ), |
||
| 82 | '1.4e3' => UnboundedQuantityValue::newFromNumber( '+1400' ), |
||
| 83 | '1.4e3!m' => QuantityValue::newFromNumber( '+1400', 'm', '+1400', '+1400' ), |
||
| 84 | '1.4e3m2' => UnboundedQuantityValue::newFromNumber( '+1400', 'm2' ), |
||
| 85 | '1.4ev' => UnboundedQuantityValue::newFromNumber( '+1.4', 'ev' ), |
||
| 86 | '1.4e' => UnboundedQuantityValue::newFromNumber( '+1.4', 'e' ), |
||
| 87 | '12e3e4' => UnboundedQuantityValue::newFromNumber( '+12000', 'e4' ), |
||
| 88 | // FIXME: Add support for 12x10^3, see DecimalParser. |
||
| 89 | '0.004e3' => UnboundedQuantityValue::newFromNumber( '+4' ), |
||
| 90 | '0.004e-3' => UnboundedQuantityValue::newFromNumber( '+0.000004' ), |
||
| 91 | '4000e3' => UnboundedQuantityValue::newFromNumber( '+4000000' ), |
||
| 92 | '4000e-3' => UnboundedQuantityValue::newFromNumber( '+4.000' ), |
||
| 93 | |||
| 94 | // precision |
||
| 95 | '0!' => QuantityValue::newFromNumber( 0, '1', 0, 0 ), |
||
| 96 | '10.003!' => QuantityValue::newFromNumber( '+10.003', '1', '+10.003', '+10.003' ), |
||
| 97 | '-200!' => QuantityValue::newFromNumber( -200, '1', -200, -200 ), |
||
| 98 | '0~' => QuantityValue::newFromNumber( 0, '1', 0.5, -0.5 ), |
||
| 99 | '10.003~' => QuantityValue::newFromNumber( '+10.003', '1', '+10.0035', '+10.0025' ), |
||
| 100 | '-200~' => QuantityValue::newFromNumber( -200, '1', -199.5, -200.5 ), |
||
| 101 | |||
| 102 | // uncertainty |
||
| 103 | '5.3 +/- 0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 104 | '5.3+-0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 105 | '5.3 ±0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 106 | |||
| 107 | '5.3 +/- +0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 108 | '5.3+-+0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 109 | |||
| 110 | '5.3e3 +/- 0.2e2' => QuantityValue::newFromNumber( '+5300', '1', '+5320', '+5280' ), |
||
| 111 | '2e-2+/-1.1e-1' => QuantityValue::newFromNumber( '+0.02', '1', '+0.13', '-0.09' ), |
||
| 112 | |||
| 113 | // negative |
||
| 114 | '5.3 +/- -0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 115 | '5.3+--0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 116 | '5.3 ±-0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
| 117 | |||
| 118 | // units |
||
| 119 | '5.3+-0.2cm' => QuantityValue::newFromNumber( '+5.3', 'cm', '+5.5', '+5.1' ), |
||
| 120 | '10.003! km' => QuantityValue::newFromNumber( '+10.003', 'km', '+10.003', '+10.003' ), |
||
| 121 | '-200~ % ' => QuantityValue::newFromNumber( -200, '%', -199.5, -200.5 ), |
||
| 122 | '100003 m³' => UnboundedQuantityValue::newFromNumber( 100003, 'm³' ), |
||
| 123 | '3.±-0.2µ' => QuantityValue::newFromNumber( '+3', 'µ', '+3.2', '+2.8' ), |
||
| 124 | '+00.20 Å' => UnboundedQuantityValue::newFromNumber( '+0.20', 'Å' ), |
||
| 125 | ]; |
||
| 126 | |||
| 127 | $argLists = []; |
||
| 128 | |||
| 129 | foreach ( $amounts as $amount => $expected ) { |
||
| 130 | //NOTE: PHP may "helpfully" have converted $amount to an integer. Yay. |
||
| 131 | $argLists[$amount] = [ strval( $amount ), $expected ]; |
||
| 132 | } |
||
| 133 | |||
| 134 | return $argLists; |
||
| 135 | } |
||
| 136 | |||
| 274 |