Currency   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 50
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A getCode() 0 4 1
A equals() 0 4 1
1
<?php
2
3
namespace MoneyMan;
4
5
use MoneyMan\Exception\InvalidCurrencyCodeException;
6
7
/**
8
 * The Currency Class
9
 *
10
 * This class is used to represent currencies as an entity.
11
 *
12
 * @package MoneyMan
13
 * @author  Graham A. Sutton <[email protected]>
14
 */
15
class Currency
16
{
17
    /**
18
     * The 3-letter ISO code used to establish the currency
19
     * this object will represent.
20
     * @var string
21
     */
22
    private $code;
23
24
    /**
25
     * Constructor
26
     *
27
     * Establish the currency by setting the currency code. This defines
28
     * the currency this object represents.
29
     *
30
     * @param  string  $code
31
     *
32
     * @throws \MoneyMan\Exception\InvalidCurrencyCodeException
33
     */
34 37
    public function __construct($code)
35
    {
36 37
        if (!is_string($code) || strlen($code) > 3) {
37 2
            throw new InvalidCurrencyCodeException('Currency code should be a 3-letter string.  e.g. "USD"');
38
        }
39
40 35
        $this->code = $code;
41 35
    }
42
43
    /**
44
     * Get the currency code.
45
     *
46
     * @return string
47
     */
48 32
    public function getCode()
49
    {
50 32
        return $this->code;
51
    }
52
53
    /**
54
     * Compares if another Currency is equal to this Currency.
55
     *
56
     * @param Currency $currency
57
     *
58
     * @return bool
59
     */
60 23
    public function equals(Currency $currency)
61
    {
62 23
        return $this->getCode() === $currency->getCode();
63
    }
64
}
65