HEX
Server: Apache/2.4.66 (Debian)
System: Linux 6dfabc3b2241 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User: (1000)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Utils/PhpDoc.php
<?php declare(strict_types=1);

namespace GraphQL\Utils;

class PhpDoc
{
    /** @param string|false|null $docBlock */
    public static function unwrap($docBlock): ?string
    {
        if ($docBlock === false || $docBlock === null) {
            return null;
        }

        $content = preg_replace('~([\r\n]) \* (.*)~i', '$1$2', $docBlock); // strip *
        assert(is_string($content), 'regex is statically known to be valid');

        $content = preg_replace('~([\r\n])[\* ]+([\r\n])~i', '$1$2', $content); // strip single-liner *
        assert(is_string($content), 'regex is statically known to be valid');

        $content = substr($content, 3); // strip leading /**
        $content = substr($content, 0, -2); // strip trailing */

        return static::nonEmptyOrNull($content);
    }

    /** @param string|false|null $docBlock */
    public static function unpad($docBlock): ?string
    {
        if ($docBlock === false || $docBlock === null) {
            return null;
        }

        $lines = explode("\n", $docBlock);
        $lines = array_map(
            static fn (string $line): string => ' ' . trim($line),
            $lines
        );

        $content = implode("\n", $lines);

        return static::nonEmptyOrNull($content);
    }

    protected static function nonEmptyOrNull(string $maybeEmptyString): ?string
    {
        $trimmed = trim($maybeEmptyString);

        return $trimmed === ''
            ? null
            : $trimmed;
    }
}