Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/Copper/Copper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ class Copper
/**
* Create the instance of Copper.
*
* @param float|string|null $value Number to be used in the formatter.
* @param int|null $style Style of formatter to use.
* @param string|null $locale Locale to use for the formatter.
* @param float|string|null $value Number to be used in the formatter.
* @param int|null $style Style of formatter to use.
* @param string|null $locale Locale to use for the formatter.
*
* @return Copper Copper instance.
*/
public static function create(float|string|null $value = null, ?int $style = null, ?string $locale = null): Copper
{
if (! self::$instance instanceof self) {
self::$instance = new self;
if (!self::$instance instanceof self) {
self::$instance = new self();
}

if (false === is_null($value)) {
Expand All @@ -84,7 +85,8 @@ public static function create(float|string|null $value = null, ?int $style = nul
/**
* Format the number using DECIMAL.
*
* @param int|null $precision Precision to use for formatter.
* @param int|null $precision Precision to use for formatter.
*
* @return string|bool Formatted number.
*/
public static function decimal(?int $precision = null): string|bool
Expand All @@ -102,7 +104,8 @@ public static function decimal(?int $precision = null): string|bool
/**
* Format the number using CURRENCY.
*
* @param string $iso The 3-letter ISO 4217 currency code indicating the currency to use.
* @param string $iso The 3-letter ISO 4217 currency code indicating the currency to use.
*
* @return string|bool Formatted number.
*/
public static function currency(string $iso): string|bool
Expand Down Expand Up @@ -145,7 +148,8 @@ public static function percentage(): string|bool
/**
* Format the number using CURRENCY_ACCOUNTING.
*
* @param string $iso The 3-letter ISO 4217 currency code indicating the currency to use.
* @param string $iso The 3-letter ISO 4217 currency code indicating the currency to use.
*
* @return string|bool Formatted number.
*/
public static function accounting(string $iso): string|bool
Expand Down Expand Up @@ -174,12 +178,13 @@ public static function scientific(): string|bool
/**
* 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
Expand All @@ -195,7 +200,7 @@ public static function unit(Unit $unit, bool $usePrefix = true, bool $useThrees
$exponent = 0;

if ($usePrefix) {
$exponent = (int) (floor(log10(abs($value))));
$exponent = (int) floor(log10(abs($value)));

if ($useThrees || $exponent >= 3) {
$options = [
Expand All @@ -217,7 +222,8 @@ public static function unit(Unit $unit, bool $usePrefix = true, bool $useThrees
/**
* Set the Locale.
*
* @param string $locale Locale in which the number would be formatted.
* @param string $locale Locale in which the number would be formatted.
*
* @return ?Copper Copper instance.
*/
public static function setLocale(string $locale): ?Copper
Expand All @@ -241,7 +247,8 @@ public static function getLocale(): string
/**
* Set the Style.
*
* @param int $style Style of the formatting.
* @param int $style Style of the formatting.
*
* @return ?Copper Copper instance.
*/
public static function setStyle(int $style): ?Copper
Expand Down
46 changes: 23 additions & 23 deletions src/Copper/Enums/Prefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ public function symbol(): string
{
return match ($this) {
self::QUETTA => 'Q',
self::RONNA => 'R',
self::YOTTA => 'Y',
self::ZETTA => 'Z',
self::EXA => 'E',
self::PETA => 'P',
self::TERA => 'T',
self::GIGA => 'G',
self::MEGA => 'M',
self::KILO => 'k',
self::HECTO => 'h',
self::DECA => 'da',
self::DECI => 'd',
self::CENTI => 'c',
self::MILLI => 'm',
self::MICRO => 'µ',
self::NANO => 'n',
self::PICO => 'p',
self::FEMTO => 'f',
self::ATTO => 'a',
self::ZEPTO => 'z',
self::YOCTO => 'y',
self::RONTO => 'r',
self::RONNA => 'R',
self::YOTTA => 'Y',
self::ZETTA => 'Z',
self::EXA => 'E',
self::PETA => 'P',
self::TERA => 'T',
self::GIGA => 'G',
self::MEGA => 'M',
self::KILO => 'k',
self::HECTO => 'h',
self::DECA => 'da',
self::DECI => 'd',
self::CENTI => 'c',
self::MILLI => 'm',
self::MICRO => 'µ',
self::NANO => 'n',
self::PICO => 'p',
self::FEMTO => 'f',
self::ATTO => 'a',
self::ZEPTO => 'z',
self::YOCTO => 'y',
self::RONTO => 'r',
self::QUECTO => 'q',
self::BASE => '',
self::BASE => '',
};
}

Expand Down
54 changes: 27 additions & 27 deletions src/Copper/Enums/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ enum Unit: string
public function name(): string
{
return match ($this) {
self::SECOND => 'Second',
self::METRE => 'Metre',
self::GRAM => 'Gram',
self::AMPERE => 'Ampere',
self::KELVIN => 'Kelvin',
self::MOLE => 'Mole',
self::CANDELA => 'Candela',
self::RADIAN => 'Radian',
self::SECOND => 'Second',
self::METRE => 'Metre',
self::GRAM => 'Gram',
self::AMPERE => 'Ampere',
self::KELVIN => 'Kelvin',
self::MOLE => 'Mole',
self::CANDELA => 'Candela',
self::RADIAN => 'Radian',
self::STERADIAN => 'Steradian',
self::HERTZ => 'Hertz',
self::NEWTON => 'Newton',
self::PASCAL => 'Pascal',
self::JOULE => 'Joule',
self::WATT => 'Watt',
self::COULOMB => 'Coulomb',
self::VOLT => 'Volt',
self::FARAD => 'Farad',
self::OHM => 'Ohm',
self::SIEMENS => 'Siemens',
self::WEBER => 'Weber',
self::TESLA => 'Tesla',
self::HENRY => 'Henry',
self::CELSIUS => 'Celsius',
self::LUMEN => 'Lumen',
self::LUX => 'Lux',
self::HERTZ => 'Hertz',
self::NEWTON => 'Newton',
self::PASCAL => 'Pascal',
self::JOULE => 'Joule',
self::WATT => 'Watt',
self::COULOMB => 'Coulomb',
self::VOLT => 'Volt',
self::FARAD => 'Farad',
self::OHM => 'Ohm',
self::SIEMENS => 'Siemens',
self::WEBER => 'Weber',
self::TESLA => 'Tesla',
self::HENRY => 'Henry',
self::CELSIUS => 'Celsius',
self::LUMEN => 'Lumen',
self::LUX => 'Lux',
self::BECQUEREL => 'Becquerel',
self::GRAY => 'Gray',
self::SIEVERT => 'Sievert',
self::KATAL => 'Katal',
self::GRAY => 'Gray',
self::SIEVERT => 'Sievert',
self::KATAL => 'Katal',
};
}
}
Loading