HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Base/FormatsValuesTrait.php
<?php declare(strict_types=1);


namespace App\Base;

use App\Finance\RoundingService;
use Komma\KMS\Globalization\RegionInfo;
use Komma\KMS\Globalization\RegionInfoInterface;

/**
 * Class FormatsValuesTrait
 *
 * Can format values
 *
 * @package App\Base
 */
trait FormatsValuesTrait
{
    /**
     * @param array $data
     * @return array
     */
    private function formattedValues(array $data)
    {
        $formattedValues = [];

        if(property_exists(static::class, 'fieldsToFormat')) {
            foreach ($this->fieldsToFormat as $fieldToFormat) {
                if (!array_key_exists($fieldToFormat, $data) || !array_key_exists($fieldToFormat, $data)) continue;
                $formattedValues[$fieldToFormat . 'Formatted'] = $this->formatValue($data[$fieldToFormat]);
            }
        }

        return $formattedValues;
    }

    /**
     * @param $value
     *
     * @return string
     */
    private function formatValue($value) {
        if(!property_exists(static::class, 'regionInfo')) {
            return '';
        }
        $currencySymbol = $this->regionInfo->getCurrencySymbol();
        return $currencySymbol.' '.$this->regionInfo->getNumberFormat()->centsToCurrency(RoundingService::Round($value), true, true);
    }
}