chamilo/chamilo-lms

View on GitHub
src/CoreBundle/Transformer/ArrayToIdentifierTransformer.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Transformer;

use Symfony\Component\Form\DataTransformerInterface;

/**
 * Object to identifier transformer.
 *
 * @author Julio Montoya
 *
 * @template-implements DataTransformerInterface<array, string>
 */
class ArrayToIdentifierTransformer implements DataTransformerInterface
{
    public function transform($value): string
    {
        if (!\is_array($value)) {
            return '';
        }

        return implode(',', $value);
    }

    public function reverseTransform($value): array
    {
        if (empty($value)) {
            return [];
        }

        return explode(',', $value);
    }
}