Completed
Branch BUG/11288/fix-datepicker (d15367)
by
unknown
108:07 queued 94:31
created

CurrencyFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createCurrencyFromCountryCurrency() 0 17 1
A createFromCountryCode() 0 6 1
A createFromCode() 0 6 1
1
<?php
2
3
namespace EventEspresso\core\services\currency;
4
5
use EE_Error;
6
use EE_Organization_Config;
7
use EventEspresso\core\domain\values\currency\Currency;
8
use EventEspresso\core\entities\Label;
9
use InvalidArgumentException;
10
11
defined('EVENT_ESPRESSO_VERSION') || exit;
12
13
14
15
/**
16
 * Class CurrencyFactory
17
 * Factory class for creating Currency objects
18
 *
19
 * @package EventEspresso\core\services\currency
20
 * @author  Brent Christensen
21
 * @since   $VID:$
22
 */
23
class CurrencyFactory
24
{
25
26
    /**
27
     * @var CountryCurrencyDao $country_currencies
28
     */
29
    private $country_currencies;
30
31
32
    /**
33
     * CurrencyFactory constructor.
34
     *
35
     * @param CountryCurrencyDao     $country_currencies
36
     * @param EE_Organization_Config $organization_config
0 ignored issues
show
Bug introduced by
There is no parameter named $organization_config. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
37
     */
38
    public function __construct(CountryCurrencyDao $country_currencies)
39
    {
40
        $this->country_currencies = $country_currencies;
41
    }
42
43
44
    /**
45
     * @param array $country_currency
46
     * @return Currency
47
     */
48
    private function createCurrencyFromCountryCurrency(array $country_currency)
49
    {
50
        return new Currency(
51
            $country_currency['CurrencyCode'],
52
            new Label(
53
                $country_currency['CurrencyNameSingle'],
54
                $country_currency['CurrencyNamePlural']
55
            ),
56
            $country_currency['CurrencySign'],
57
            $country_currency['CurrencySignB4'],
58
            $country_currency['CurrencyDecimalPlaces'],
59
            $country_currency['CurrencyDecimalMark'],
60
            $country_currency['CurrencyThousands'],
61
            $country_currency['CurrencySubunits'],
62
            $country_currency['CurrencySignSeparator']
63
        );
64
    }
65
66
67
    /**
68
     * returns a Currency object for the supplied country code
69
     *
70
     * @param string $CNT_ISO
71
     * @return Currency
72
     * @throws EE_Error
73
     * @throws InvalidArgumentException
74
     */
75
    public function createFromCountryCode($CNT_ISO)
76
    {
77
        return $this->createCurrencyFromCountryCurrency(
78
            $this->country_currencies->getCountryCurrencyByIsoCode($CNT_ISO)
79
        );
80
    }
81
82
83
    /**
84
     * returns a Currency object for the supplied currency code
85
     * PLZ NOTE: variations may exist between how different countries display the same currency,
86
     * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results
87
     *
88
     * @param string $code
89
     * @return Currency
90
     * @throws InvalidArgumentException
91
     * @throws EE_Error
92
     */
93
    public function createFromCode($code)
94
    {
95
        return $this->createCurrencyFromCountryCurrency(
96
            $this->country_currencies->getCountryCurrencyByCurrencyCode($code)
97
        );
98
    }
99
}
100
// Location: CreateCurrency.php
101