<commit_before><?php
require __DIR__ . '/vendor/autoload.php';

use GraphQL\Utils\Utils;

$outputFile = __DIR__ . '/docs/class-reference.md';

$entries = [
    \GraphQL\GraphQL::class,
    \GraphQL\Type\Definition\Type::class,
    \GraphQL\Type\Definition\ResolveInfo::class,
    \GraphQL\Language\DirectiveLocation::class => ['constants' => true],
    \GraphQL\Type\SchemaConfig::class,
    \GraphQL\Type\Schema::class,
    \GraphQL\Language\Parser::class,
    \GraphQL\Language\Printer::class,
    \GraphQL\Language\Visitor::class,
    \GraphQL\Language\AST\NodeKind::class => ['constants' => true],
    \GraphQL\Executor\Executor::class,
    \GraphQL\Executor\ExecutionResult::class,
    \GraphQL\Executor\Promise\PromiseAdapter::class,
    \GraphQL\Validator\DocumentValidator::class,
    \GraphQL\Error\Error::class           => ['constants' => true, 'methods' => true, 'props' => true],
    \GraphQL\Error\Warning::class         => ['constants' => true, 'methods' => true],
    \GraphQL\Error\ClientAware::class,
    \GraphQL\Error\DebugFlag::class       => ['constants' => true],
    \GraphQL\Error\FormattedError::class,
    \GraphQL\Server\StandardServer::class,
    \GraphQL\Server\ServerConfig::class,
    \GraphQL\Server\Helper::class,
    \GraphQL\Server\OperationParams::class,
    \GraphQL\Utils\BuildSchema::class,
    \GraphQL\Utils\AST::class,
    \GraphQL\Utils\SchemaPrinter::class
];

function renderClassMethod(ReflectionMethod $method) {
    $args = array_map(
        static function (ReflectionParameter $p): string {
            $type = ltrim($p->getType() . " ");
            $def = $type . '$' . $p->getName();

            if ($p->isDefaultValueAvailable()) {
                $val = $p->isDefaultValueConstant()
                    ? $p->getDefaultValueConstantName()
                    : $p->getDefaultValue();
                $def .= " = " . Utils::printSafeJson($val);
            }

            return $def;
        },
        $method->getParameters()
    );
    $argsStr = implode(", ", $args);
    if (strlen($argsStr) >= 80) {
        $argsStr = "\n    " . implode(",\n    ", $args) . "\n";
    }
    $returnType = $method->getReturnType();
    $def = "function {$method->getName()}($argsStr)";
    $def = $method->isStatic() ? "static $def" : $def;
    $def = $returnType ? "$def: $returnType" : $def;
    $docBlock = unpadDocblock($method->getDocComment());

    return <<<TEMPLATE
```php
{$docBlock}
{$def}
```
TEMPLATE;
}

function renderConstant($value, $name) {
    return "const $name = " . Utils::printSafeJson($value) . ";";
}

function renderProp(ReflectionProperty $prop) {
    $signature = implode(" ", Reflection::getModifierNames($prop->getModifiers())) . ' $' . $prop->getName() . ';';
    return unpadDocblock($prop->getDocComment()) . "\n" . $signature;
}

function renderClass(ReflectionClass $class, $options) {
    $classDocs = unwrapDocblock(unpadDocblock($class->getDocComment()));
    $content = '';
    $label = $class->isInterface() ? 'Interface' : 'Class';

    if (!empty($options['constants'])) {
        $constants = $class->getConstants();
        $constants = array_map('renderConstant', $constants);
        if (!empty($constants)) {
            $constants = "```php\n" . implode("\n", $constants) . "\n```";
            $content .= "**$label Constants:** \n$constants\n\n";
        }
    }

    if (!empty($options['props'])) {
        $props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
        $props = Utils::filter($props, 'isApi');
        if (!empty($props)) {
            $props = array_map('renderProp', $props);
            $props = "```php\n" . implode("\n\n", $props) . "\n```";
            $content .= "**$label Props:** \n$props\n\n";
        }<commit_msg>Fix class reference for constants (#942)<commit_after><?php
require __DIR__ . '/vendor/autoload.php';

use GraphQL\Utils\Utils;

$outputFile = __DIR__ . '/docs/class-reference.md';

$entries = [
    \GraphQL\GraphQL::class,
    \GraphQL\Type\Definition\Type::class,
    \GraphQL\Type\Definition\ResolveInfo::class,
    \GraphQL\Language\DirectiveLocation::class => ['constants' => true],
    \GraphQL\Type\SchemaConfig::class,
    \GraphQL\Type\Schema::class,
    \GraphQL\Language\Parser::class,
    \GraphQL\Language\Printer::class,
    \GraphQL\Language\Visitor::class,
    \GraphQL\Language\AST\NodeKind::class => ['constants' => true],
    \GraphQL\Executor\Executor::class,
    \GraphQL\Executor\ExecutionResult::class,
    \GraphQL\Executor\Promise\PromiseAdapter::class,
    \GraphQL\Validator\DocumentValidator::class,
    \GraphQL\Error\Error::class           => ['constants' => true, 'methods' => true, 'props' => true],
    \GraphQL\Error\Warning::class         => ['constants' => true, 'methods' => true],
    \GraphQL\Error\ClientAware::class,
    \GraphQL\Error\DebugFlag::class       => ['constants' => true],
    \GraphQL\Error\FormattedError::class,
    \GraphQL\Server\StandardServer::class,
    \GraphQL\Server\ServerConfig::class,
    \GraphQL\Server\Helper::class,
    \GraphQL\Server\OperationParams::class,
    \GraphQL\Utils\BuildSchema::class,
    \GraphQL\Utils\AST::class,
    \GraphQL\Utils\SchemaPrinter::class
];

function renderClassMethod(ReflectionMethod $method) {
    $args = array_map(
        static function (ReflectionParameter $p): string {
            $type = ltrim($p->getType() . " ");
            $def = $type . '$' . $p->getName();

            if ($p->isDefaultValueAvailable()) {
                $val = $p->isDefaultValueConstant()
                    ? $p->getDefaultValueConstantName()
                    : $p->getDefaultValue();
                $def .= " = " . Utils::printSafeJson($val);
            }

            return $def;
        },
        $method->getParameters()
    );
    $argsStr = implode(", ", $args);
    if (strlen($argsStr) >= 80) {
        $argsStr = "\n    " . implode(",\n    ", $args) . "\n";
    }
    $returnType = $method->getReturnType();
    $def = "function {$method->getName()}($argsStr)";
    $def = $method->isStatic() ? "static $def" : $def;
    $def = $returnType ? "$def: $returnType" : $def;
    $docBlock = unpadDocblock($method->getDocComment());

    return <<<TEMPLATE
```php
{$docBlock}
{$def}
```
TEMPLATE;
}

function renderConstant($value, $name) {
    return "const $name = " . Utils::printSafeJson($value) . ";";
}

function renderProp(ReflectionProperty $prop) {
    $signature = implode(" ", Reflection::getModifierNames($prop->getModifiers())) . ' $' . $prop->getName() . ';';
    return unpadDocblock($prop->getDocComment()) . "\n" . $signature;
}

function renderClass(ReflectionClass $class, $options) {
    $classDocs = unwrapDocblock(unpadDocblock($class->getDocComment()));
    $content = '';
    $label = $class->isInterface() ? 'Interface' : 'Class';

    if (!empty($options['constants'])) {
        $constants = $class->getConstants();
        $constants = array_map('renderConstant', $constants, array_keys($constants));
        if (!empty($constants)) {
            $constants = "```php\n" . implode("\n", $constants) . "\n```";
            $content .= "**$label Constants:** \n$constants\n\n";
        }
    }

    if (!empty($options['props'])) {
        $props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
        $props = Utils::filter($props, 'isApi');
        if (!empty($props)) {
            $props = array_map('renderProp', $props);
            $props = "```php\n" . implode("\n\n", $props) . "\n```";
            $content .= "**$label Props:** \n$props\n\n";
        }
{'fraction_non_alphanumeric': 0.1929545755529069, 'fraction_numerical': 0.00092702953251225, 'mean_word_length': 2.964304461942257, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, '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': '5872620', 'n_tokens_mistral': 2377, 'n_tokens_neox': 2383, 'n_words': 366}