Mistralys /
mailcode
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Mailcode; |
||
| 6 | |||
| 7 | use AppUtils\OperationResult; |
||
| 8 | |||
| 9 | class Mailcode_Number_LocalCurrency extends OperationResult |
||
| 10 | { |
||
| 11 | public const DEFAULT_COUNTRY = "US"; |
||
| 12 | public const DEFAULT_CURRENCY_NAME = "USD"; |
||
| 13 | public const DEFAULT_CURRENCY_SYMBOL = "$"; |
||
| 14 | public const DEFAULT_UNIT_SEPARATOR = " "; |
||
| 15 | public const DEFAULT_FORMAT = "1,000.00"; |
||
| 16 | |||
| 17 | private string $country; |
||
| 18 | private string $currencyName; |
||
| 19 | private string $currencySymbol; |
||
| 20 | private string $unitSeparator; |
||
| 21 | private string $formatString; |
||
| 22 | |||
| 23 | private ?Mailcode_Parser_Statement_Tokenizer_Token $currency; |
||
| 24 | private ?Mailcode_Parser_Statement_Tokenizer_Token $region; |
||
| 25 | |||
| 26 | private static ?Mailcode_Number_LocalCurrency $instance = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $country |
||
| 30 | * @param string $currencyName |
||
| 31 | * @param string $currencySymbol |
||
| 32 | * @param string $unitSeparator |
||
| 33 | * @param string $formatString |
||
| 34 | * @param Mailcode_Parser_Statement_Tokenizer_Token|NULL $currency |
||
| 35 | * @param Mailcode_Parser_Statement_Tokenizer_Token|NULL $region |
||
| 36 | */ |
||
| 37 | public function __construct(string $country, |
||
| 38 | string $currencyName, |
||
| 39 | string $currencySymbol, |
||
| 40 | string $unitSeparator, |
||
| 41 | string $formatString, |
||
| 42 | ?Mailcode_Parser_Statement_Tokenizer_Token $currency = null, |
||
| 43 | ?Mailcode_Parser_Statement_Tokenizer_Token $region = null) |
||
| 44 | { |
||
| 45 | parent::__construct(); |
||
| 46 | |||
| 47 | $this->country = $country; |
||
| 48 | $this->currencyName = $currencyName; |
||
| 49 | $this->currencySymbol = $currencySymbol; |
||
| 50 | $this->unitSeparator = $unitSeparator; |
||
| 51 | $this->formatString = $formatString; |
||
| 52 | |||
| 53 | $this->currency = $currency; |
||
| 54 | $this->region = $region; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function getCountry(): string |
||
| 58 | { |
||
| 59 | return $this->country; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getCurrencyName(): string |
||
| 63 | { |
||
| 64 | return $this->currencyName; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getCurrencySymbol(): string |
||
| 68 | { |
||
| 69 | return $this->currencySymbol; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getUnitSeparator(): string |
||
| 73 | { |
||
| 74 | return $this->unitSeparator; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function getFormatString(): string |
||
| 78 | { |
||
| 79 | return $this->formatString; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function getRegion(): ?Mailcode_Parser_Statement_Tokenizer_Token |
||
| 83 | { |
||
| 84 | return $this->region; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function getCurrency(): ?Mailcode_Parser_Statement_Tokenizer_Token |
||
| 88 | { |
||
| 89 | return $this->currency; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function withRegion(?Mailcode_Parser_Statement_Tokenizer_Token $region = null): Mailcode_Number_LocalCurrency |
||
| 93 | { |
||
| 94 | return new Mailcode_Number_LocalCurrency( |
||
| 95 | $this->country, |
||
| 96 | $this->currencyName, |
||
| 97 | $this->currencySymbol, |
||
| 98 | $this->unitSeparator, |
||
| 99 | $this->formatString, |
||
| 100 | $this->currency, |
||
| 101 | $region |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function withCurrency(?Mailcode_Parser_Statement_Tokenizer_Token $currency = null): Mailcode_Number_LocalCurrency |
||
| 106 | { |
||
| 107 | return new Mailcode_Number_LocalCurrency( |
||
| 108 | $this->country, |
||
| 109 | $this->currencyName, |
||
| 110 | $this->currencySymbol, |
||
| 111 | $this->unitSeparator, |
||
| 112 | $this->formatString, |
||
| 113 | $currency, |
||
| 114 | $this->region |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | public function getFormatInfo(): Mailcode_Number_Info |
||
| 119 | { |
||
| 120 | return new Mailcode_Number_Info($this->formatString); |
||
| 121 | } |
||
| 122 | |||
| 123 | public static function defaultInstance(): Mailcode_Number_LocalCurrency |
||
| 124 | { |
||
| 125 | if (!isset(self::$instance)) { |
||
| 126 | self::$instance = new self( |
||
| 127 | self::DEFAULT_COUNTRY, |
||
| 128 | self::DEFAULT_CURRENCY_NAME, |
||
| 129 | self::DEFAULT_CURRENCY_SYMBOL, |
||
| 130 | self::DEFAULT_UNIT_SEPARATOR, |
||
| 131 | self::DEFAULT_FORMAT |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | return self::$instance; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 135 | } |
||
| 136 | } |