Passed
Pull Request — master (#70)
by Jan
11:26
created

ExchangeRateUpdater::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
4
namespace App\Services;
5
6
7
use App\Entity\PriceInformations\Currency;
8
use Brick\Math\BigDecimal;
9
use Swap\Swap;
10
11
class ExchangeRateUpdater
12
{
13
    private $base_currency;
14
    private $swap;
15
16
    public function __construct(string $base_currency, Swap $swap)
17
    {
18
        $this->base_currency = $base_currency;
19
        $this->swap = $swap;
20
    }
21
22
    /**
23
     * Updates the exchange rate of the given currency using the globally configured providers.
24
     * @param  Currency  $currency
25
     * @return Currency
26
     */
27
    public function update(Currency $currency): Currency
28
    {
29
        $rate = $this->swap->latest($currency->getIsoCode().'/'.$this->base_currency);
30
        $currency->setExchangeRate(BigDecimal::of($rate->getValue()));
0 ignored issues
show
Bug introduced by
It seems like Brick\Math\BigDecimal::of($rate->getValue()) can also be of type Brick\Math\BigInteger and Brick\Math\BigRational; however, parameter $exchange_rate of App\Entity\PriceInformat...ency::setExchangeRate() does only seem to accept Brick\Math\BigDecimal|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $currency->setExchangeRate(/** @scrutinizer ignore-type */ BigDecimal::of($rate->getValue()));
Loading history...
31
        return $currency;
32
    }
33
34
}