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