<commit_before><?php

namespace Tequila\MongoDB\ODM\Metadata\Factory;

use Tequila\MongoDB\ODM\Metadata\ClassMetadata;
use Tequila\MongoDB\ODM\Exception\LogicException;

class StaticMethodAwareFactory implements MetadataFactoryInterface
{
    /**
     * @var array
     */
    private $metadataCache = [];

    /**
     * {@inheritdoc}
     */
    public function getClassMetadata($documentClass): ClassMetadata
    {
        if (!array_key_exists($documentClass, $this->metadataCache)) {
            if (!class_exists($documentClass)) {
                throw new LogicException(sprintf('Document class %s does not exist.', $documentClass));
            }

            $reflection = new \ReflectionClass($documentClass);
            if ($reflection->isAbstract()) {
                throw new LogicException(
                    sprintf('Document class %s must be not abstract.', $documentClass)
                );
            }

            if (!$reflection->hasMethod('loadClassMetadata')) {
                throw new LogicException(
                    sprintf(
                        '%s requires document class %s to have method "loadClassMetadata()".',
                        __CLASS__,
                        $documentClass
                    )
                );
            }

            $reflectionMethod = $reflection->getMethod('loadClassMetadata');

            if (!$reflectionMethod->isPublic() || !$reflectionMethod->isStatic()) {
                throw new LogicException(
                    sprintf(
                        '%s requires document class %s method "loadClassMetadata" to be public and static.',
                        __CLASS__,
                        $documentClass
                    )
                );
            }

            $metadata = new ClassMetadata($documentClass);
            call_user_func([$documentClass, 'loadClassMetadata'], $metadata);
            if (null === $metadata->getPrimaryKeyField()) {
                $metadata->addObjectIdField('id', '_id', true);
            }
            $this->metadataCache[$documentClass] = $metadata;
        }

        return $this->metadataCache[$documentClass];
    }
}<commit_msg>Fix in StaticMethodAwareFactory<commit_after><?php

namespace Tequila\MongoDB\ODM\Metadata\Factory;

use Tequila\MongoDB\ODM\Metadata\ClassMetadata;
use Tequila\MongoDB\ODM\Exception\LogicException;

class StaticMethodAwareFactory implements MetadataFactoryInterface
{
    /**
     * @var array
     */
    private $metadataCache = [];

    /**
     * {@inheritdoc}
     */
    public function getClassMetadata($documentClass): ClassMetadata
    {
        if (!array_key_exists($documentClass, $this->metadataCache)) {
            if (!class_exists($documentClass)) {
                throw new LogicException(sprintf('Document class %s does not exist.', $documentClass));
            }

            $reflection = new \ReflectionClass($documentClass);
            if ($reflection->isAbstract()) {
                throw new LogicException(
                    sprintf('Document class %s must be not abstract.', $documentClass)
                );
            }

            if (!$reflection->hasMethod('loadClassMetadata')) {
                throw new LogicException(
                    sprintf(
                        '%s requires document class %s to have method "loadClassMetadata()".',
                        __CLASS__,
                        $documentClass
                    )
                );
            }

            $reflectionMethod = $reflection->getMethod('loadClassMetadata');

            if (!$reflectionMethod->isPublic() || !$reflectionMethod->isStatic()) {
                throw new LogicException(
                    sprintf(
                        '%s requires document class %s method "loadClassMetadata" to be public and static.',
                        __CLASS__,
                        $documentClass
                    )
                );
            }

            $metadata = new ClassMetadata($documentClass);
            call_user_func([$documentClass, 'loadClassMetadata'], $metadata);
            if (null === $metadata->getPrimaryKeyField() && $metadata->isIdentifiable()) {
                $metadata->addObjectIdField('id', '_id', true);
            }
            $this->metadataCache[$documentClass] = $metadata;
        }

        return $this->metadataCache[$documentClass];
    }
}
{'fraction_non_alphanumeric': 0.10859215597370211, 'fraction_numerical': 0.0, 'mean_word_length': 1.743781094527363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '3625334', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1025, 'n_words': 215}