MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.32
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //var/www/html/Modules/Currency/Services/CurrencyRateExchanger.php
<?php

namespace Modules\Currency\Services;

use Swap\Swap;
use Exchanger\Exception\Exception;

class CurrencyRateExchanger
{
    /**
     * Instance of swap.
     *
     * @var \Swap\Swap
     */
    private $swap;

    /**
     * Create a new CurrencyRateExchanger instance.
     *
     * @param \Swap\Swap $swap
     */
    public function __construct(Swap $swap)
    {
        $this->swap = $swap;
    }

    /**
     * Exchange to the latest currency rate.
     *
     * @param string $fromCurrency
     * @param string $toCurrency
     * @return float|null
     */
    public function exchange($fromCurrency, $toCurrency)
    {
        try {
            return $this->swap->latest("{$fromCurrency}/{$toCurrency}")->getValue();
        } catch (Exception $e) {
            return 1;
        }
    }
}