<commit_before><?php
/**
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
 * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
 */

namespace ZF\Apigility\Doctrine\Admin\Model;

use ZF\Apigility\Admin\Model\AbstractAutodiscoveryModel;

class DoctrineAutodiscoveryModel extends AbstractAutodiscoveryModel
{
    /**
     * Fetch fields for an adapter
     *
     * @param  string $module
     * @param  int    $version
     * @param  string $adapter_name
     * @return array
     */
    public function fetchFields($module, $version, $adapter_name)
    {
        $entities = array();

        /**
         * @var \Doctrine\ORM\EntityManager $em
         */
        $em = $this->getServiceLocator()->get($adapter_name);

        /**
         * @var \Doctrine\ORM\Mapping\ClassMetadataFactory $cmf
         */
        $cmf = $em->getMetadataFactory();

        /**
         * @var \Doctrine\ORM\Mapping\ClassMetadata $classMetadata
         */
        foreach ($cmf->getAllMetadata() as $classMetadata) {
            $service = substr($classMetadata->getName(), strrpos($classMetadata->getName(), '\\') + 1);
            if ($this->moduleHasService($module, $version, $service)) {
                continue;
            }
            $entity = array(
                'entity_class' => $classMetadata->getName(),
                'service_name' => $service,
                'fields' => array(),
            );

            foreach ($classMetadata->fieldMappings as $mapping) {
                if ($classMetadata->isIdentifier($mapping['fieldName'])) {
                    continue;
                }
                $field = array(
                    'name' => $mapping['fieldName'],
                    'required' => (!isset($mapping['nullable']) || $mapping['nullable'] !== true),
                    'filters' => array(),
                    'validators' => array(),
                );
                switch ($mapping['type']) {
                    case 'string':
                        $field['filters'] = $this->filters['text'];
                        if (isset($mapping['length']) && $mapping['length']) {
                            $validator = $this->validators['text'];
                            $validator['options']['max'] = $mapping['length'];
                            $field['validators'][] = $validator;
                        }
                        break;
                    case 'integer':
                        $field['filters'] = $this->filters['integer'];
                        break;
                    default:
                        continue;
                        break;
                }
                $entity['fields'][] = $field;
            }<commit_msg>add int case for filter auto detection<commit_after><?php
/**
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
 * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
 */

namespace ZF\Apigility\Doctrine\Admin\Model;

use ZF\Apigility\Admin\Model\AbstractAutodiscoveryModel;

class DoctrineAutodiscoveryModel extends AbstractAutodiscoveryModel
{
    /**
     * Fetch fields for an adapter
     *
     * @param  string $module
     * @param  int    $version
     * @param  string $adapter_name
     * @return array
     */
    public function fetchFields($module, $version, $adapter_name)
    {
        $entities = array();

        /**
         * @var \Doctrine\ORM\EntityManager $em
         */
        $em = $this->getServiceLocator()->get($adapter_name);

        /**
         * @var \Doctrine\ORM\Mapping\ClassMetadataFactory $cmf
         */
        $cmf = $em->getMetadataFactory();

        /**
         * @var \Doctrine\ORM\Mapping\ClassMetadata $classMetadata
         */
        foreach ($cmf->getAllMetadata() as $classMetadata) {
            $service = substr($classMetadata->getName(), strrpos($classMetadata->getName(), '\\') + 1);
            if ($this->moduleHasService($module, $version, $service)) {
                continue;
            }
            $entity = array(
                'entity_class' => $classMetadata->getName(),
                'service_name' => $service,
                'fields' => array(),
            );

            foreach ($classMetadata->fieldMappings as $mapping) {
                if ($classMetadata->isIdentifier($mapping['fieldName'])) {
                    continue;
                }
                $field = array(
                    'name' => $mapping['fieldName'],
                    'required' => (!isset($mapping['nullable']) || $mapping['nullable'] !== true),
                    'filters' => array(),
                    'validators' => array(),
                );
                switch ($mapping['type']) {
                    case 'string':
                        $field['filters'] = $this->filters['text'];
                        if (isset($mapping['length']) && $mapping['length']) {
                            $validator = $this->validators['text'];
                            $validator['options']['max'] = $mapping['length'];
                            $field['validators'][] = $validator;
                        }
                        break;
                    case 'integer':
                    case 'int':
                        $field['filters'] = $this->filters['integer'];
                        break;
                    default:
                        continue;
                        break;
                }
                $entity['fields'][] = $field;
            }
{'fraction_non_alphanumeric': 0.14337110991185464, 'fraction_numerical': 0.0025184385680877856, 'mean_word_length': 1.47001332741004, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '969912', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1361, 'n_words': 254}