diff --git a/src/Copper/Copper.php b/src/Copper/Copper.php index 954279c02779f8c0126a33c7a9775e4f7a49f9f3..8d352083d3b19d22e6ea5344e825661fb350ece6 100755 --- a/src/Copper/Copper.php +++ b/src/Copper/Copper.php @@ -183,10 +183,13 @@ class Copper /** * Format the number using SI units and prefixes. - * @param Unit $unit SI Unit to display using. + * + * @param Unit $unit SI Unit to display using. + * * @parm bool $usePrefix Set whether to use prefixes. - * @param bool $useThrees Set whether to use only multiples of three in prefixes. - * @param int|null $precision Set the precision of the number. + * + * @param bool $useThrees Set whether to use only multiples of three in prefixes. + * @param int|null $precision Set the precision of the number. * @return string Formatted number. */ public static function unit(Unit $unit, bool $usePrefix = true, bool $useThrees = true, ?int $precision = null): string @@ -201,13 +204,13 @@ class Copper $value = self::$value; $exponent = 0; - if($usePrefix) { - $exponent = (int) (floor(log10(abs($value)))); + if ($usePrefix) { + $exponent = (int) floor(log10(abs($value))); if ($useThrees || $exponent >= 3) { $options = [ (int) floor($exponent / 3) * 3, - (int) ceil($exponent / 3) * 3 + (int) ceil($exponent / 3) * 3, ]; $exponent = abs($exponent - $options[0]) < abs($options[1] - $exponent) @@ -218,7 +221,7 @@ class Copper $value /= (10 ** $exponent); } - return self::$formatter->format($value) . ' ' . Prefix::from($exponent)->symbol() . $unit->value; + return self::$formatter->format($value).' '.Prefix::from($exponent)->symbol().$unit->value; } /** diff --git a/src/Copper/Enums/Prefix.php b/src/Copper/Enums/Prefix.php index 107068e7c6ff43d9d3bd9b11be4aea7039743c36..8daedefce4336867579a3c28202f5fdb252789f8 100644 --- a/src/Copper/Enums/Prefix.php +++ b/src/Copper/Enums/Prefix.php @@ -32,8 +32,9 @@ enum Prefix: int case RONTO = -27; case QUECTO = -30; - public function symbol(): string { - return match($this) { + public function symbol(): string + { + return match ($this) { self::QUETTA => 'Q', self::RONNA => 'R', self::YOTTA => 'Y', @@ -62,7 +63,8 @@ enum Prefix: int }; } - public function multipleOfThree(): bool { + public function multipleOfThree(): bool + { return ! abs(self::value) % 3; } } diff --git a/src/Copper/Enums/Unit.php b/src/Copper/Enums/Unit.php index 8dae1769933a252df1fbc035d88f9110b6e2f5a8..d591ee2163e0d15fc81609f045f5a3991c128b65 100644 --- a/src/Copper/Enums/Unit.php +++ b/src/Copper/Enums/Unit.php @@ -36,9 +36,9 @@ enum Unit: string case SIEVERT = 'Sv'; case KATAL = 'kat'; - public function name(): string { - return match($this) - { + public function name(): string + { + return match ($this) { self::SECOND => 'Second', self::METRE => 'Metre', self::GRAM => 'Gram',