<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 SchemaOrgModel\AnnotationGenerator;

/**
 * PHPDoc annotation generator.
 *
 * @author <NAME> <<EMAIL>>
 */
class PhpDocAnnotationGenerator extends AbstractAnnotationGenerator
{
    const INDENT = '   ';

    /**
     * {@inheritdoc}
     */
    public function generateClassAnnotations($className)
    {
        return $this->generateDoc($className);
    }

    /**
     * {@inheritdoc}
     */
    public function generateInterfaceAnnotations($className)
    {
        return $this->generateDoc($className, true);
    }

    /**
     * {@inheritdoc}
     */
    public function generateConstantAnnotations($className, $constantName)
    {
        $resource = $this->classes[$className]['constants'][$constantName]['resource'];

        $annotations = $this->formatDoc($resource->get('rdfs:comment'), true);
        $annotations[0] = sprintf(
            '@type %s %s',
            'string',
            $constantName,
            $annotations[0]
        );

        return $annotations;
    }

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

        $annotations = $this->formatDoc($field['resource']->get('rdfs:comment'), true);
        $annotations[0] = sprintf(
            '@type %s $%s %s',
            $this->toPhpType($field['range']),
            $fieldName,
            $annotations[0]
        );

        return $annotations;
    }

    /**
     * {@inheritdoc}
     */
    public function generateGetterAnnotations($className, $fieldName)
    {
        return [
            sprintf('Gets %s.', $fieldName),
            '',
            sprintf('@return %s', $this->toPhpType($this->classes[$className]['fields'][$fieldName]['range'])),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function generateSetterAnnotations($className, $fieldName)
    {
        return [
            sprintf('Sets %s.', $fieldName),
            '',
            sprintf(
                '@param  %s $%s',
                $this->toPhpType($this->classes[$className]['fields'][$fieldName]['range']),
                $fieldName
            ),
            '@return $this',
        ];
    }

    /**
     * Generates class or interface PHPDoc
     *
     * @param  string $className
     * @param  bool   $interface
     * @return array
     */
    private function generateDoc($className, $interface = false)
    {
        $resource = $this->classes[$className]['resource'];
        $annotations = [];

        if (!$interface && isset($this->classes[$className]['interfaceName'])) {
            $annotations[] = '{@inheritdoc}';
            $annotations[] = '';
        } else {
            $annotations = $this->formatDoc($resource->get('rdfs:comment'));
            $annotations[] = '';
            $annotations[] = sprintf('@see %s %s', $resource->getUri(), 'Documentation on Schema.org');
        }

        if ($this->config['author']) {
            $annotations[] = sprintf('@author %s', $this->config['author']);
        }

        return $annotations;
    }

    /**
     * Converts HTML to Markdown and explode
     *
     * @param  string $doc
     * @param  bool   $indent
     * @return array
     */
    private function formatDoc($doc, $indent = false)
    {
        $doc = explode("\n", (new \HTML_To_Markdown($doc))->output());

        if ($indent) {
            for ($i = 1; $i < count($doc); $i++) {
                $doc[$i] = self::INDENT.$doc[$i];
            }
        }

        return $doc;
    }
}<commit_msg>Make SL Insight happy.<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 SchemaOrgModel\AnnotationGenerator;

/**
 * PHPDoc annotation generator.
 *
 * @author <NAME> <<EMAIL>>
 */
class PhpDocAnnotationGenerator extends AbstractAnnotationGenerator
{
    const INDENT = '   ';

    /**
     * {@inheritdoc}
     */
    public function generateClassAnnotations($className)
    {
        return $this->generateDoc($className);
    }

    /**
     * {@inheritdoc}
     */
    public function generateInterfaceAnnotations($className)
    {
        return $this->generateDoc($className, true);
    }

    /**
     * {@inheritdoc}
     */
    public function generateConstantAnnotations($className, $constantName)
    {
        $resource = $this->classes[$className]['constants'][$constantName]['resource'];

        $annotations = $this->formatDoc($resource->get('rdfs:comment'), true);
        $annotations[0] = sprintf(
            '@type %s %s',
            'string',
            $constantName,
            $annotations[0]
        );

        return $annotations;
    }

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

        $annotations = $this->formatDoc($field['resource']->get('rdfs:comment'), true);
        $annotations[0] = sprintf(
            '@type %s $%s %s',
            $this->toPhpType($field['range']),
            $fieldName,
            $annotations[0]
        );

        return $annotations;
    }

    /**
     * {@inheritdoc}
     */
    public function generateGetterAnnotations($className, $fieldName)
    {
        return [
            sprintf('Gets %s.', $fieldName),
            '',
            sprintf('@return %s', $this->toPhpType($this->classes[$className]['fields'][$fieldName]['range'])),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function generateSetterAnnotations($className, $fieldName)
    {
        return [
            sprintf('Sets %s.', $fieldName),
            '',
            sprintf(
                '@param  %s $%s',
                $this->toPhpType($this->classes[$className]['fields'][$fieldName]['range']),
                $fieldName
            ),
            '@return $this',
        ];
    }

    /**
     * Generates class or interface PHPDoc
     *
     * @param  string $className
     * @param  bool   $interface
     * @return array
     */
    private function generateDoc($className, $interface = false)
    {
        $resource = $this->classes[$className]['resource'];
        $annotations = [];

        if (!$interface && isset($this->classes[$className]['interfaceName'])) {
            $annotations[] = '{@inheritdoc}';
            $annotations[] = '';
        } else {
            $annotations = $this->formatDoc($resource->get('rdfs:comment'));
            $annotations[] = '';
            $annotations[] = sprintf('@see %s %s', $resource->getUri(), 'Documentation on Schema.org');
        }

        if ($this->config['author']) {
            $annotations[] = sprintf('@author %s', $this->config['author']);
        }

        return $annotations;
    }

    /**
     * Converts HTML to Markdown and explode
     *
     * @param  string $doc
     * @param  bool   $indent
     * @return array
     */
    private function formatDoc($doc, $indent = false)
    {
        $doc = explode("\n", (new \HTML_To_Markdown($doc))->output());

        if ($indent) {
            $count = count($doc);
            for ($i = 1; $i < $count; $i++) {
                $doc[$i] = self::INDENT.$doc[$i];
            }
        }

        return $doc;
    }
}
{'fraction_non_alphanumeric': 0.1644108280254777, 'fraction_numerical': 0.001326963906581741, 'mean_word_length': 2.0464834276475345, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, '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': '7151401', 'n_tokens_mistral': 2119, 'n_tokens_neox': 2097, 'n_words': 411}