<commit_before><?php

namespace Coosos\TagBundle\Form\DataTransformer;

use Coosos\TagBundle\Entity\Tag;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;

class TagsTransformer implements DataTransformerInterface
{
    /**
     * @var ObjectManager
     */
    private $manager;

    /**
     * @var array
     */
    private $options;

    /**
     * TagsTransformer constructor.
     * @param ObjectManager $manager
     * @param array         $options
     */
    public function __construct(ObjectManager $manager, array $options)
    {
        $this->manager = $manager;
        $this->options = $options;
    }

    /**
     * @param mixed $value
     * @return string
     */
    public function transform($value): string
    {
        return implode(",", $value);
    }

    /**
     * @param mixed $value
     * @return Tag[]
     */
    public function reverseTransform($value): array
    {
        $names = array_unique(array_filter(array_map('trim', explode(',', $value))));
        $tags = $this->manager->getRepository("CoososTagBundle:Tag")->findBy([
            "name" => $names
        ]);

        if($this->options["coosos_tag_persist_new"]) {
            $newNames = array_diff($names, $tags);
            foreach ($newNames as $name) {
                $tag = new Tag();
                $tag->setName($name);
                $tags[] = $tag;
            }
        }

        return $tags;
    }
}
<commit_msg>Enable 'coosos_tag_category' option in tags transformer<commit_after><?php

namespace Coosos\TagBundle\Form\DataTransformer;

use Coosos\TagBundle\Entity\Tag;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;

class TagsTransformer implements DataTransformerInterface
{
    /**
     * @var ObjectManager
     */
    private $manager;

    /**
     * @var array
     */
    private $options;

    /**
     * TagsTransformer constructor.
     * @param ObjectManager $manager
     * @param array         $options
     */
    public function __construct(ObjectManager $manager, array $options)
    {
        $this->manager = $manager;
        $this->options = $options;
    }

    /**
     * @param mixed $value
     * @return string
     */
    public function transform($value): string
    {
        return implode(",", $value);
    }

    /**
     * @param mixed $value
     * @return Tag[]
     */
    public function reverseTransform($value): array
    {
        $names = array_unique(array_filter(array_map('trim', explode(',', $value))));
        $tags = $this->manager->getRepository("CoososTagBundle:Tag")->findBy([
            "name" => $names
        ]);

        if($this->options["coosos_tag_persist_new"]) {
            $newNames = array_diff($names, $tags);
            foreach ($newNames as $name) {
                $tag = new Tag();
                $tag->setName($name);
                $tag->setCategory($this->options["coosos_tag_category"]);
                $tags[] = $tag;
            }
        }

        return $tags;
    }
}

{'fraction_non_alphanumeric': 0.13695510735198438, 'fraction_numerical': 0.0, 'mean_word_length': 2.1668383110195673, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7235660', 'n_tokens_mistral': 905, 'n_tokens_neox': 888, 'n_words': 174}