<commit_before><?php

namespace Glavweb\RestBundle\ApiDoc\Parser;

use Glavweb\DatagridBundle\DataSchema\DataSchemaFactory;
use Glavweb\DatagridBundle\Loader\Yaml\DataSchemaYamlLoader;
use Nelmio\ApiDocBundle\Parser\ParserInterface;
use Symfony\Component\Config\FileLocator;

/**
 * Class DataSchemaParser
 * @package Glavweb\RestBundle\ApiDoc\Parser
 */
class DataSchemaParser implements ParserInterface
{
    /**
     * @var DataSchemaFactory
     */
    protected $dataSchemaFactory;

    /**
     * @var string
     */
    protected $dataSchemaDir;

    /**
     * DataSchemaParser constructor.
     *
     * @param DataSchemaFactory $dataSchemaFactory
     * @param string $dataSchemaDir
     */
    public function __construct(DataSchemaFactory $dataSchemaFactory, $dataSchemaDir)
    {
        $this->dataSchemaFactory = $dataSchemaFactory;
        $this->dataSchemaDir     = $dataSchemaDir;
    }

    /**
     * @param array $item
     * @return bool
     */
    public function supports(array $item)
    {
        return !$item['class'] && isset($item['options']['data_schema']);
    }

    /**
     * @param array $item
     */
    public function parse(array $item)
    {
        $schemaFile = $item['options']['data_schema'];

        $dataSchema = $this->dataSchemaFactory->createDataSchema($schemaFile);
        $configuration = $dataSchema->getConfiguration();

        return $this->getParameters($configuration);
    }

    /**
     * @param array $configuration
     * @return array
     */
    protected function getParameters(array $configuration)
    {
        $parameters = [];

        if (isset($configuration['properties'])) {
            $properties = $configuration['properties'];
            
            foreach ($properties as $name => $info) {
                $parameters[$name] = $this->getItemMetaData($info);

                if (isset($info['properties'])) {
                    $parameters[$name]['children'] = $this->getParameters($info);
                }
            }
        }

        return $parameters;
    }

    /**
     * @param array$info
     * @return arra y
     */
    public function getItemMetaData(array $info)
    {
        $type = $info['type'];

        $meta = [
            'dataType'    => $type == 'NULL' ? null : $type,
            'actualType'  => $type,
            'subType'     => null,
            'required'    => null,<commit_msg>Same changes in DataSchemaParser.<commit_after><?php

namespace Glavweb\RestBundle\ApiDoc\Parser;

use Glavweb\DatagridBundle\DataSchema\DataSchemaFactory;
use Glavweb\DatagridBundle\Loader\Yaml\DataSchemaYamlLoader;
use Nelmio\ApiDocBundle\Parser\ParserInterface;
use Symfony\Component\Config\FileLocator;

/**
 * Class DataSchemaParser
 * @package Glavweb\RestBundle\ApiDoc\Parser
 */
class DataSchemaParser implements ParserInterface
{
    /**
     * @var DataSchemaFactory
     */
    protected $dataSchemaFactory;

    /**
     * @var string
     */
    protected $dataSchemaDir;

    /**
     * DataSchemaParser constructor.
     *
     * @param DataSchemaFactory $dataSchemaFactory
     * @param string $dataSchemaDir
     */
    public function __construct(DataSchemaFactory $dataSchemaFactory, $dataSchemaDir)
    {
        $this->dataSchemaFactory = $dataSchemaFactory;
        $this->dataSchemaDir     = $dataSchemaDir;
    }

    /**
     * @param array $item
     * @return bool
     */
    public function supports(array $item)
    {
        return !$item['class'] && isset($item['options']['data_schema']);
    }

    /**
     * @param array $item
     */
    public function parse(array $item)
    {
        $schemaFile = $item['options']['data_schema'];

        $dataSchema = $this->dataSchemaFactory->createDataSchema($schemaFile);
        $configuration = $dataSchema->getConfiguration();

        return $this->getParameters($configuration);
    }

    /**
     * @param array $configuration
     * @return array
     */
    protected function getParameters(array $configuration)
    {
        $parameters = [];

        if (isset($configuration['properties'])) {
            $properties = $configuration['properties'];
            
            foreach ($properties as $name => $info) {
                $parameters[$name] = $this->getItemMetaData($info);

                if (isset($info['properties'])) {
                    $parameters[$name]['children'] = $this->getParameters($info);
                }
            }
        }

        return $parameters;
    }

    /**
     * @param array$info
     * @return array
     */
    public function getItemMetaData(array $info)
    {
        $type = $info['type'];

        $meta = [
            'dataType'    => $type == 'NULL' ? null : $type,
            'actualType'  => $type,
            'subType'     => null,
            'required'    => null,
{'fraction_non_alphanumeric': 0.13213026343082349, 'fraction_numerical': 0.0, 'mean_word_length': 2.307270233196159, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '3848217', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1317, 'n_words': 243}