<?php

namespace Modules\Stock\TwigExtension;

use Modules\Stock\Enum\EmptyEnum;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class CodeExtension extends AbstractExtension
{
    public function getFunctions(): array
    {
        return [
            new TwigFunction('get_param_from_code', [$this, 'getParamFromCode']),
        ];
    }

    /**
     * @param string $code
     * @return string
     */
    public function getParamFromCode(string $code): string
    {
        return $code === '' ? EmptyEnum::EMPTY_PARAM->value: $code;
    }
}
