| Total Complexity | 6 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Currency |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | private $quotes; |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $source; |
||
| 18 | /** |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | private $timestamp; |
||
| 22 | /** |
||
| 23 | * @var string|null |
||
| 24 | */ |
||
| 25 | private $date; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Currency constructor. |
||
| 29 | * |
||
| 30 | * @param array $quotes |
||
| 31 | * @param string $source |
||
| 32 | * @param int $timestamp |
||
| 33 | * @param string|null $date |
||
| 34 | */ |
||
| 35 | public function __construct(array $quotes, string $source, int $timestamp, ?string $date = null) |
||
| 36 | { |
||
| 37 | $this->quotes = $quotes; |
||
| 38 | $this->source = $source; |
||
| 39 | $this->timestamp = $timestamp; |
||
| 40 | $this->date = $date; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param string $name |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | public function __get(string $name) |
||
| 49 | { |
||
| 50 | $key = $this->source . $name; |
||
| 51 | if (! array_key_exists($key, $this->quotes)) { |
||
| 52 | throw new \InvalidArgumentException($name . ' does not exist in API response. Did you requested it?'); |
||
| 53 | } |
||
| 54 | |||
| 55 | return $this->quotes[$key]; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | public function getQuotes(): array |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function getSource(): string |
||
| 70 | { |
||
| 71 | return $this->source; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return DateTimeImmutable |
||
| 76 | * @throws \Exception |
||
| 77 | */ |
||
| 78 | public function getTimestamp(): DateTimeImmutable |
||
| 81 | } |
||
| 82 | } |
||
| 83 |