BaseCurrencyValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 22
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 3
1
<?php
2
/*
3
 * This file is part of the Exchange Rate package, an RunOpenCode project.
4
 *
5
 * (c) 2016 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\ExchangeRate\Processor;
11
12
use RunOpenCode\ExchangeRate\Exception\ConfigurationException;
13
use RunOpenCode\ExchangeRate\Contract\ProcessorInterface;
14
use RunOpenCode\ExchangeRate\Contract\RateInterface;
15
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface;
16
use RunOpenCode\ExchangeRate\Utils\CurrencyCodeUtil;
17
18
/**
19
 * Class BaseCurrencyValidator
20
 *
21
 * Processor which checks weather all rates have same base currency code.
22
 *
23
 * This processor should be added to processing queue as one of the last ones.
24
 *
25
 * @package RunOpenCode\ExchangeRate\Processor
26
 */
27
class BaseCurrencyValidator implements ProcessorInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    public function process($baseCurrencyCode, RatesConfigurationRegistryInterface $configurations, array $rates)
33
    {
34 2
        $baseCurrencyCode = CurrencyCodeUtil::clean($baseCurrencyCode);
35
36
        /**
37
         * @var RateInterface $rate
38
         */
39 2
        foreach ($rates as $rate) {
40
41 2
            if ($baseCurrencyCode !== $rate->getBaseCurrencyCode()) {
42 1
                throw new ConfigurationException(sprintf('Invalid base currency code "%s" of rate "%s" from source "%s" is not calculated.', $rate->getBaseCurrencyCode(), $rate->getCurrencyCode(), $rate->getSourceName()));
43
            }
44
        }
45
46 1
        return $rates;
47
    }
48
}
49