ProviderMockTrait::generateFakeProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ProviderMockTrait.php$0 ➔ __construct() 0 4 1
A ProviderMockTrait.php$0 ➔ getExchangeRate() 0 4 1
1
<?php
2
3
namespace BenTools\Currency\Tests;
4
5
use BenTools\Currency\Model\CurrencyInterface;
6
use BenTools\Currency\Model\ExchangeRate;
7
use BenTools\Currency\Model\ExchangeRateInterface;
8
use BenTools\Currency\Provider\ExchangeRateProviderInterface;
9
use DateTimeInterface;
10
11
trait ProviderMockTrait
12
{
13
    /**
14
     * @param float $ratio
15
     * @return ExchangeRateProviderInterface
16
     */
17
    private function generateFakeProvider(float $ratio): ExchangeRateProviderInterface
18
    {
19
        return new class($ratio) implements ExchangeRateProviderInterface
20
        {
21
            private $ratio;
22
23
            public function __construct(float $ratio)
24
            {
25
                $this->ratio = $ratio;
26
            }
27
28
            public function getExchangeRate(CurrencyInterface $sourceCurrency, CurrencyInterface $targetCurrency, DateTimeInterface $date = null): ExchangeRateInterface
29
            {
30
                return new ExchangeRate($sourceCurrency, $targetCurrency, $this->ratio);
31
            }
32
33
        };
34
    }
35
36
    /**
37
     * @return float
38
     * @throws \Exception
39
     */
40
    private function generateFakeRatio(): float
41
    {
42
        return (float) sprintf('%s.%s', random_int(0, 1), random_int(1, 1000));
43
    }
44
45
}