RbcRateBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromJson() 0 9 2
1
<?php
2
3
namespace Movavi\Builder;
4
5
use Movavi\Entity\Rate;
6
use Movavi\Exception\NoneRateException;
7
8
/**
9
 * Class RbcRateBuilder
10
 *
11
 * Builder for the Movavi\Entity\Rate
12
 * Implementation of Builder pattern (GoF)
13
 *
14
 * @package Movavi\Builder
15
 */
16
class RbcRateBuilder
17
{
18
    /**
19
     * Returns an instance of Movavi\Entity\Rate,
20
     * by string in json-format from cash.rbc.ru
21
     *
22
     * @param string $currencyFrom
23
     * @param string $currencyTo
24
     * @param \DateTime $date
25
     * @param string $jsonString
26
     *
27
     * @return Rate
28
     *
29
     * @throws NoneRateException
30
     */
31
    public function fromJson(string $currencyFrom, string $currencyTo, \DateTime $date, string $jsonString): Rate
32
    {
33
        $dataObj = json_decode($jsonString);
34
35
        if (empty($dataObj->data->sum_result)) {
36
            throw new NoneRateException('Service cash.rbc.ru has not send any rate data');
37
        }
38
39
        return new Rate($currencyFrom, $currencyTo, $date, $dataObj->data->sum_result);
40
    }
41
}
42