Passed
Pull Request — master (#18)
by
unknown
03:40
created

Mailcode_Number_LocalCurrency::getCurrencySymbol()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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 static ?Mailcode_Number_LocalCurrency $instance = null;
24
25
    /**
26
     * @param string $country
27
     * @param string $currencyName
28
     * @param string $currencySymbol
29
     * @param string $unitSeparator
30
     * @param string $formatString
31
     */
32
    public function __construct(string $country, string $currencyName, string $currencySymbol, string $unitSeparator, string $formatString)
33
    {
34
        $this->country = $country;
35
        $this->currencyName = $currencyName;
36
        $this->currencySymbol = $currencySymbol;
37
        $this->unitSeparator = $unitSeparator;
38
        $this->formatString = $formatString;
39
    }
40
41
    public function getCountry(): string
42
    {
43
        return $this->country;
44
    }
45
46
    public function getCurrencyName(): string
47
    {
48
        return $this->currencyName;
49
    }
50
51
    public function getCurrencySymbol(): string
52
    {
53
        return $this->currencySymbol;
54
    }
55
56
    public function getUnitSeparator(): string
57
    {
58
        return $this->unitSeparator;
59
    }
60
61
    public function getFormatString(): string
62
    {
63
        return $this->formatString;
64
    }
65
66
    public function getFormatInfo(): Mailcode_Number_Info
67
    {
68
        return new Mailcode_Number_Info($this->formatString);
69
    }
70
71
    public static function defaultInstance(): Mailcode_Number_LocalCurrency
72
    {
73
        if (!isset(self::$instance)) {
74
            self::$instance = new self(
75
                self::DEFAULT_COUNTRY,
76
                self::DEFAULT_CURRENCY_NAME,
77
                self::DEFAULT_CURRENCY_SYMBOL,
78
                self::DEFAULT_UNIT_SEPARATOR,
79
                self::DEFAULT_FORMAT
80
            );
81
        }
82
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type null which is incompatible with the type-hinted return Mailcode\Mailcode_Number_LocalCurrency. Consider adding an additional type-check to rule them out.
Loading history...
83
    }
84
}