<commit_before><?php

/*
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace ApiPlatform\SchemaGenerator\AnnotationGenerator;

use ApiPlatform\SchemaGenerator\CardinalitiesExtractor;
use ApiPlatform\SchemaGenerator\TypesGenerator;

/**
 * Doctrine MongoDB annotation generator.
 *
 * @author <NAME> <<EMAIL>>>
 */
class DoctrineMongoDBAnnotationGenerator extends AbstractAnnotationGenerator
{
    /**
     * {@inheritdoc}
     */
    public function generateClassAnnotations($className)
    {
        $class = $this->classes[$className];

        if ($class['isEnum']) {
            return [];
        }

        if (isset($this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'])) {
            $inheritanceMapping = $this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'];
        } else {
            $inheritanceMapping = $class['abstract'] ? '@MongoDB\MappedSuperclass' : '@MongoDB\Document';
        }

        return [
            '',
            $inheritanceMapping,
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function generateFieldAnnotations($className, $fieldName)
    {
        $this->classes[$className];
        $field = $this->classes[$className]['fields'][$fieldName];

        $annotations = [];

        if ($field['isEnum']) {
            if ($field['isArray']) {
                $type = 'simple_array';
            } else {
                $type = 'string';
            }
        } else {
            switch ($field['range']) {
                case 'Boolean':
                    $type = 'boolean';
                    break;
                case 'Date':
                    // No break
                case 'DateTime':
                    $type = 'date';
                    break;
                case 'Time':
                    $type = 'time';
                    break;
                case 'Number':
                    // No break
                case 'Float':
                    $type = 'float';
                    break;
                case 'Integer':
                    $type = 'integer';
                    break;
                case 'Text':
                    // No break
                case 'URL':
                    $type = 'string';
                    break;
            }
        }

        if (isset($type)) {
            if (!$field['isId']) {
                $annotation = '@MongoDB\Field';

                if ($field['isArray']) {
                    $type = 'collection';
                }

                $annotation .= sprintf('(type="%s")', $type);

                $annotations[] = $annotation;
            }
        } else {
            switch ($field['cardinality']) {
                case ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_0_1
                    || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_1_1):

                    $annotations[] = sprintf('@MongoDB\ReferenceOne(targetDocument="%s", simple=true))', $this->getRelationName($field['range']));
                    break;
                case ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_UNKNOWN):
                    // No break
                case ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_0
                    || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_1):

                    $annotations[] = sprintf('@MongoDB\ReferenceOne(targetDocument="%s", simple=true))', $this->getRelationName($field['range']));
                    break;
                case ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_0_N
                    || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_1_N
                    || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_N):

                    $annotations[] = sprintf('@MongoDB\ReferenceMany(targetDocument="%s", simple=true)', $this->getRelationName($field['range']));
                    break;
            }
        }

        if ($field['isId']) {
            $annotations[] = '@MongoDB\Id';
        }

        return $annotations;
    }<commit_msg>Refactoring code style<commit_after><?php

/*
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace ApiPlatform\SchemaGenerator\AnnotationGenerator;

use ApiPlatform\SchemaGenerator\CardinalitiesExtractor;
use ApiPlatform\SchemaGenerator\TypesGenerator;

/**
 * Doctrine MongoDB annotation generator.
 *
 * @author <NAME> <<EMAIL>>>
 */
class DoctrineMongoDBAnnotationGenerator extends AbstractAnnotationGenerator
{
    /**
     * {@inheritdoc}
     */
    public function generateClassAnnotations($className)
    {
        $class = $this->classes[$className];

        if ($class['isEnum']) {
            return [];
        }

        if (isset($this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'])) {
            $inheritanceMapping = $this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'];
        } else {
            $inheritanceMapping = $class['abstract'] ? '@MongoDB\MappedSuperclass' : '@MongoDB\Document';
        }

        return [
            '',
            $inheritanceMapping,
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function generateFieldAnnotations($className, $fieldName)
    {
        $this->classes[$className];
        $field = $this->classes[$className]['fields'][$fieldName];

        $annotations = [];

        if ($field['isEnum']) {
            if ($field['isArray']) {
                $type = 'simple_array';
            } else {
                $type = 'string';
            }
        } else {
            switch ($field['range']) {
                case 'Boolean':
                    $type = 'boolean';
                    break;
                case 'Date':
                    // No break
                case 'DateTime':
                    $type = 'date';
                    break;
                case 'Time':
                    $type = 'time';
                    break;
                case 'Number':
                    // No break
                case 'Float':
                    $type = 'float';
                    break;
                case 'Integer':
                    $type = 'integer';
                    break;
                case 'Text':
                    // No break
                case 'URL':
                    $type = 'string';
                    break;
            }
        }

        if (isset($type)) {
            if (!$field['isId']) {
                $annotation = '@MongoDB\Field';

                if ($field['isArray']) {
                    $type = 'collection';
                }

                $annotation .= sprintf('(type="%s")', $type);

                $annotations[] = $annotation;
            }
        } else {
            if ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_0_1
                || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_1_1
                || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_0
                || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_1) {
                $annotations[] = sprintf('@MongoDB\ReferenceOne(targetDocument="%s", simple=true))', $this->getRelationName($field['range']));
            } elseif ($field['cardinality'] === CardinalitiesExtractor::CARDINALITY_0_N
                || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_1_N
                || $field['cardinality'] === CardinalitiesExtractor::CARDINALITY_N_N) {
                $annotations[] = sprintf('@MongoDB\ReferenceMany(targetDocument="%s", simple=true)', $this->getRelationName($field['range']));
            }
        }

        if ($field['isId']) {
            $annotations[] = '@MongoDB\Id';
        }

        return $annotations;
    }
{'fraction_non_alphanumeric': 0.14517326732673266, 'fraction_numerical': 0.0019801980198019802, 'mean_word_length': 1.674942072161536, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 36, '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': '7486488', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2046, 'n_words': 357}