@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Euro; |
| 6 | 6 | |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | * @param int $cents |
| 22 | 22 | * @throws InvalidArgumentException |
| 23 | 23 | */ |
| 24 | - private function __construct( int $cents ) { |
|
| 25 | - if ( $cents < 0 ) { |
|
| 26 | - throw new InvalidArgumentException( 'Amount needs to be positive' ); |
|
| 24 | + private function __construct(int $cents) { |
|
| 25 | + if ($cents < 0) { |
|
| 26 | + throw new InvalidArgumentException('Amount needs to be positive'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | $this->cents = $cents; |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * @return self |
| 35 | 35 | * @throws InvalidArgumentException |
| 36 | 36 | */ |
| 37 | - public static function newFromCents( int $cents ): self { |
|
| 38 | - return new self( $cents ); |
|
| 37 | + public static function newFromCents(int $cents): self { |
|
| 38 | + return new self($cents); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -49,32 +49,32 @@ discard block |
||
| 49 | 49 | * @return self |
| 50 | 50 | * @throws InvalidArgumentException |
| 51 | 51 | */ |
| 52 | - public static function newFromString( string $euroAmount ): self { |
|
| 53 | - if ( !is_numeric( $euroAmount ) ) { |
|
| 54 | - throw new InvalidArgumentException( 'Not a number' ); |
|
| 52 | + public static function newFromString(string $euroAmount): self { |
|
| 53 | + if (!is_numeric($euroAmount)) { |
|
| 54 | + throw new InvalidArgumentException('Not a number'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $parts = explode( '.', $euroAmount, 2 ); |
|
| 57 | + $parts = explode('.', $euroAmount, 2); |
|
| 58 | 58 | |
| 59 | - $euros = (int)$parts[0]; |
|
| 60 | - $cents = self::centsFromString( $parts[1] ?? '0' ); |
|
| 59 | + $euros = (int) $parts[0]; |
|
| 60 | + $cents = self::centsFromString($parts[1] ?? '0'); |
|
| 61 | 61 | |
| 62 | - return new self( $euros * self::CENTS_PER_EURO + $cents ); |
|
| 62 | + return new self($euros * self::CENTS_PER_EURO + $cents); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - private static function centsFromString( string $cents ): int { |
|
| 66 | - if ( strlen( $cents ) > self::DECIMAL_COUNT ) { |
|
| 67 | - return self::roundCentsToInt( $cents ); |
|
| 65 | + private static function centsFromString(string $cents): int { |
|
| 66 | + if (strlen($cents) > self::DECIMAL_COUNT) { |
|
| 67 | + return self::roundCentsToInt($cents); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Turn .1 into .10, so it ends up as 10 cents |
| 71 | - return (int)str_pad( $cents, self::DECIMAL_COUNT, '0' ); |
|
| 71 | + return (int) str_pad($cents, self::DECIMAL_COUNT, '0'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - private static function roundCentsToInt( string $cents ): int { |
|
| 75 | - $centsInt = (int)substr( $cents, 0, self::DECIMAL_COUNT ); |
|
| 74 | + private static function roundCentsToInt(string $cents): int { |
|
| 75 | + $centsInt = (int) substr($cents, 0, self::DECIMAL_COUNT); |
|
| 76 | 76 | |
| 77 | - if ( (int)$cents[self::DECIMAL_COUNT] >= 5 ) { |
|
| 77 | + if ((int) $cents[self::DECIMAL_COUNT] >= 5) { |
|
| 78 | 78 | $centsInt++; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * @return self |
| 91 | 91 | * @throws InvalidArgumentException |
| 92 | 92 | */ |
| 93 | - public static function newFromFloat( float $euroAmount ): self { |
|
| 94 | - return new self( intval( |
|
| 93 | + public static function newFromFloat(float $euroAmount): self { |
|
| 94 | + return new self(intval( |
|
| 95 | 95 | round( |
| 96 | - round( $euroAmount, self::DECIMAL_COUNT ) * self::CENTS_PER_EURO, |
|
| 96 | + round($euroAmount, self::DECIMAL_COUNT) * self::CENTS_PER_EURO, |
|
| 97 | 97 | 0 |
| 98 | 98 | ) |
| 99 | - ) ); |
|
| 99 | + )); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @return self |
| 105 | 105 | * @throws InvalidArgumentException |
| 106 | 106 | */ |
| 107 | - public static function newFromInt( int $euroAmount ): self { |
|
| 108 | - return new self( $euroAmount * self::CENTS_PER_EURO ); |
|
| 107 | + public static function newFromInt(int $euroAmount): self { |
|
| 108 | + return new self($euroAmount * self::CENTS_PER_EURO); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | public function getEuroCents(): int { |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * Returns the euro amount as string with two decimals always present in format "42.00". |
| 121 | 121 | */ |
| 122 | 122 | public function getEuroString(): string { |
| 123 | - return number_format( $this->getEuroFloat(), self::DECIMAL_COUNT, '.', '' ); |
|
| 123 | + return number_format($this->getEuroFloat(), self::DECIMAL_COUNT, '.', ''); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function equals( Euro $euro ): bool { |
|
| 126 | + public function equals(Euro $euro): bool { |
|
| 127 | 127 | return $this->cents === $euro->cents; |
| 128 | 128 | } |
| 129 | 129 | |