CurrenciesRepository::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace GNAHotelSolutions\CurrencyConverter;
4
5
use GNAHotelSolutions\CurrencyConverter\Contracts\CurrenciesRepositoryContract;
6
use GNAHotelSolutions\CurrencyConverter\Exceptions\CurrencyNotFoundException;
7
8
class CurrenciesRepository implements CurrenciesRepositoryContract
9
{
10
    /** @var array */
11
    private $currencies;
12
13
    public function __construct(array $currencies)
14
    {
15
        foreach ($currencies as $currency) {
16
            $this->append($currency);
17
        }
18
    }
19
20
    public function get(string $currency): ?Currency
21
    {
22
        if (! isset($this->currencies[$currency])) {
23
            throw new CurrencyNotFoundException($currency);
24
        }
25
26
        return $this->currencies[$currency];
27
    }
28
29
    public function append(Currency $currency): void
30
    {
31
        $this->currencies[$currency->name()] = $currency;
32
    }
33
34
    public function has(string $currency): bool
35
    {
36
        return isset($this->currencies[$currency]);
37
    }
38
}
39