@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * Convert without the bother of an object |
| 17 | 17 | */ |
| 18 | - static public function convert( $amount, $fromUnit, $toUnit ) { |
|
| 18 | + static public function convert($amount, $fromUnit, $toUnit) { |
|
| 19 | 19 | $quantity = new static($amount, $fromUnit); |
| 20 | 20 | return $quantity->to($toUnit); |
| 21 | 21 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * Check if the given unit is valid for this quantity |
| 25 | 25 | */ |
| 26 | - static public function validUnit( $unit ) { |
|
| 26 | + static public function validUnit($unit) { |
|
| 27 | 27 | $units = static::$units; |
| 28 | - if ( isset($units[0]) ) { |
|
| 28 | + if (isset($units[0])) { |
|
| 29 | 29 | return in_array($unit, $units); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * |
| 43 | 43 | */ |
| 44 | - public function __construct( $amount, $unit = null, $convertToDefault = true ) { |
|
| 44 | + public function __construct($amount, $unit = null, $convertToDefault = true) { |
|
| 45 | 45 | // Invalid unit! |
| 46 | - if ( $unit && !static::validUnit($unit) ) { |
|
| 46 | + if ($unit && !static::validUnit($unit)) { |
|
| 47 | 47 | $quantity = (new \ReflectionClass(get_called_class()))->getShortName(); |
| 48 | 48 | throw new ConversionException("Can't import '$quantity' as '$unit'."); |
| 49 | 49 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->original_unit = $this->unit; |
| 55 | 55 | |
| 56 | 56 | // Convert incoming unit into storage unit |
| 57 | - if ( $convertToDefault && $this->unit != $this::$default_unit ) { |
|
| 57 | + if ($convertToDefault && $this->unit != $this::$default_unit) { |
|
| 58 | 58 | $this->amount = $this->to($this::$default_unit); |
| 59 | 59 | $this->unit = $this::$default_unit; |
| 60 | 60 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Convert object amount to another unit, and return, don't save |
| 65 | 65 | */ |
| 66 | - public function to( $toUnit ) { |
|
| 67 | - if ( $toUnit === 'base' ) { |
|
| 66 | + public function to($toUnit) { |
|
| 67 | + if ($toUnit === 'base') { |
|
| 68 | 68 | $toUnit = static::BASE_UNIT; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * The convertor heart, that every sub class needs |
| 76 | 76 | */ |
| 77 | - abstract protected function convertor( $toUnit ); |
|
| 77 | + abstract protected function convertor($toUnit); |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * The default convertor, using the Quantity's conversion table |
| 81 | 81 | */ |
| 82 | - protected function convertUsingTable( $toUnit ) { |
|
| 82 | + protected function convertUsingTable($toUnit) { |
|
| 83 | 83 | // Invalid unit! |
| 84 | - if ( !$this::validUnit($toUnit) ) { |
|
| 84 | + if (!$this::validUnit($toUnit)) { |
|
| 85 | 85 | $quantity = (new \ReflectionClass($this))->getShortName(); |
| 86 | 86 | throw new ConversionException("Can't convert '$quantity' to '$toUnit'."); |
| 87 | 87 | } |
@@ -102,15 +102,15 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Advanded convertor, using unit-base-unit methods |
| 104 | 104 | */ |
| 105 | - protected function convertUsingMethods( $toUnit ) { |
|
| 105 | + protected function convertUsingMethods($toUnit) { |
|
| 106 | 106 | $amount = $this->amount; |
| 107 | 107 | |
| 108 | - if ( $this->unit != $this::BASE_UNIT ) { |
|
| 109 | - $amount = call_user_func(array($this, $this->unit . 'to' . $this::BASE_UNIT), $amount); |
|
| 108 | + if ($this->unit != $this::BASE_UNIT) { |
|
| 109 | + $amount = call_user_func(array($this, $this->unit.'to'.$this::BASE_UNIT), $amount); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( $this::BASE_UNIT != $toUnit ) { |
|
| 113 | - $amount = call_user_func(array($this, $this::BASE_UNIT . 'to' . $toUnit), $amount); |
|
| 112 | + if ($this::BASE_UNIT != $toUnit) { |
|
| 113 | + $amount = call_user_func(array($this, $this::BASE_UNIT.'to'.$toUnit), $amount); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return $amount; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | /** |
| 120 | 120 | * Convert the object to another standard unit |
| 121 | 121 | */ |
| 122 | - public function convertTo( $unit ) { |
|
| 122 | + public function convertTo($unit) { |
|
| 123 | 123 | $this->amount = $this->to($unit); |
| 124 | 124 | $this->unit = $unit; |
| 125 | 125 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function all() { |
| 131 | 131 | $all = array(); |
| 132 | - foreach ( $this::$units as $unit => $conversion ) { |
|
| 133 | - if ( is_int($unit) ) { |
|
| 132 | + foreach ($this::$units as $unit => $conversion) { |
|
| 133 | + if (is_int($unit)) { |
|
| 134 | 134 | $unit = $conversion; |
| 135 | 135 | } |
| 136 | 136 | |