<commit_before><?php

/*
 * This file is part of the DunglasApiBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Dunglas\ApiBundle\Mapping;

use Doctrine\Common\Cache\Cache;
use Dunglas\ApiBundle\Mapping\Loader\LoaderInterface;
use Dunglas\ApiBundle\Util\ClassInfo;

/**
 * {@inheritdoc}
 *
 * @author <NAME> <<EMAIL>>
 */
class ClassMetadataFactory implements ClassMetadataFactoryInterface
{
    use ClassInfo;

    /**
     * @var LoaderInterface
     */
    private $loader;
    /**
     * @var Cache|null
     */
    private $cache;
    /**
     * @var array
     */
    private $loadedClasses = [];

    public function __construct(LoaderInterface $loader, Cache $cache = null)
    {
        $this->loader = $loader;
        $this->cache = $cache;
    }

    /**
     * {@inheritdoc}
     */
    public function getMetadataFor(
        $value,
        array $normalizationGroups = null,
        array $denormalizationGroups = null,
        array $validationGroups = null
    ) {
        $class = $this->getClass($value);
        if (false === $class) {
            throw new \InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
        }

        $classKey = serialize([$class, $normalizationGroups, $denormalizationGroups, $validationGroups]);

        if (isset($this->loadedClasses[$classKey])) {
            return $this->loadedClasses[$classKey];
        }

        if ($this->cache && ($this->loadedClasses[$classKey] = $this->cache->fetch($classKey))) {
            return $this->loadedClasses[$classKey];
        }

        if (!class_exists($class) && !interface_exists($class)) {
            throw new \InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $class));
        }

        $classMetadata = new ClassMetadata($class);
        $this->loader->loadClassMetadata(
            $classMetadata,
            $normalizationGroups,
            $denormalizationGroups,
            $denormalizationGroups
        );

        if ($this->cache) {<commit_msg>Fix validation group in getMetadataFor<commit_after><?php

/*
 * This file is part of the DunglasApiBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Dunglas\ApiBundle\Mapping;

use Doctrine\Common\Cache\Cache;
use Dunglas\ApiBundle\Mapping\Loader\LoaderInterface;
use Dunglas\ApiBundle\Util\ClassInfo;

/**
 * {@inheritdoc}
 *
 * @author <NAME> <<EMAIL>>
 */
class ClassMetadataFactory implements ClassMetadataFactoryInterface
{
    use ClassInfo;

    /**
     * @var LoaderInterface
     */
    private $loader;
    /**
     * @var Cache|null
     */
    private $cache;
    /**
     * @var array
     */
    private $loadedClasses = [];

    public function __construct(LoaderInterface $loader, Cache $cache = null)
    {
        $this->loader = $loader;
        $this->cache = $cache;
    }

    /**
     * {@inheritdoc}
     */
    public function getMetadataFor(
        $value,
        array $normalizationGroups = null,
        array $denormalizationGroups = null,
        array $validationGroups = null
    ) {
        $class = $this->getClass($value);
        if (false === $class) {
            throw new \InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
        }

        $classKey = serialize([$class, $normalizationGroups, $denormalizationGroups, $validationGroups]);

        if (isset($this->loadedClasses[$classKey])) {
            return $this->loadedClasses[$classKey];
        }

        if ($this->cache && ($this->loadedClasses[$classKey] = $this->cache->fetch($classKey))) {
            return $this->loadedClasses[$classKey];
        }

        if (!class_exists($class) && !interface_exists($class)) {
            throw new \InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $class));
        }

        $classMetadata = new ClassMetadata($class);
        $this->loader->loadClassMetadata(
            $classMetadata,
            $normalizationGroups,
            $denormalizationGroups,
            $validationGroups
        );

        if ($this->cache) {
{'fraction_non_alphanumeric': 0.13160291438979962, 'fraction_numerical': 0.0, 'mean_word_length': 2.5861224489795918, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 41, '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': '645800', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1196, 'n_words': 284}