MoneyFormatter::getCurrency()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NeptuneSoftware\Invoice;
4
5
class MoneyFormatter
6
{
7
8
    /**
9
     * The current currency.
10
     *
11
     * @var string
12
     */
13
    protected $currency;
14
15
    /**
16
     * The current locale.
17
     *
18
     * @var string
19
     */
20
    protected $locale;
21
22 11
    public function __construct(string $currency = 'TRY', string $locale = 'tr_TR')
23
    {
24 11
        $this->currency = $currency;
25 11
        $this->locale = $locale;
26 11
    }
27
28
    /**
29
     * Gets the amount formatted according the currency and locale
30
     * @param $amount The amount in cents(!)
0 ignored issues
show
Bug introduced by
The type NeptuneSoftware\Invoice\The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     * @return String The current locale
32
     */
33 11
    public function format($amount)
34
    {
35 11
        $formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
36 11
        return (string) $formatter->formatCurrency($amount / 100, $this->currency);
37
    }
38
39
    /**
40
     * Gets the current locale
41
     * @return String The current locale
42
     */
43
    public function getLocale() : string
44
    {
45
        return (string) $this->locale;
46
    }
47
48
    /**
49
     * Sets the current locale
50
     * @param $locale The locale (i.e. 'nl_NL')
51
     * @return Void
52
     */
53 2
    public function setLocale(string $locale)
54
    {
55 2
        $this->locale = $locale;
56 2
    }
57
58
    /**
59
     * Gets the current currency
60
     * @return String The current currency
61
     */
62
    public function getCurrency()
63
    {
64
        return (string) $this->currency;
65
    }
66
67
     /**
68
     * Sets the current currency
69
     * @param $currency The currency (i.e. 'EUR')
70
     * @return Void
71
     */
72 3
    public function setCurrency(string $currency)
73
    {
74 3
        $this->currency = $currency;
75 3
    }
76
}
77